$(document).ready(function() {
	$("#leftWindow .content a:not(:first)").hide();
	setTimeout('changeLeftWindow()',5000);
	
	$("#accordion").accordion({
		header: "h3",
		autoHeight: false,
		collapsible: true,
		active: false,
		navigation: true
	});
	
	$(".lightbox").lightbox({
		fitToScreen: true,
		imageClickClose: false,
        disableNavbarLinks: true
	});
	
	$(".product").click(function() {
		//Cancel the link behavior
		//Get the A tag
		//var id = "#dialog";
		//transition effect
		if ($.browser.msie && $.browser.version.substring(0,1) === '6') {
			$('#mask').height($(".redBord").height());
		}
		$('#mask').fadeIn(300);	
		$('#mask').fadeTo("fast",0.9);	
		
		var top = $(document).scrollTop();
		var $hgh = 40 + top - 150;
		if ($hgh < 40) $hgh = 40;
		var win = $(this).next(".window");
		$(win).show();
		var parHgh = $(".mainWindow").height();
		//$(win).offset().top
		var compHgh = top + $(win).height() - 100;
		var diff = compHgh - parHgh + 80;
		if (parHgh < compHgh) {
			$hgh -= diff;
			$("html").scrollTop(top-diff);
		}
		$(win).css("top", $hgh + "px");
	});
		
	$('.close').click(function (e) {
		// zatvorenie okna s produktom
		if ($("#mask").is(":visible")) {
		//Cancel the link behavior
			e.preventDefault();
			$('#mask, .window').hide();
		}
	});
	
	//if mask is clicked
	$('#mask').click(function () {
		
		$(this).hide();
		$('.window').hide();
	});
	

});

function changeLeftWindow() {
	var $vis = $("#leftWindow .content a:visible");
	var $next = $($vis).next("a");
	if ($next.length == 0)
		$next = $("#leftWindow .content a:first");
	$($next).fadeIn("normal", function () {
			setTimeout('changeLeftWindow()',5000);
	})
	$($vis).fadeOut();
}
