/*
* ����� �������.
*/


// jQuery.noConflict();

(function($) {

	$.bBigCoatShowing	= false;

	$.InitSite	= function()
		{
			if ( $('#BigCoat').is("div") )
			{
				$('#BigCoat img').eq(0).ready( PlayCollection );
			} else if ( $('body.FirstPage').is("body") )
			{
//				$("#MovieFlash").css("visibility", "hidden");
				PlayLogo();
			} else {
				PlayBigImages();
			}
			$('#TextContent').css("background","#ABABAB");
		}

	function PlayLogo()
		{
			$("#Logo").fadeIn(5000, function()
				{
					$("#Logo").animate({opacity: 1}, 1000, "linear", function()
						{
							$("#MainBack img").eq(0).show();
							$("#MainBack").fadeIn(4000);
							$("#Logo").animate({
								top: 0,
								left: 790
							}, 2000, "easeInOutQuad", function()
							{
								PlayMenu();
//								PlayBigMovie();
								PlayBigImages();
							});
							
							$("#MusicBtn").fadeTo(0, 0, function()
								{
									$("#MusicBtn").animate({
										left: -40,
										opacity: 1
									}, 1500, "easeInOutQuad");
								});
						})
				});
		}

	function PlayMenu()
		{
			$("#MainMenu li").add("#MainMenu div").fadeTo(0, 0, function()
				{
					$( this ).css("display", "block");
				});
			
//			$("#MainMenu li").fadeTo(1000, 1);
			var j = 500;
			for( var i = 0; i < $("#MainMenu li").length; i++ )
			{
				setTimeout('$("#MainMenu li").eq(' + i + ').animate({top: 0, opacity: 1}, 2000, "swing");', j);
				j += 750;
			}
			setTimeout('$("#MainMenu div").animate({top: 0, opacity: 1}, 2000, "swing");', j);
		}

	function PlayBigMovie()
		{
			setTimeout( function()
				{
					document.getElementById("MainFlash").StartPlaying();
				}, 100 );
			
		}

	ShowBigMovie	= function ()
		{
//			alert( 5 );
			$("#MovieFlash").css("visibility", "visible");
		}

	function PlayBigImages()
		{
			$('#MainBack img').eq(0).show();
			$('#MainBack').cycle({
				fx: 'fade',
				speed: 2000,
				easing: "swing",
//				easing: "easeInBounce",
				timeout: 5000
//				autostop: 4
			});
		}

	function PlayCollection(e)
		{
			// ������ ���������� ������� ����������� ��� ������. ;-)
			// ������� title, ����� �� ������������� ������.
			$('#BigCoatimg').click( function()
				{
					ShowBigCoat( this, true );
				});
	
		
/*
			$('#MainBack img').eq(0).show();
			$("#MainBack").fadeTo("slow",0.4);
*/
//			$('#SmallGallery').show("slow");
			$('#GalleryArrows').show("slow");
			$("#BigCoat").show();
			$('#BigCoat').cycle({
				containerResize: false,
				slideResize: false,
				fx:			"fade",
				speed:		1000,
				timeout: 	4500,
				next:		"#NextImg",
				prev:		"#PrevImg",
				before:		CheckBigCoat,
				after:		BigCoatAfter
			});
		}

	function CheckBigCoat(oImgSmall, oImgNext)
		{
			var x = 820 / 432;
			if( window.innerHeight < 600 )
				$("#BigCoat IMG").css({"height": 550, "width": (550 / x)});
			else if( window.innerHeight > 870 )
				$("#BigCoat IMG").css({"height": 820, "width": 432});
			else
				$("#BigCoat IMG").css({"height": (window.innerHeight - 70), "width": ((window.innerHeight - 70) / x)} );

			$("#BigCoat").css("left", (350 - ($("#BigCoat IMG").eq(0).width() / 2)));
			$("#PrevImg").css("left", (0 - ($("#BigCoat IMG").eq(0).width() / 2) - 150));
			$("#NextImg").css("left", (($("#BigCoat IMG").eq(0).width() / 2)));

			$("#BigCoatDesc").html("").hide().fadeIn(1000);

			$("#Coat_" + $(oImgNext).attr("id")).clone().attr("id", "CurrentDesc").appendTo("#BigCoatDesc");

		}

	function HideBigCoat(oImgSmall)
		{
			if( $.bBigCoatShowing )
				$("#BigCoat").fadeOut("fast", function(){ $( this ).empty() });

		}
	
	function BigCoatAfter(oImgSmall)
		{
		}


	function ShowBigCoat( oImgSmall, bFromClick )
		{
			if( $.bBigCoatShowing && bFromClick )
			{
				$.bBigCoatShowing = false;
				$('#BigCoat').cycle("resume");
			} else {
				$('#BigCoat').cycle("pause");
				$("<img>").attr("src", $( oImgSmall ).attr("src-big")).appendTo("#BigCoat");
				$("#Coat_" + $(oImgSmall).attr("id").substr(3)).clone().attr("id", "CurrentDesc").appendTo("#BigCoat");
				$("#BigCoat").fadeIn("slow");
				$.bBigCoatShowing	= true;
			}
		}
////////////////////////////////////////////////////////////////////////////////
$(document).ready(
	function(){
		if( !($('body.FirstPage').is("body")) )
			$.InitSite();
	}
);


})(jQuery);

