// JavaScript Document

$(function(){
	var staticHeight = $(".categories-binder").height();
	
	$(".categories-binder .category").switchInfo();
	$("#navigationMenu").roller();
});

function hideContent()
{
	height = $(".content-binder .showUp").height()+54;
	$(".content-binder").animate({height: 0},1200,"easeInOutQuad");
	$(".content-binder .showUp").css({position:"absolute", left: ($("body").width()-998)/2+"px"})
	.animate(
			{"top":"-"+height+"px"},
			1000,
			"easeInQuad",
			function(){
				$(this).removeClass("showUp");
	});
	return false;
}
function showContent(commonBlockId)
{
	if ($(".content-binder .showUp").is("#"+commonBlockId))
		return false;
	if ($(".content-binder .content:animated").length)
		return false;
	
	var height=0;
	height = $(".content-binder .showUp").height()+54;

	if ($(".content-binder .showUp").length)
	{
		$(".content-binder").css("height",height+"px");
		$(".content-binder .showUp").css({position:"absolute", left: ($("body").width()-998)/2+"px"})
		.animate(
				{"top":"-"+height+"px"},
				1000,
				"easeInQuad",
				function(){
					$(this).removeClass("showUp");
				height = $("#"+commonBlockId).height()+54;
				$("#"+commonBlockId).css({display: "block", position:"absolute", top: height+"px", left: ($("body").width()-998)/2+"px"})
				.animate({top:0},1000,"easeOutQuad",function(){$(this).addClass("showUp");});
					
		});
		height = $("#"+commonBlockId).height()+54;
		$(".content-binder").animate({"height":height+"px"},2000,"easeInOutQuad");
	}else
	{
		$(this).removeClass("showUp");
		height = $("#"+commonBlockId).height()+54;
		$(".content-binder").animate({"height":height+"px"},2000,"easeInOutQuad");
		$("#"+commonBlockId).css({display: "block"})
		.animate({top:0},1000,"easeOutQuad",function(){$(this).addClass("showUp");});
	}
	return false;
	
}
$.fn.roller = function()
{
	rollerPositionTop = new Array("2px","25px","49px","73px","97px");
	
	$(this).children("li:not(#menuRoller)").find("a").hover(function(){
		var menuElementIndex = $("#navigationMenu li").index($(this).parent("li"));
		$("#menuRoller").stop();
		$("#menuRoller").animate({top: rollerPositionTop[menuElementIndex]},2000,"easeOutElastic");
		$(this).click(function()
		{
			$("#active").attr("id","inActive");
			$(this).parent("li").attr("id","active");
		});
	},function(){
			var menuElementIndex = $("#active").parent("ul").children("li").index($("#active"));
			$("#menuRoller").stop();
			$("#menuRoller").animate({top: rollerPositionTop[menuElementIndex]},2000,"easeOutElastic");
			$(this).click(function()
			{
				$(this).parent("li").attr("id","");
			});
	});
};


$.fn.switchInfo = function(){

	var staticHeight = $(".categories-binder").height()+"px";	
	
	$(this).css({height: 0});
	
	$("body").mousemove(function(){
		doWork(0,staticHeight);
	});
	

	$(this).children(".motto, .addintional-info").css("height",staticHeight);
	$(this).children(".addintional-info").css({display: "block",opacity: 0});
	

		
	this.motto = $(this).children(".motto");
	this.additionalInfo = $(this).children(".addintional-info");
	
	
		
	$(this).hover(
	function(){
		$(this).children(".motto").stop();
		$(this).children(".addintional-info").stop();
		$(this).children(".motto").animate({height: 0},1000,"easeOutQuad",function(){ $(this).css("display","none"); });
		$(this).children(".addintional-info").animate({opacity: 1});
	}, 
	function(){
		$(this).children(".motto").stop();
		$(this).children(".addintional-info").stop();
		$(this).children(".motto").animate({height: staticHeight},1000);
		$(this).children(".addintional-info").animate({opacity: 0});
	});
};

function doWork(i,staticHeight)
{
	el = $(".categories-binder .category");
	$(el[i]).animate({"height": staticHeight},1000,"easeOutBack");
	
	if (i==4)
	{
		clearTimeout(t);
		return;
	}
	
	t = setTimeout("doWork("+(++i)+",\""+staticHeight+"\")",105);
}
