function formatItem(row)
{
	return row[0];
}
function formatResult(row)
{
	return row[1];
}

$(document).ready(function(e) {

	$("div.acc").addClass('acc-js');
	$("div#block-wrapper").addClass('block-wrapper-js');
    // sets the length of each animation
    var duration = '100';
    // sets the type of easing you want
    var easing = 'easeOutQuad';
    $("#first-div").hover(function(){
        $("#first-div").animate({"left": "0px"},
            {queue:false, duration:duration, easing:easing});
        $("#second-div").animate({"left": "400px"},
          {queue:false, duration:duration, easing:easing});
        $("#third-div").animate({"left": "600px"},
            {queue:false, duration:duration, easing:easing});
    });
    $("#second-div").hover(function(){
        $("#first-div").animate({"left": "0px"},
             {queue:false, duration:duration, easing:easing});
        $("#second-div").animate({"left": "200px"},
             {queue:false, duration:duration, easing:easing});
        $("#third-div").animate({"left": "600px"},
            {queue:false, duration:duration, easing:easing});
    });
    $("#third-div").hover(function(){
        $("#first-div").animate({"left": "0px"},
            {queue:false, duration:duration, easing:easing});
        $("#second-div").animate({"left": "200px"},
            {queue:false, duration:duration, easing:easing});
        $("#third-div").animate({"left": "400px"},
            {queue:false, duration:duration, easing:easing});
    });
	
	
	// menu
    $(".menu, .menu-selected").hover(
		function()
		{
			var submenu = $("> .submenu", this);
			if ( submenu.css("display") == "none" )
			{
				submenu.show('fast');
			}
		},
		function()
		{
			$("> .submenu", this).fadeOut('fast');
		}
	);

    $(".crewmember").hover(
		function()
		{
			var submenu = $("> .crewmember-sub", this);
			if ( submenu.css("display") == "none" )
			{
				submenu.fadeIn('fast');
			}
		},
		function()
		{
			$("> .crewmember-sub", this).fadeOut('fast');
		}
	);

	
	// fastnav
	var fastnav = "#fastnav";
	var menuYloc = null;
	var fastmenu = "#fastmenu";

	menuYloc = parseInt($(fastnav).css("top").substring(0,$(fastnav).css("top").indexOf("px")))
	$(window).scroll(function () { 
		offset = menuYloc+$(document).scrollTop()+"px";
		$(fastnav).animate({top:offset},{duration:500,queue:false});
	});
	
	$(fastnav).hover(
		function () 
		{ 
			$(fastnav).animate({width:'160px'},{duration:400,queue:false});
			$(fastmenu).show({duration:300,queue:false});
		},
		
		function () 
		{ 
			$(fastnav).animate({width:'43px'},{duration:200,queue:false});
			$(fastmenu).hide({duration:100,queue:false});
		}
	);
		
	/* $("#rychlykontakt").hover(
		function () 
				{ 
					$("#popup").fadeIn({duration:300,queue:true});
				},
				
		function () 
				{ 
					$("#popup").fadeOut({duration:300,queue:true});
				}
		
		); */
	
	
	// PRODUKTY ZOOM
    $(".produkt-obal").hover(
		function()
		{	
			var submenu = $("> .produkt-zoom", this);
			if ( submenu.css("display") == "none" )
			{
				submenu.fadeIn("fast");
			}
			
			$(this).css("z-index", "1001");
		},
		function()
		{
			$("> .produkt-zoom", this).fadeOut('fast');
			$(this).css("z-index", "1000");
		}
	);




	// PRODUKTY ZOOM
    $("#left-side ").hover(
		function()
		{	
			$(this).css("z-index", "1002");
		},
		function()
		{
			$(this).css("z-index", "999");
		}
	);




		
    $("#galerie-first, #galerie-second, #galerie-third").hover(
		function()
		{	
			var vyskabig = $(this).height();
			var vyskasmall = $("> .popis-big-galerie", this).height();
			var vysledek = vyskabig - vyskasmall + "px";
			
			$("> .popis-big-galerie", this).animate({ top: vysledek }, {queue:false, duration:200});	
		},
		function()
		{
			$("> .popis-big-galerie", this).animate({top:"260px"},{duration:300,queue:false});
		}
	);


	$(".otazky").toggle(
		function () 
				{ 
					$("p", this).show({duration:300,queue:false});
				},
				
		function () 
				{ 
					$("p", this).hide({duration:300,queue:false});
				}
	);
	
	$(".viewertouch").toggle(
		function () 
				{ 
					$(".cislo", this).animate({ "font-size" : "30px", "width":"30px" });
					$(".nadpisbigbox", this).animate({ "font-size" : "14px" });
					$(".nadpisbigboxFAQ", this).animate({ "font-size" : "14px" });
					$("p", this).show({duration:300,queue:false});
					$(".bigboximg", this).show({duration:300,queue:false});
				},
				
		function () 
				{ 
					$(".cislo", this).animate({ "font-size" : "45px", "width":"50px" });
					$(".nadpisbigbox", this).animate({ "font-size" : "30px" });
					$(".nadpisbigboxFAQ", this).animate({ "font-size" : "20px" });
					$("p", this).hide({duration:300,queue:false});
					$(".bigboximg", this).hide({duration:300,queue:false});
				}
	);
	
	
	// SCROLL
	$(function() {
		
		$(".scrollable").scrollable();
		
		$(".items img").click(function() {
		
			// see if same thumb is being clicked
			if ($(this).hasClass("active")) { return; }
		
			// calclulate large image's URL based on the thumbnail URL (flickr specific)
			var url = $(this).attr("src").replace("/thumbs", "");
			var alt = $(this).attr("alt");
			var title = $(this).attr("title");
		
			// get handle to element that wraps the image and make it semi-transparent
			var wrap = $("#image_wrap").fadeTo("medium", 0.8);
		
			// the large image from www.flickr.com
			var img = new Image();
		
		
			// call this function after it's loaded
			img.onload = function() {
		
				// make wrapper fully visible
				wrap.fadeTo("fast", 1);
		
				// change the image
				wrap.find("img").attr("src", url).attr("alt", alt).attr("title", title);
		
			};
		
			// begin loading the image from www.flickr.com
			img.src = url;
		
			// activate item
			$(".items img").removeClass("active");
			$(this).addClass("active");
		
		// when page loads simulate a "click" on the first image
		})/*.filter(":first").click()*/;
		
		$("#gallery-scroll img").filter(":first").click();
	});


	$(function() {
		// setup ul.tabs to work as tabs for each div directly under div.panes
		$("ul.tabs").tabs("div.panes > .panefaderdiv", { effect: 'fade'});
	});


	var vyskastredu = $("#center-inner-main").height() - 40 + "px";
	$(".right-boxes-inside").css({ "min-height": vyskastredu });
	
	var novinky = $("#center-inner-main").height() - 456 + "px";
	$(".novinkyGO").css({ "min-height": novinky });

	// presunute sem z: galerie-produkty-pole.html
	try
	{
		$("body select").msDropDown({visibleRows:5, rowHeight:20});
	}
	catch(e)
	{
		//alert(e.message);
	}
	
	
	// system/product list - image scroll
	//$('.produkt-thumb img').imageScroll( {width:220, height:187} );
	$('#detail-produktu-foto-big a img').imageScroll( {width:365, height:275} );
	$('.detail-produktu-foto-small-img').imageScroll( {width:75, height:75, duration: 300} );
	$('.obrazek-pane img').imageScroll( {width:49, height:49, duration: 300} );
	$('.news-item-image img').imageScroll( {width:139, height:60, duration: 666} );
	$('#galleries-scroll div p img').imageScroll( {width:90, height:70, duration: 300} );
	$('#gallery-scroll div p img').imageScroll( {width:90, height:70, duration: 300} );
	$('#galleryMainImage').imageScroll( {width:600, height:394, duration: 666} );	
	$('.sivak').imageScroll( {width:40, height:40, duration: 666} );
	$('.sivak2').imageScroll( {width:160, height:120, duration: 300} );
	$('.gallery-list-img').imageScroll( {width:198, height:315, duration: 2500} );
	$('.hledani-img').imageScroll( {width:75, height:75, duration: 300} );	
	$('#profil-spolecnosti-foto-small a img').imageScroll( {width:75, height:75, duration: 300} );
	$('.postup-realizace a img').imageScroll( {width:90, height:70, duration: 300} );	
	
	$().piroBox({
		  my_speed: 400, //animation speed
		  bg_alpha: 0.1, //background opacity
		  slideShow : true, // true == slideshow on, false == slideshow off
		  slideSpeed : 3, //slideshow
		  close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
		  });
		  
	$("#hledani").autocomplete("/autocomplete-search.php", 
	{
		width: 400,
		scroll: true,
		scrollHeight: 400,
		selectFirst: false,
		formatItem: formatItem,
		formatResult: formatResult
	});
	
	// ----------------------------------------------------------------------------------------------
	// login
	var login_triggers = $(".login-modal-input").overlay({
		mask: 
		{
			color: '#ebecff',
			loadSpeed: 200,
			opacity: 0.9
		},
	
		closeOnClick: false,
		
		onBeforeLoad: function()
		{
			$("#login-modal").load(
				'/parts/login-modal.php',
				function()
				{
					$("#login-modal").load();
				}
			);
		}
	});
	
	$("#login-modal").load(
		function(ee)
		{	
			$("#authForm2 .close, #authForm3 .close").click( function(e)
			{
				login_triggers.eq(0).overlay().close();
				login_triggers.eq(1).overlay().close();
			});
			
			$("#authForm2").submit( function(e) 
			{
				this.pwd.value = SHA1(document.authForm1.pwd.value); 
				this.uname.value = document.authForm1.uname.value;
			
				$.ajax({
					url: '/parts/login-modal.php',
					type: 'POST',
					data: $("#login-modal form").serialize(),
					success: function(data) 
					{
						$('#login-modal').html(data);
						$("#login-modal").load();
					}
				});
			
				// do not submit the form
				return e.preventDefault();
			});
			
			$("#authForm3").submit( function(e) 
			{
				$.ajax({
					url: '/parts/login-modal.php',
					type: 'POST',
					data: $("#login-modal form").serialize()
				});
			});
		}
	);	
	
	// register
	var register_triggers = $(".register-modal-input").overlay({
		mask: 
		{
			color: '#ebecff',
			loadSpeed: 200,
			opacity: 0.9
		},
	
		closeOnClick: false,
		
		onBeforeLoad: function()
		{
			$("#register-modal").load(
				'/parts/register-modal.php',
				function()
				{
					$("#register-modal").load();
				}
			);
		}
	});
	
	$("#register-modal").load(
		function(ee)
		{
			$("#register-modal form .close").click( function(e)
			{
				register_triggers.eq(0).overlay().close();
				register_triggers.eq(1).overlay().close();
			});
			
			$("#register-modal form").submit( function(e) 
			{			
				$.ajax({
					url: '/parts/register-modal.php',
					type: 'POST',
					data: $("#register-modal form").serialize(),
					success: function(data) 
					{
						$('#register-modal').html(data);
						$("#register-modal").load();
					}
				});
			
				// do not submit the form
				return e.preventDefault();
			});
		}
	);
	
});


