$("document").ready(function() {
	
	var throughyougo = 0;
	
	var y = $(window).height();	
	$('.screen').css({'height':y+'px'}).smartBackgroundImage('../images/index/background.png');	
	
	$("#but_register").click(function() {
		$(".inner_text,.inner_buttons").fadeOut(1500);
		$(".content").animate({"top":"40%","height":"300px"}, 1500, function() {
		   $(".reg_form").fadeIn(500);	
		});
	});
	
	$(".form_text").focus(function() {
		var me = $(this).attr("id");
		var forminfo = '#f_'+me.substr(2);
		
		$(forminfo).slideToggle(500);
	});
	
	$(".form_text").blur(function() {
		var me = $(this).attr("id");
		var forminfo = '#f_'+me.substr(2);
		
		$(forminfo).slideToggle(500);
	});	
	
	
	
	$("#r_p").keyup(function() {
		var parent = $(this).parent();
		var val = $(this).val();
		var score = testPassword(val);
		var strength_image = ''
				
		if(score < 16)
		{
		   strength_image = "door_open";
		}
		else if (score > 15 && score < 25)
		{
		   strength_image = "door";
		}
		else if (score > 24 && score < 35)
		{
		   strength_image = "lock_break";
		}
		else if (score > 34 && score < 45)
		{
		   strength_image = "lock"
		}
		else
		{
		   strength_image = "lock_delete";
		}		
		
		if (val == '') {
			strength_image = "delete";
		}
		
		$("#ajax_password").html('<img src="images/fam/'+strength_image+'.png" alt="password_strength" width="16" height="16" />');
	});
	
	$("#r_pr").keyup(function() {
		var parent = $(this).parent();
		var val = $(this).val();
		var rval = $("#r_p").val();
		if (rval != val) {
			$("#ajax_password_repeat").html('<img src="images/fam/delete.png" alt="password_strength" width="16" height="16" />');	
		} else {
			$("#ajax_password_repeat").html('<img src="images/fam/accept.png" alt="password_strength" width="16" height="16" />');	
		}
	});	
	
	$("#r_u").keyup(function() {
		var parent = $(this).parent();
		var val = $(this).val();
		if (val.length > 3) {
			//stick an image next to the form field
			if ($("#ajax_user").is(":visible")) {
				$("#ajax_user").attr("src", "images/ajax/small_form.gif");
			} else {
				$("#ajax_user").fadeIn(250);
			}
			//go go ajax
	        $.ajax({
	            type: "POST",
	            url: "ajax/index_ajax.php",
	            data: {
	                "func": "check_name",
	                "a_val": val
	            },
	            async: true,
	            success: function(ret) {
					ret = ar(ret);
					if (ret == "1") {
						//okay
						$("#ajax_user").attr("src", "images/fam/accept.png");
						$("#r_u").css("border-color","#E0DFE3");
					} else {
						$("#ajax_user").attr("src", "images/fam/delete.png");
						$("#r_u").css("border-color","#FF0000");
					}
					     
	            }
	        });			
		} else {
			$("#r_u").css("border-color","#E0DFE3");
			if ($("#ajax_user").is(":visible")) {
				$("#ajax_user").fadeOut(250);
			}
		}
	});
	
	$("#r_e").keyup(function() {
		var parent = $(this).parent();
		var val = $(this).val();
		if (val.length > 3) {
			//stick an image next to the form field
			if ($("#ajax_email").is(":visible")) {
				$("#ajax_email").attr("src", "images/ajax/small_form.gif");
			} else {
				$("#ajax_email").fadeIn(250);
			}
			//go go ajax
	        $.ajax({
	            type: "POST",
	            url: "ajax/index_ajax.php",
	            data: {
	                "func": "check_email",
	                "a_val": val
	            },
	            async: true,
	            success: function(ret) {
					ret = ar(ret);
					if (ret == "1") {
						//okay
						$("#ajax_email").attr("src", "images/fam/accept.png");
						$("#r_e").css("border-color","#E0DFE3");
					} else {
						$("#ajax_email").attr("src", "images/fam/delete.png");
						$("#r_e").css("border-color","#FF0000");
					}
					     
	            }
	        });			
		} else {
			$("#r_e").css("border-color","#E0DFE3");
			if ($("#ajax_email").is(":visible")) {
				$("#ajax_email").fadeOut(250);
			}
		}
	});	

});

 $.fn.smartBackgroundImage = function(url){
  var t = this;
  //create an img so the browser will download the image:
  $('<img />')
	.attr('src', url)
	.load(function(){ //attach onload to set background-image
	   t.each(function(){ 
	      // $(this).css('backgroundImage', 'url('+url+')').fadeIn(3000);
	   });
	});
   return this;
 }	