$(document).ready(function() {
  // ========================= antispam ochrana ================================
    $(".no_sp").closest('div').hide();
    $("input.no_sp").val("no" + "spam");
  
  // ================================= cufon ===================================
  Cufon.replace(".slogan");
  Cufon.replace(".stats");
  Cufon.replace(".child h2");
  Cufon.replace(".read-more a", {textShadow: "0px 0px #0f9dc7"});
  Cufon.replace(".back-to-homepage a", {textShadow: "0px 0px #0f9dc7"});
  Cufon.replace(".supportWrapper .text", {textShadow: "0px 0px #000"});
  Cufon.replace(".supportWrapper .percent", {textShadow: "0px 0px #000"});
  Cufon.replace(".mainMenu li a", {hover: true, textShadow: "0px 0px #fff"});
  Cufon.replace(".childrenSliderSmall .name");
  Cufon.replace(".wishTabs li", { color: "#fff", textShadow: "0px 0px #fff"});
  Cufon.replace(".wishTabs .current a", { color: "#0584a9", textShadow: "0px 0px #0584a9"});
  Cufon.replace(".news h2", {textShadow: "0px 0px #fff"});
  Cufon.replace(".more", {textShadow: "0px 0px #377204"});
  Cufon.replace(".article h2", {textShadow: "0px 0px #d6007f"});
  Cufon.replace("#dms h2", {textShadow: "0px 0px #aa0064"});


  // ===================== rozbalovani hlavniho menu ===========================
  $('.hasSubmenu ul').hide();
  //$('.hasSubmenu-selected ul').show();
  /*$('.hasSubmenu a.button').click(function(event){
    event.preventDefault();
    $(this).blur();
    $('.hasSubmenu ul').not($(this).next()).slideUp('slow');
    $(this).next().slideToggle('slow');
  });*/


  // ============================= velky slider ================================
  $(".childrenSliderBig").scrollable({
    next: ".nextBig",
    prev: ".prevBig",

    // po kliknutí na sipku sbali pribeh, prizpusobi vysku slideru a sirku maleho slideru
    onBeforeSeek: function(){
      $(".re-collapse a").trigger('click');
      $('.childrenSliderBig').stop().animate({
        height: $(".childrenWrapperBig").height()
      }, 500, function(){
        adjustSmallSlider();
      });
      $('.additional_info').hide();
    },
    circular: true
  }).autoscroll({
    interval: 10000
  });

  // rozbalovani pribehu
  /*$(".wishText").expander({

    // po rozbaleni prizpusobi vysku slideru a sirku maleho slideru
    afterExpand: function() {
      $('.childrenSliderBig').stop().animate({
        height: $(".childrenWrapperBig").height() + 60
      }, 500, function(){
        adjustSmallSlider();
      });
      $('.dashed-flexible').css('margin', '10px 0 10px 0');
    },
    // po sbaleni prizpusobi vysku slideru
    onCollapse: function() {
      $('.childrenSliderBig').stop().animate({
        height: $(".childrenWrapperBig").height()
      }, 500);
      $('.dashed-flexible').css('margin', '0 0 10px 300px');
      $(this).closest(".childText").find('.additional_info').hide();
    },
    slicePoint: 400,
    widow: 2,
    expandText: 'Celý příběh &gt;',
    expandEffect: 'show',
    expandSpeed: 0,
    userCollapseText: ''
  });
*/
  // pocatecni nastaveni vysky slideru
  $(".childrenSliderBig").height($(".childrenWrapperBig").height());


  // ============================== maly slider ================================
  $(".childrenSliderSmall").scrollable({
    next: ".nextSmall",
    prev: ".prevSmall",
    circular: true
  }).scrollableAddClones();

  // prispusobeni maleho slideru po nacteni stranky
  $(window).load( function() {
    adjustSmallSlider();
  });

  // funkce pro prizpusobeni sirky maleho slideru
  function adjustSmallSlider(){
    if ($('.contentWrapper').height() - $('.rightCol').height() > 0 ) {
      $('.childrenSliderSmall').animate({
        width: 845
      }, 500);
      $('.bottomRightCorner').animate({
        width: 29
      }, 500);
      $('.sliderSmallNav').animate({
        width: 815
      }, 500);
      $('.nextSmall').animate({
        left: 921
      }, 500)
      $('.childrenSliderSmall .box').animate({
        marginLeft: -7
      }, 500);

      $('.rightCol').css('margin-bottom','0px');

    } else {
      $('.childrenSliderSmall').animate({
        width: 545
      }, 500);
      $('.bottomRightCorner').animate({
        width: 329
      }, 500);
      $('.sliderSmallNav').animate({
        width: 515
      }, 500);
      $('.nextSmall').animate({
        left: 620
      }, 500)
      $('.childrenSliderSmall .box').animate({
        marginLeft: -10
      }, 500);
      $('.childrenSliderSmall').animate({
        marginLeft: -10
      }, 500);

      $('.rightCol').css('margin-bottom','-100px');

    }
  }


  // ====================== taby s pranimi (modry box) =========================
  $(".wishTabs").tabs(".wishPane", {
    tabs: 'li'
  });
  $('.wishTabs li').click(function() {
    Cufon.refresh();
  });


  // ===================== nastaveni sirky hor podle okna ======================
  $('.hillsFront, .hillsBack').width($(window).width());
  $(window).resize(function() {
    $('.hillsFront, .hillsBack').width($(window).width());
  });

  // ===================== bubliny s napovedou v zadosti o prani ===============
   $('label').tipsy({gravity: 'sw',opacity:1});
   $('input').each(function(){
       var label = $(this).closest('div').find('label');
       if(label.length>0){
           $(this).focus(function(){
               label.tipsy('show');
           });
           $(this).blur(function(){
               label.tipsy('hide');
           });
       }
   });
   $('textarea').each(function(){
       var label = $(this).closest('div').find('label');
       if(label.length>0){
           $(this).focus(function(){
               label.tipsy('show');
           });
           $(this).blur(function(){
               label.tipsy('hide');
           });
       }
   });
   $('select').each(function(){
       var label = $(this).closest('div').find('label');
       if(label.length>0){
           $(this).focus(function(){
               label.tipsy('show');
           });
           $(this).blur(function(){
               label.tipsy('hide');
           });
       }
   });
   // ================= bubliny s napovedou pro hotovku a cekarnu ==============
   $('.wishTabs a').tipsy({gravity:'sw',opacity:1});
   
   //carousel pro zmenu loga
   $("#mycarousel ul").cycle({
    fx: 'fade',
    speed: 30,
    timeout: 8000,
    random: 1
    });
    $(".read-more a").click(function(){
        $(this).closest(".childText").find('.additional_info').show();
    });    
    //dms fancybox
    $("a#dms_link").fancybox({
        'hideOnContentClick': true
    });
    if(readCookie('dms') == null){
        createCookie('dms',1);
        $("a#dms_link").trigger('click');
    }
});
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split('; ');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
