positions = new Array();
var bgrN = (Math.floor(Math.random()*9)) + 1;
var bgrA = 6;
var dur = 3000;

function cSwitch() { var hash = document.location.hash; hash = hash.replace("#",""); bgr = (Math.floor(Math.random()*9)) + 1; switch (hash) { case "galleryRU": fetch("gallery", "RU", bgr); break; case "galleryEN": fetch("gallery", "EN", bgr); break; case "comicsRU": fetch("comics", "RU", bgr); break; case "comicsEN": fetch("comics", "EN", bgr); break; case "aboutRU": fetch("about", "RU", bgrA); break; case "aboutEN": fetch("about", "EN", bgrA); break; default: jQuery("#pages .page").addClass("enter").find(".wrap").append("<a href=\"pages/galleryRU.html\" id=\"enter\" title=\"Вход\">Вход</a>"); break; }; };
function fetch(cls, lng, bgr) { jQuery("#pages .page").removeClass().addClass("page " + cls); jQuery("#pages .page .bodyLayout").empty().load("pages/" + cls + lng + ".html .wrap", function() { jQuery("#pages .page").addClass("bgr" + bgr); }); };
function shift(cls, lng, bgr, dir) {
	var pageH = jQuery(".page:last").height();
	jQuery("#pages").append("<div class=\"page " + cls + "\"><div class=\"bodyLayout\"></div></div>").find(".page:last .bodyLayout").load("pages/" + cls + lng + ".html .wrap", function(){
		switch (dir) {
			case 0: jQuery("#pages").css("left", "-100%").find(".page").css("float", "right"); jQuery("#pages").animate({ left: "0" }, dur, function(){ jQuery("#pages").find(">.page:first").remove().end().find(".page").css("float", "left"); if (cls === "monkey") { jQuery(".navMonkey").animate({ top: "-225px" }, 200) } else { jQuery(".navMonkey").animate({ top: "-180px" }, 200) } }); jQuery("#pages .page:last").addClass("bgr" + bgr); break;
			case 1: jQuery("#pages .page").css("float", "none"); jQuery("#pages").animate({ top: "-" + pageH + "px" }, dur, function(){ jQuery("#pages").find(">.page:first").remove().end().find(".page").css("float", "left").end().css("top", "0"); if (cls === "monkey") { jQuery(".navMonkey").animate({ top: "-225px" }, 200) } else { jQuery(".navMonkey").animate({ top: "-180px" }, 200) }; }); jQuery("#pages .page:last").addClass("bgr" + bgr); break;
			case 2: jQuery("#pages .page").css("float", "left"); jQuery("#pages").animate({ left: "-100%" }, dur, function(){ jQuery("#pages").find(">.page:first").remove().end().css("left", "0"); if (cls === "monkey") { jQuery(".navMonkey").animate({ top: "-225px" }, 200) } else { jQuery(".navMonkey").animate({ top: "-180px" }, 200) }; }); jQuery("#pages .page:last").addClass("bgr" + bgr); break;
			case 3: jQuery("#pages .page").css("float", "none"); jQuery("#pages .page:last").prependTo("#pages"); jQuery("#pages").css("top", "-" + pageH + "px").animate({ top: "0" }, dur, function(){ jQuery("#pages").find(">.page:last").remove().end().find(".page").css("float", "left"); if (cls === "monkey") { jQuery(".navMonkey").animate({ top: "-225px" }, 200) } else { jQuery(".navMonkey").animate({ top: "-180px" }, 200) }; }); jQuery("#pages .page:first").addClass("bgr" + bgr); break;
		}; document.location.hash = "#" + cls + lng; }); };

jQuery(document).ready(function() {
	var lang = jQuery("body").hasClass("langRU");
	if (lang) { positions[0] = new Array("0","100px","80%","0","338px","68px","253px","51px","118px","24px"); positions[1] = new Array("50px","165px","80.5%","40px","331px","69px","248px","51px","115px","24px"); positions[2] = new Array("150px","225px","79%","80px","362px","96px","271px","72px","126px","33px"); } else { positions[0] = new Array("0","100px","88%","0","207px","68px","155px","51px","72px","24px");positions[1] = new Array("50px","165px","70.5%","40px","404px","55px","378px","51px","176px","24px");positions[2] = new Array("150px","225px","73%","80px","364px","76px","342px","72px","159px","33px"); };
	jQuery("#content table tr:odd").addClass("odd");
	jQuery(".navMonkey").hover(function() { jQuery(this).animate({ top: "0px" }, 500) }, function() { jQuery(this).animate({ top: "-180px" }, 500) });
	jQuery("#aboutSections .back").live("click", function() { jQuery(this).slideUp(500).prev().slideUp(1000, function() {for (i = 0; i <= 2; i++) { jQuery("#aboutSections li:eq(" + i + ")").removeClass("side").animate({ top: positions[i][1], left: positions[i][0] }, 500).find("h2").animate({ width: positions[i][6], height: positions[i][7], opacity: .5 }, 500, function() { jQuery(this).attr("style","") }); }; }).parent().removeClass("active"); });
	jQuery("#aboutSections>li h2").live("click", function() { var thisObject = jQuery(this).parent(); var thisIndex = jQuery("#aboutSections>li").index(thisObject); var thisClass = thisObject.attr("class"); if ((thisClass == "shortStory side") || (thisClass == "longStory side") || (thisClass == "vacations side")) { jQuery("#aboutSections>li.active").find(">.back").slideUp(500).prev().slideUp(1000, function() { var activeObject = jQuery(this).parent(); var activeIndex = jQuery("#aboutSections>li").index(activeObject); var swTop = thisObject.css("top"); jQuery(this).parent().removeClass("active").addClass("side").animate({ top: swTop, left: positions[activeIndex][2] }, 500).find("h2").animate({ width: positions[activeIndex][8], height: positions[activeIndex][9], opacity: .5 }, 500); thisObject.addClass("active").removeClass("side").animate({ top: 0, left: 0 }, 600).find("h2").animate({ width: positions[thisIndex][4], height: positions[thisIndex][5], opacity: 1 }, 500, function() { jQuery(this).next().slideDown(1000).next().slideDown(1000); }); }); } else { jQuery("#aboutSections").each(function() { var j = 0; for (i = 0; i <= 2; i++) { if (i != thisIndex) { jQuery("#aboutSections>li:eq(" + i + ")").addClass("side").animate({ top: positions[j][3], left: positions[i][2] }, 500).find("h2").animate({ width: positions[i][8], height: positions[i][9] }, 500, function() { thisObject.addClass("active").find(">div").slideDown(1000).next().slideDown(1000); }); j++; }; }; thisObject.animate({ top: 0, left: 0 }, 600).find("h2").animate({ width: positions[thisIndex][4], height: positions[thisIndex][5], opacity: 1 }, 500) }); }; });
	jQuery("#enter").live("click", function() { var cls = "gallery"; var lng = jQuery("body").attr("class"); lng = lng.replace("lang",""); jQuery("body").addClass("lang" + lng); shift(cls, lng, bgrN, 1); return false; });
	jQuery(".navigation a, .navMonkey a").live("click", function() { cls = jQuery(this).parent().attr("class"); cls = cls.replace("nav",""); cls = cls.toLowerCase(); var lng = jQuery("body").attr("class"); lng = lng.replace("lang",""); if ( cls === "about" ) { bgr = bgrA; var dir = (Math.floor(Math.random()*4)); } else if ( cls === "monkey" ) { dir = 3; var rnd = (Math.floor(Math.random()*4)); if (rnd != 1) { var hash = document.location.hash; hash = hash.replace("#", ""); hash = hash.replace("RU", ""); hash = hash.replace("EN", ""); cls = hash; if (cls === "about") { bgr = bgrA; } else if (bgrN != 9) { bgrN++; bgr = bgrN; } else { bgrN = 1; bgr = bgrN; }; } } else { if (bgrN != 9) { bgrN++ } else { bgrN = 1 }; bgr = bgrN; var dir = (Math.floor(Math.random()*4)); }; shift(cls, lng, bgr, dir); return false; });
	jQuery(".langRU .languages .EN span, .langEN .languages .RU span").live("click", function() { var cls = jQuery(".page:last").hasClass("gallery"); if (cls) { var page = "gallery" } else { var cls = jQuery(".page:last").hasClass("comics"); if (cls) { var page = "comics" } else { var cls = jQuery(".page:last").hasClass("about"); if (cls) { var page = "about" } else { var page = "monkey" } } }; var lng = jQuery(this).parent().attr("class"); 		jQuery("#pages").find(".page .bodyLayout").load("pages/" + page + lng + ".html .wrap", function() { if (lng === "RU") { jQuery("body").removeAttr("class").addClass("langRU"); positions[0] = new Array("0","100px","80%","0","338px","68px","253px","51px","118px","24px"); positions[1] = new Array("50px","165px","80.5%","40px","331px","69px","248px","51px","115px","24px"); positions[2] = new Array("150px","225px","79%","80px","362px","96px","271px","72px","126px","33px"); } else { jQuery("body").removeAttr("class").addClass("langEN"); positions[0] = new Array("0","100px","88%","0","207px","68px","155px","51px","72px","24px"); positions[1] = new Array("50px","165px","70.5%","40px","404px","55px","378px","51px","176px","24px"); positions[2] = new Array("150px","225px","73%","80px","364px","76px","342px","72px","159px","33px"); }; }); });
	cSwitch();
});