$(document).ready(function() { 
	if(login==1) {
		$("div.column").hide();
		$("form").show();
	}
						   
	var cursec =""					   
	
	$("a.section").css('opacity',0.7);
	
	$("a.section").hover(
		function()
		{
			$(this).animate({opacity: 1, paddingBottom: '3px'}, 250);
		},
		function()
		{
			$(this).animate({opacity: 0.7, paddingBottom: 0}, 250);
		}
	);
	
	$("a.section").click(function() {
		$("div.content").fadeOut("fast");
		if($(this).attr("title")!=cursec) {
			cursec = $(this).attr("title");
			$("div." + cursec).fadeIn("fast");
		} else {
			cursec="";
		}
	});
	
	$("a.login").click(function() {
		if($("form").is(":hidden")) {						
			$("div.column").fadeOut("fast");
			$("form").fadeIn("fast");
		} else {
			$("form").fadeOut("fast");
			$("div.column").fadeIn("fast");
		}
	});
	
	$("#center").css("margin-left", "-" + ($("#center").width() * .5) + "px");
	
	$(window).resize(function() {
		$("#center").css("margin-left", "-" + ($("#center").width() * .5) + "px");
	});
	
	//Preloader	
	$.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
		$("<img>").attr("src", arguments[i]);
	  }
	}
	
	$.preloadImages(
	  "images/abg.png",
	  "images/ahbg.png",
	  "images/colbg.png"
	);
	
	$('form').submit(function() {
		$(this).append("<img src='/images/loading.gif' alt='' class='loading'>");
		$.ajax({
			type: "POST",
			url: "client/login.php",
			data: $("form.login").serialize(),
			dataType: "json",
			success: function(data, textStatus) {
				if (data.redirect) {
					window.location.href = data.redirect;
				}
				else {
					$("span.error").text(data.error);
					$(".loading").remove();
				}
			}
		});
		return false;
	});
	
	$("a.submit").click(function() {
		$("form").submit();
	});						 
	
});

$(window).load(function() {
	$("#bg img").fadeIn(500);
});	

