$(document).ready(function() {
   var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if (badBrowser) {
     alert("Bohužel stránky NOI CZ s.r.o. se ve Vašem prohlížeči zobrazují chybně.\nAktualizujte Váš prohlížec Internet Explorer 6.0 na novější verzi.");
   }
});
function printTable() {
	var printContent = document.getElementById("cenik_tabulka");
	var windowUrl = 'about:blank';
	var num;
	var uniqueName = new Date();
	var windowName = 'Print' + uniqueName.getTime();
	var printWindow = window.open(num, windowName, 'left=50000,top=50000,width=0,height=0');
	printWindow.document.write(printContent.innerHTML);
	printWindow.document.close();
	printWindow.focus();
	printWindow.print();
	printWindow.close();
}
//FOTKY
$(function() {
	$('.fotky_lb').lightBox();
	$('.fotky a').lightBox();
});

$(document).ready(function() {
	aktivni($('input#pecko').val(),$('input#decko').val());
  
    //When mouse rolls over  
    $(".menu_polozka").mouseover(function(){  
        $(this).stop().animate({height:'80px'},{queue:false, duration:600})  
    });  
  
    //When mouse is removed  
    $(".menu_polozka").mouseout(function(){  
        $(this).stop().animate({height:'50px'},{queue:false, duration:600})  
    });  
});

function aktivni(prvni, druhy) {
//	if(parametr == "p") {	
//		$(".menu").children("div").each(function (){ 
//			$(this).removeClass("menu_aktivni");
//		});
//		if(sender == "drevene-brikety") { $('.menu_b').addClass("menu_aktivni"); }
//		if(sender == "palubky-a-podlahovky") { $('.menu_papp').addClass("menu_aktivni"); }
//		if(sender == "zahradni-program") { $('.menu_zp').addClass("menu_aktivni"); }
//		if(sender == "palety-a-obaly") { $('.menu_pao').addClass("menu_aktivni"); }
//		
//	}

//	if(sender == "menu") {
//		$('.submenu_leve').css("display", "none"); 
//	}
	//nastaveni aktivni class v hornim rychlym menu
	if(prvni == "1") { $('.r_'+druhy).addClass("menu_r_aktivni"); }
	
	if(prvni != "1") {	
		//obarvit zvolenou polozku submenu
		$(".submenu_leve").children("div").each(function (){ 
			$(this).removeClass(".submenu_leve_aktivni");
		});
		if (druhy != null){
			$("div.submenu_leve_polozka:nth-child("+(parseInt(druhy)+1)+")").addClass("submenu_leve_aktivni");
		}
		//zvyraznit zvolenou polozku v menu
		$("ul.menu").children("li").children("a").each(function (){ 
			$(this).removeClass(".active_menu");
		});
		if (druhy != null){
			$("ul.menu > li:nth-child("+(parseInt(prvni)-1)+")").children("a").addClass("active_menu");
		}
		
		
	}
}

//PALETY A OBAL 
$(document).ready(function() {
	//$(".submenu").scrollFixed();
});

function slideSwitch2() {
    var $active = $('#bigPic DIV.active');
    if ( $active.length == 0 ) $active = $('#bigPic DIV:last');
    var $next =  $active.next().length ? $active.next()
        : $('#bigPic DIV:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 800, function() {
            $active.removeClass('active last-active');
        });
	$('#thumbs li').removeClass('active-li');
	$($('#thumbs li')[$next]).addClass('active-li');
}
$(function() {
    setInterval( "slideSwitch2()", 2000 );
});

//postrani submenu se drzi obahu stranky
$.fn.scrollFixed = function(params){
params = $.extend( {appearAfterDiv: 0, hideBeforeDiv: 0}, params);
var element = $(this);

if(params.appearAfterDiv)
	var distanceTop = element.offset().top + $(params.appearAfterDiv).outerHeight(true) + element.outerHeight(true);
else
	var distanceTop = element.offset().top;

if(params.hideBeforeDiv)
	var bottom = $(params.hideBeforeDiv).offset().top - element.outerHeight(true) - 10;
else
	var bottom = 200000;				

	$(window).scroll(function(){	
		if( $(window).scrollTop() > distanceTop && $(window).scrollTop() < bottom )
			element.css({'position':'relative', 'top':'-80px;', 'left':'0'});
		else
			element.css({'position':'static'});				
	});			  
};

//skripty pro menu
$(function() {
	/* position of the <li> that is currently shown */
	var current = 0;
	
	var loaded  = 0;
	for(var i = 1; i < 5; ++i)
		$('<img />').load(function(){
			++loaded;
			if(loaded == 4){
				$('#bg1,#bg2,#bg3,#bg4').mouseover(function(e){
					
					var $this = $(this);
					/* if we hover the current one, then don't do anything */
					if($this.parent().index() == current)
						return;

					/* item is bg1 or bg2 or bg3, depending where we are hovering */
					var item = e.target.id;

					/*
					this is the sub menu overlay. Let's hide the current one
					if we hover the first <li> or if we come from the last one,
					then the overlay should move left -> right,
					otherwise right->left
					 */
					if(item == 'bg1' || current == 2)
						$('#menu .sub'+parseInt(current+1)).stop().animate({backgroundPosition:"(-400px 0)"},300,function(){
							$(this).find('li').hide();
						});
					else
						$('#menu .sub'+parseInt(current+1)).stop().animate({backgroundPosition:"(400px 0)"},300,function(){
							$(this).find('li').hide();
						});

					if(item == 'bg1' || current == 2){
						/* if we hover the first <li> or if we come from the last one, then the images should move left -> right */
						$('#menu > li').animate({backgroundPosition:"(-950px 0)"},0).removeClass('bg1 bg2 bg3 bg4').addClass(item);
						move(1,item);
					}
					else{
						/* if we hover the first <li> or if we come from the last one, then the images should move right -> left */
						$('#menu > li').animate({backgroundPosition:"(950px 0)"},0).removeClass('bg1 bg2 bg3 bg4').addClass(item);
						move(0,item);
					}

					/*
					We want that if we go from the first one to the last one (without hovering the middle one),
					or from the last one to the first one, the middle menu's overlay should also slide, either
					from left to right or right to left.
					 */
					if(current == 2 && item == 'bg1'){
						$('#menu .sub'+parseInt(current)).stop().animate({backgroundPosition:"(-235px 0)"},300);
					}
					if(current == 0 && item == 'bg3'){
						$('#menu .sub'+parseInt(current+2)).stop().animate({backgroundPosition:"(235px 0)"},300);
					}

					
					/* change the current element */
					current = $this.parent().index();
					
					/* let's make the overlay of the current one appear */
				   
					$('#menu .sub'+parseInt(current+1)).stop().animate({backgroundPosition:"(0 0)"},300,function(){
						$(this).find('li').fadeIn();
					});
				});
			}	
		}).attr('src', 'img/'+i+'.jpg');
	
				
	/*
	dir:1 - move left->right
	dir:0 - move right->left
	 */
	function move(dir,item){
		if(dir){
			$('#bg1').parent().stop().animate({backgroundPosition:"(0 0)"},200);
			$('#bg2').parent().stop().animate({backgroundPosition:"(-235px 0)"},300);
			$('#bg3').parent().stop().animate({backgroundPosition:"(-470px 0)"},400);
			$('#bg4').parent().stop().animate({backgroundPosition:"(-705px 0)"},400,function(){
				$('#menuWrapper').removeClass('bg1 bg2 bg3 bg4').addClass(item);
			});
		}
		else{
			$('#bg1').parent().stop().animate({backgroundPosition:"(0 0)"},400,function(){
				$('#menuWrapper').removeClass('bg1 bg2 bg3 bg4').addClass(item);
			});
			$('#bg2').parent().stop().animate({backgroundPosition:"(-235px 0)"},300);
			$('#bg3').parent().stop().animate({backgroundPosition:"(-470px 0)"},200);
			$('#bg4').parent().stop().animate({backgroundPosition:"(-705px 0)"},200);
		}
	}
});
//konec skriptu pro menu

