$(document).ready(function(){				
	
	$("#java").hide(); 
	
	if ($.browser.msie){
	$("#load").hide();
	$("#noie").show();
	}
	else{
	
	setInterval(
	function(){
	$("#load p").append(".");
	}, 500);
	
	var kvaka = $("#load img").attr("id");
	if (kvaka == "balet")
	{setInterval(balet, 1000);}       
	else if (kvaka == "swing")
	{setInterval(swing, 1700);}     


	var path = window.location.pathname;
	var s = path.match(/[a-zA-Z0-9-]+/);
	$("#nav div").append("<a href='../../" + s + ".html'><span>" + s + "</span>/&nbsp;</a>");
	$("#set").load("data.html #set");
	$("#desc").load("data.html #desc");
	$("#book").load("data.html img", pages);

	$(window).load(
		function(){
		$("#load").fadeOut(1000);
		$("#load img").animate({width: 0, height: 0, left: 150, top: 150}, 1000,
			function(){
			$("#cont").fadeIn(300);
			}
		);}
	);
	}
});
		

	function swing(){
	$("#load img").animate({width: 225, height: 300, left: 37, top: 50},500,
		function(){
		$(this).animate({width: 300, height: 400, left: 0, top: 0},250,
			function(){
			$(this).animate({width: 225, height: 300, left: 37, top: 50},250,
				function(){
				$(this).animate({width: 150, height: 200, left: 75, top: 50},500);
				}
			);}
		);}
	);}
	
	function balet(){
	var up = $("#load img").attr("src").replace("down","up");
	$("#load img").attr("src",up).animate({bottom: 100}, 400,
		function(){
		$(this).animate({bottom: 0}, 400,
			function(){
			this.src = this.src.replace("up","down");
			}
		);}	
	);}
	
	
	function pages(){
	var w = $("#book img").attr("width");
	var h = $("#book img").attr("height");
	$("#book").css({width: w*2, height: h, right: w/2});
	$("#box-book, #cont").css({width: w*2+12});
	$("#box-shadow").css({width: w*2});
	
	$("#shadow div").hide();
	
	$("#book img").each(
		function(){
		var s = $(this).attr("src");
		$(this).wrap("<div></div>").parent().css({backgroundImage: "url("+s+")", width: w, height: h}).empty();
		}
	);
	
	$("#book div:first").html("<a id='out-right'></a>");	
	$("#book div:even").each(
		function(){
		$(this).prependTo("#book");
		}
	);
	
	var n = $("#book div").length;
	$("#book div").slice(0,n/2).css({left: w});
	$("#book div").slice(n/2).css({width: 0, left: w*1.5});
	
	$("#number").append(" of " + ((n/2)+1));
	
	$("#book div").click(
		function(){
		var x = $("#book div").index(this);

		if (x == n/2){
			$("#shadow").animate({width: "50%", left: "25%"}, 100);
			$("#shadow div").fadeOut(200);
			$("#book").animate({left: -w/2}, 400);
		}
		else if (x == 0){
			$("#shadow").animate({width: "50%", left: "25%"}, 100);
			$("#shadow div").fadeOut(200);
			$("#book").animate({left: w/2}, 400);
		}
		else { 
			$("#shadow").fadeTo(400,1).animate({width: "100%", left: "0%"}, 400);
			$("#shadow div").fadeTo(400,1).slideDown(400);
			$("#book").animate({left: 0}, 400);
		}

		if(x < n/2){
		$("#book div").eq(x-1).html("<a id='out-right'></a><a id='in-left' class='for'></a>");
		$(this).animate({width: w/2}, 100,
			function(){
			$(this).animate({width: 0}, 200, 
				function(){$(this).css({left: w/2}).empty();});
			
			$("#book div").eq(n-x-1).html("<a id='in-right' class='for'></a><a id='out-left'></a>")
			.animate({width: w, left: 0},
				{duration: 600, complete:
				function(){
				$(this).prev().empty();
				$("#number span").html($("#number span").html()*1+1);
				}}
			);}
		);}
		
		else{
		$("#book div").eq(x-1).html("<a id='in-right' class='back'></a><a id='out-left'></a>");
		$(this).animate({width: w/2, left: w/2, backgroundPosition: "(" + -w/2 + "px 0px)"}, 100,
			function(){
			$(this).animate({width: 0, left: w, backgroundPosition: "(" + -w + "px 0px)"}, 200, 
				function(){$(this).css({left: w*1.5, backgroundPosition: "0px 0px"}).empty();});
			
			$("#book div").eq(n-x-1).html("<a id='out-right'></a><a id='in-left' class='back'></a>")
			.css({zIndex: 100, backgroundPosition: "right"}).animate({width: w, left: w},
				{duration: 600, complete:
				function(){
				$(this).css({zIndex: 0, backgroundPosition: "left"}).prev().empty();
				$("#number span").html($("#number span").html()*1-1);
				}}
			);}
		);}
		
		}
	);}
