// Delay Plugin for jQuery
// - http://www.evanbot.com
// - ø 2008 Evan Byrne

jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});

	return this;
};

var isOpenUniversal = false;
function showOverlayBoxUniversal() {
	if( isOpenUniversal == false ) return;

	var top = $(window).scrollTop() + ( $(window).height() - $('.overlayBoxUniversal').height() )/2;
	if (top<10)
		top = 10;

	$('.overlayBoxUniversal').css({
		display:'block',
		left:( $(window).width() - $('.overlayBoxUniversal').width() )/2,
		top: top ,
		position:'absolute'
	});
	$('.bgCoverUniversal').css({
		display:'block',
		width: $(window).width(),
		height:$("#bottom").height() + 308
	});
}
function doOverlayOpenUniversal(color) {
	isOpenUniversal = true;
	if (color!='')
		$('.overlayColor').addClass(color)
	showOverlayBoxUniversal();
	$('.bgCoverUniversal').css({opacity:0}).animate( {opacity:0.7, backgroundColor:'#1d3e8b'} );
	return false;
}
function doOverlayCloseUniversal() {
	isOpenUniversal = false;
	$('.overlayBoxUniversal').css( 'display', 'none' );
	$('.bgCoverUniversal').hide();
	$(".reg-left select").show();
  return true;
}


$(document).ready(function(){

	if( $("html").height() > ($("#bottom").height()+308) )
    $("#bottom").height($("html").height()-308);
	
	$("#menu > ul > li").hover(
      function () {
        $(this).children(".submenu").show();
        $(this).children("a").addClass("hover");
      },
      function () {
        $(this).children(".submenu").hide();
        $(this).children("a").removeClass("hover");
      }
	);
	
	$("#menu > ul > li").mouseleave(function(){ //zavreni menu pojistka
    $(this).children(".submenu").hide();
  });
//podmenu pro ie6	
	$(".submenu ul li").hover(
      function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
	);
//srovnani vysek
	if ( $(".tnvycet-right").height() > ($(".tnvycet-left").height()+10+58) ){
	  $(".vycet").height( $(".tnvycet-right").height() - 10 - 58 - 4 - $(".vycet-head").height() );
	}
	
//mapa na tnv-pridat	
$(".mapatoggle,.kdytoggle").click(function () {
    $(this).next().toggle();
    $(this).next().mouseleave(function(){ //zavreni
    	$(this).hide();
  	});
  	return false;
  });
  
  $(".mapa map area").click(function () {
    $(".kde a").text($(this).attr("alt"));
  });
  $(".mapa map area").mousemove(function () {
    $(".kde a.mapatoggle").text($(this).attr("alt"));
  });
  
  $(".kdy-content a").click(function () {
    $(".kdytoggle").text($(this).text());
  });
  

//pohyblivy brumik u registrace  
  $(window).scroll(function() {
    var heightBlok2=348 + $(".reg-left form").height() -($(".reg-roll").height()+286);
  	if( ($(window).scrollTop() > 294) && ($(window).scrollTop() < heightBlok2) ){
			$(".reg-roll").css("top", -48 + $(window).scrollTop() - 294)
		}
			else{
				if( ($(window).scrollTop() < 294))
					$(".reg-roll").css("top", -48 )
        if( ($(window).scrollTop() > heightBlok2))
					$(".reg-roll").css("top", heightBlok2-348 )
			}
	});
	
//text napovedz do brumikova boxu	
  $(".reg input.text").focus(function () {
    $(".info-box p").text($(this).next("input").val())
  });
  $(".reg select").focus(function () {
    $(".info-box p").text($(this).parent().parent().find("input").val())
  });


	function datumradio(){
		$(".cas-right,.cas-left").css("visibility","visible");
		switch($('.datum input:radio:checked').val())
		{
		case "vden":
		  $(".cas-right").css("visibility","hidden");
		  break;
		case "celorocne":
		  $(".cas-right,.cas-left").css("visibility","hidden");
		  break;
		}		
	}
  
//tnv prepinani typu datumu
	datumradio(); 
  $(".datum input:radio").change(function(i) {
		datumradio();
  });
  

//hodnocení hvezdama
/*  $.each($(".rating .stars a"), function(i, val) {
		$(this).mouseover(function(){
      //alert(i);
      for(k=0;k<=i;k++){
        $(".rating .stars a").eq(k).addClass("hover")
      }
		}).mouseout(function(){
        $(".rating .stars a").removeClass("hover")
		})
	});
*/
  $.each($(".stars"), function(it, valt) {
		$.each($(this).children(), function(i, val) {
			$(this).mouseover(function(){
	      //alert(i+' '+val);
	      for(k=0;k<=i;k++){
	        $(this).parent().children().eq(k).addClass("hover");
	      }
			}).mouseout(function(){
	        $(this).parent().children().removeClass("hover")
			})
    });
	});



//Login formular a text ve vstupnim poli
	$(".form-login input.text").eq(0).addClass("text2");
	$(".form-login input.text").eq(1).addClass("heslo2");
  $(".form-login input.text").eq(0).focus(function () {
    $(this).removeClass("text2");
  });
  $(".form-login input.text").eq(0).blur(function () {
    if( $(this).val() == '')
      $(this).addClass("text2");
  });
  $(".form-login input.text").eq(1).focus(function () {
    $(this).removeClass("heslo2");
  });
  $(".form-login input.text").eq(1).blur(function () {
    if( $(this).val() == '')
      $(this).addClass("heslo2");
  });
  
  
// Reg form - deti
	var MAXpocetDeti = 6;
  $(".dite").hide();
  $(".dite").eq(0).show();
  $(".no-hide").show();
  $(".dalsi-dite a").click(function () {
  	if ( $(".dite:visible").length < MAXpocetDeti )
  		$(".dite").eq($(".dite:visible").length).show();
  		else
  			alert("další dítě nelze přidat");
  			
		$(".odebrat-dite").show();
		if ( $(".dite:visible").length >= MAXpocetDeti )
			$(".dalsi-dite").hide();
		
  	return false;
  });
  
  $(".odebrat-dite a").click(function () {
  	var pocet = $(".dite:visible").length;
  	if (pocet>1){
			$(".dite").eq(pocet-1).hide();
			$(".dite").eq(pocet-1).children().children(".line-in").children("input").val("");	
		}
			else{
				alert('První dítě nelze smazat, nevyplňujte jméno');
			}
			
		var pocet = $(".dite:visible").length;	
		if (pocet<2){
			if ( $(".odebrat-dite").is(':visible') )  //for fun podminka
				$(".odebrat-dite").hide();
		}
		if (pocet<MAXpocetDeti){
			$(".dalsi-dite").show();
		}
	
	
  	return false;
  });
  
  
  $(".doplnky-toggle,.doplnky").toggle();
  $(".doplnky-toggle").one("click", function(event) {
    $(".doplnky-toggle,.doplnky").toggle();
    return false;
	});

  


  //the status of overlay box
var isOpen = false;
//function to display the box
function showOverlayBox() {
	//if box is not set to open then don't do anything
	if( isOpen == false ) return;
	// set the properties of the overlay box, the left and top positions
	//spocitam top pozici
	
	$('.overlayBox').css({
		display:'block',
		left:( $(window).width() - $('.overlayBox').width() )/2,
		top:$(window).scrollTop() + ( $(window).height() - $('.overlayBox').height() )/2 -20,
		position:'absolute'
	});
	// set the window background for the overlay. i.e the body becomes darker
	$('.bgCover').css({
		display:'block',
		width: $(window).width(),
		height:$("html").height()
	});
}
function doOverlayOpen() {
	//set status to open
	isOpen = true;
	showOverlayBox();
	$('.bgCover').css({opacity:0}).animate( {opacity:0.7, backgroundColor:'#1d3e8b'} );
	// dont follow the link : so return false.
	return false;
}
function doOverlayClose() {
        //set status to closed
	isOpen = false;
	$('.overlayBox').css( 'display', 'none' );
	$('.bgCover').hide();
  return true;
}
$(".overlayBox form").submit(function() {
  doOverlayClose();
  return true;
});
// if window is resized then reposition the overlay box
$(window).bind('resize',showOverlayBox);
// activate when the link with class launchLink is clicked
$('a.launchLink').click( doOverlayOpen );
// close it when closeLink is clicked
$('.overlayBox a.closeLink').click( doOverlayClose );


$('.sdilet').click(function () {
	$(".overlayBox").addClass("sdilet").height(297);
	doOverlayOpen();
  return false;
});



$('.overlayBoxUniversal a.closeLink').click( doOverlayCloseUniversal );

/*
$('#news-hp a').click(function () {
	doOverlayOpenUniversal('red');
  return false;
});
*/


  $.each($(".over"), function(i, val) {
		$(this).mouseover(function(){
      $(".pop").eq(i).show();
      $(".popbg").eq(i).show();
        // Delay 1 second...
  		$(this).delay(4000,function(){
        if( $(".pop").eq(i).hasClass("mouseover") ){
				}
				  else{
						$(".pop").eq(i).hide();
						$(".popbg").eq(i).hide();
					}
			})
		})
	});
	
	$(".pop").mouseover(function(){
    $(this).addClass('mouseover');
	});
	$(".pop").mouseleave(function(){
    $(this).removeClass('mouseover').hide();
    $(this).prev().hide();
	});
	
	
	
	$('.cnt-5nej-in').tabs();

	if ($(".znak60 input.text").val()=="" ){
		$(".znak60 input.text").addClass("frinput");
	}

  $(".znak60 input.text").focus(function () {
    $(this).removeClass("frinput");
  });
  $(".znak60 input.text").blur(function () {
    if( $(this).val() == ''){
      $(this).addClass("frinput");
		}
  });

	
//harmonika
	$(".harmonika h4,.harmonika div").removeClass("open");


	$(".harmonika h4").click(function () {
		$(this).toggleClass("open");
		$(this).next().toggleClass("open");
	});
	

	$(".svacinka td.cerealni,.svacinka td.cerealni-active").click(function () {
		if( $(this).hasClass("cerealni") ){
  		$(this).removeClass("cerealni");
			$(this).addClass("cerealni-active");
		}
		  else{
        $(this).addClass("cerealni");
				$(this).removeClass("cerealni-active");
			}
	});
	
	$(".svacinka td.mlecne,.svacinka td.mlecne-active").click(function () {
		if( $(this).hasClass("mlecne") ){
  		$(this).removeClass("mlecne");
			$(this).addClass("mlecne-active");
		}
		  else{
        $(this).addClass("mlecne");
				$(this).removeClass("mlecne-active");
			}
	});
	
	$(".svacinka td.ovoce,.svacinka td.ovoce-active").click(function () {
		if( $(this).hasClass("ovoce") ){
  		$(this).removeClass("ovoce");
			$(this).addClass("ovoce-active");
		}
		  else{
        $(this).addClass("ovoce");
				$(this).removeClass("ovoce-active");
			}
	});
	
 $(".svacinka td.napoj,.svacinka td.napoj-active").click(function () {
		if( $(this).hasClass("napoj") ){
  		$(this).removeClass("napoj");
			$(this).addClass("napoj-active");
		}
		  else{
        $(this).addClass("napoj");
				$(this).removeClass("napoj-active");
			}
	});
	
	svacinka=new Array(0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0);
	$.each($(".svacinka table td"), function(i, val) {
		$(this).click(function () {
			var re=/active/;
			var result=re.test(this.className); //vrací: true
			if (result)
			  svacinka[i]=1;
			  else
			    svacinka[i]=0;
			//alert(svacinka);
			//alert(this.className + ' ' + i );
  	})
	});
	
	$(".vp .print .button").click(function () {
	  $("#svacinka-polozky").val(svacinka);
		//alert($("#svacinka-polozky").val());
		return true;
	});
	
	
	$(".il-svacinka li > div").hide();
 	$(".il-svacinka li > a").click(function () {
	  //alert($(this).attr("class") )
	  $(".overlayColor").attr("id",$(this).attr("class")).addClass("il-svacinka");
	  //alert($(this).parent().children("div").html());
		$(".overlayContent-in").html($(this).parent().children("div").html());
		$('.overlayContent-in p').wrap('<div class="il-whitebox" />');
		$('.il-whitebox').prepend('<div class="il-whitebox-top"> </div>');
		$('<div class="il-whitebox-bottom"> </div>').appendTo('.il-whitebox');
		$('<a href="#" class="svacinka-ok">ok<span>&nbsp;</span></a>').appendTo('.overlayContent-in');
		$('<div class="il-ico">&nbsp;</div>').appendTo('.il-whitebox');
		$(".overlayBoxUniversal").addClass("overlayBoxUniversalw395");
		$(".overlayBoxUniversal .closeLink").hide();
    doOverlayOpenUniversal();
    return false;
	});
	
	$(".svacinka-ok").livequery('click', function(event) {
	  doOverlayCloseUniversal();
	  $(".overlayColor").attr("id","").removeClass("il-svacinka");
	  $(".overlayBoxUniversal").removeClass("overlayBoxUniversalw395");
	  $(".overlayBoxUniversal .closeLink").show();
    return false;
	});
	

	$(".poradit textarea").hide();
	$(".poradit a").click(function () {
	  $(".poradit textarea").show();
	  return false;
	});
	$(".poradit textarea").elastic();
	
	$(".rada p.vice").hide();
	$(".rada div.vice a").click(function () {
	  if ( $(this).text()=='více' )
	    $(this).text('méně')
	    else
	      $(this).text('více')
	  
	  $(this).parent().parent().parent().children("p.vice").toggle();
    return false;
	});
	
	//graficka vypomoc
	$.each($(".cnt-blok .whitebox table"), function() {
	  $(this).find("tr").not(":first").not(":last").addClass("white");
	});
	
	$(".nejrada p.vice").hide();
	$(".nejrada div.vice a").click(function () {
	  $(this).parent().parent().children("p.vice").toggle();
    return false;
	});
	
	$(".poradit .nologettoggle").hide();
	
	$(".poradit input.text").focus(function () {
    $(this).parent().parent().parent().find(".nologettoggle").show();
  });
	
	
	if( $(".cnt-dalsi .cnt-left").height() > ( $(".cnt-right .rady > h3").height() + $(".cnt-right .rady .rady-content").height() + $(".cnt-right .rady .rady-bottom").height() + 15) ) //15 padding u  .rady-bottom
	  $(".cnt-right .rady .rady-content").height( $(".cnt-dalsi .cnt-left").height() - $(".cnt-right .rady > h3").height() -  $(".cnt-right .rady .rady-bottom").height() - 15);


    $(".malujeme-content .omalovanky").click(function () {
        $(".overlayColor").attr("id","omalovanky");
        $(".overlayBoxMalujeme").show();
        return false;
    });
    $(".overlayBoxMalujeme a.closeLink").click(function () {
        $(".overlayBoxMalujeme").hide();
        return false;
    });

    $(".malujeme-content .spojovacky").click(function () {
        $(".overlayColor").attr("id","spojovacky");
        $(".overlayBoxSpojovacky").show();
        return false;
    });
    $(".overlayBoxSpojovacky a.closeLink").click(function () {
        $(".overlayBoxSpojovacky").hide();
        return false;
    });

    $(".malujeme-content .bludiste").click(function () {
        $(".overlayColor").attr("id","bludiste");
        $(".overlayBoxBludiste").show();
        return false;
    });
    $(".overlayBoxBludiste a.closeLink").click(function () {
        $(".overlayBoxBludiste").hide();
        return false;
    });

    $(".malujeme-content .vystrihovanky").click(function () {
        $(".overlayColor").attr("id","vystrihovanky");
        $(".overlayBoxVystrihovacky").show();
        return false;
    });
    $(".overlayBoxVystrihovacky a.closeLink").click(function () {
        $(".overlayBoxVystrihovacky").hide();
        return false;
    });

	
    $(".pohadky-toggler,.rikadla-toggler").click(function () {
        $(".pohadky-zalozka,.rikadla-zalozka,.pohadky-toggler,.rikadla-toggler,.text-rikadla,.text-pohadky").toggle();
        return false;
    });
	
	
	$(".line-in input.text,.line-in select,.line-in textarea").focus(function(event) {
		$(this).parents(".line-in").next().children("span").css("display","block");
		return false;
	});
	

/*  Tento kus kodu je "jinak" implementovan primo v sablone formulare
    Tento kus kodu je "jinak" implementovan primo v sablone formulare
 $(".text-pohadky li > a").click(function () {
	  $(".overlayBoxUniversal").addClass("overlayBoxUniversal-pohadky");
	  $(".overlayBoxUniversal .closeLink").hide();
    doOverlayOpenUniversal();
    //return false;
	});
	$(".s-l a").click(function () {  // zavre ilayer u pohadky
    doOverlayCloseUniversal();
    return false;
	});
*/
	
	
	
	$(".ico a.tisknout").click(function () {
    window.print();
    return false;
	});
	
	
	$(".jak-dopadne").next("div").hide();
	$(".jak-dopadne span").click(function () {
    $(this).parents(".jak-dopadne").next().toggle();
    return false;
	});
	
	
	$(".reg-left ul.error").wrap('<div class="error-dupl-out" />').wrap('<div class="error-dupl" />').wrap('<div class="error-dupl-in" />').removeClass("error");


	if($.browser.msie){
      //alert("msie");
      if ( $("#frmcoNasTrapiForm-odeslatRadu").is(":disabled")){
        //alert("dis");
        $("#frmcoNasTrapiForm-odeslatRadu").parent("fieldset").append('<div class="ie-rada">Odeslat radu<span></span></div>');
			}
   }
   
   $(".rikadla-content img[src$='png']").pngfix();
   $(".text img[src$='.png']").pngfix();
   $(".akce img[src$='.png']").pngfix();
   $(".sp-right-img img[src$='png']").pngfix();
   //alert($(".rikadla-content img[src$='png']").length) ;


	$(".galerie a").lightBox({
	imageLoading: 'http://www.brumik.cz/images/lightbox/lightbox-ico-loading.gif',
	imageBtnClose: 'http://www.brumik.cz/images/lightbox/lightbox-btn-close.gif',
	imageBtnPrev: 'http://www.brumik.cz/images/lightbox/lightbox-btn-prev.gif',
	imageBtnNext: 'http://www.brumik.cz/images/lightbox/lightbox-btn-next.gif'
   });
   

  $(".neodhlasovat2 input:checkbox").click(function() {
    RegisterUserForm.validateControl(this);
	});
	
	
	$(".reg-left .check input:checkbox").click(function() {
	  if( $(this).is(":checked") ){
    	//alert('click');
    	doOverlayOpenUniversal();
    	$(".reg-left select").hide();
    	$(".overlayContent-in").html('<div class="newsletterInfo" />');
    	$(".newsletterInfo").append($(".newsletterIlayerText").html());
		}
	});
	var zvyrazneniNewsletter = $(".reg-left .check label").text();
        $(".reg-left .check label").html(zvyrazneniNewsletter.replace("ANO", "<b>ANO</b>") );
        $(".reg-left .check label").html(zvyrazneniNewsletter.replace("ÁNO", "<b>ÁNO</b>") );



  $.each($(".hadanka-right .hadanka-odpoved"), function(i, val) {
		$(this).click(function(){
		  if($(".hadanka-right .odpoved").eq(i).is(":hidden")){ //jestli je odpoved skryta, odkryju a napisu zavrit
		    $(".hadanka-right .odpoved").eq(i).show();
		    $(this).text($(".hadanka-right .zavrit-odpoved").eq(i).text());
			}
				else{
				  $(".hadanka-right .odpoved").eq(i).hide();
		    	$(this).text($(".hadanka-right .otevrit-odpoved").eq(i).text());
				}
		  return false;
		})
	});


});


