$(document).ready(function(){

	//$(document).pngFix();
	
	
	//search stuff
	$("#memberSearch").click(function(event) 
	{
		event.preventDefault();
		
		//--
		
		var s = $("#searchString").val();

		window.location = "http://"+window.location.host+"/uyebul/1/"+escape(_utf8_encode(s));

	});
	
	
	//------------------------------------------------
	
	var isLoginShown = false;
	var isForgotShown = false;

	/* Hover Stuff */
	$("#footer_content table td a img").each(function()
	{
		$(this).fadeTo(0, 0.2);
		
		$(this).hover(

			function () 
			{
				$(this).fadeTo("fast", 1);
			},
			function () 
			{
				$(this).fadeTo("fast", 0.2);

			}

		);
		
	});
	
	/* Login Stuff */
	$("#header #menu7 a").click(function(event) 
	{
		event.preventDefault();
		
		if(isLoginShown == false)
		{
			$("#login_email").val("");
			$("#login_password").val("");
			
			isLoginShown = true;
			$("#login").show("fast");
		}
		else
		{
			isLoginShown = false;
			$("#login").hide("fast");
			
			isForgotShown = false;
			$("#forgotpassword").hide("fast");
			
		}
	});
	
	/* Forgot Stuff */
	$("#forgotpassword_button").click(function(event) 
	{
		event.preventDefault();

		if(isForgotShown == false)
		{
			$("#forgot_email").val("");
			
			isForgotShown = true;
			$("#forgotpassword").show("fast");
		}
		else
		{
			isForgotShown = false;
			$("#forgotpassword").hide("fast");
			
		}
	});

	setInterval( "counterCheck()", 5000 );
	counterCheck();
});


function counterCheck()
{
	var requestData = new Object();
	
	requestData.counterCheck = 1;
	
	$.ajax({
		type: "POST",
		url: "/pactions/",
		data: requestData,

		success: function(res)
		{
			
			var datas = res.split("#");
			datas[1] = addCommas(datas[1]);
			datas[0] = addCommas(datas[0]);
			
			$("#counter #total_count").html( datas[1] );
			$("#counter #total_user b").html( datas[0] );
			
			$("#counter").fadeIn("slow");
			
			
		}

	});
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}