var retfulltext=0;
var actnews=0;
var slidespeed=4000;
$(document).ready(function(){

    /*$('#esetbanner').fadeIn('slow').bind('mouseenter',function(){
      $(this).animate({opacity:1},'fast');
    }).bind('mouseleave',function(){
      $(this).animate({opacity:0.25},'fast');
    });
    setTimeout("$('#esetbanner').animate({opacity: 0.25},'slow')",5000);*/

    $('#hotlineform').submit(function(){
      if($("#kontaktni_osoba").attr("value") && $("#telefon").attr("value") && $("#telefon").attr("value") && $("#email").attr("value") && $("#dotaz").attr("value")){
        return true;
      } else {
        alert("Je potřeba vyplnit všechna povinná pole");
        return false;
      }
    });
    if ($('#rightbannerin').text()==""){
      $('#rightbanner').hide();
    }
    $('#menu li').bind('mouseleave',function(){
      $(this).children('ul').hide();
    }).bind('mouseenter',function(){
      $(this).children('ul').show();
    });
    retfulltext=$('input[name=cntnt01returnid]:first').attr('value');
    $('#srch .search-input').attr('autocomplete','off').keyup(function(){
      if ($(this).attr('value').length>=3){
        $('input[name=cntnt01returnid]:first').attr('value','45');
        $.post($('#srchres').attr('rel'),$("#srch form").serialize(),function(data){
          $('#srchres').html(data);
        });
        $('input[name=cntnt01returnid]:first').attr('value',retfulltext);
      } else {
        $('#srchres').html('');
      }
    });
    if ($('h1 a:first').css('line-height')!='200px'){
      $('h1 a:first').text(' ');
    }
    $('#introcover .submenu').find('h3:first').css('border','none').css('margin-top','-2px');
    $('#introcover .submenu').find('h3:not(:first)').css('padding-top','5px');
    $('#introcover .submenu').closest('li').css('width','285px');
    $('#introcover .submenu').find('.submenu:last').append('<div style="font-size: 1px; height: 1px; clear: both;">&nbsp;</div>');
    $('#introcover>ul>li').map(function(){
      presah=$(this).position().top-5+$(this).find('.submenu:first').height()-400;
      if (presah>0){
        $(this).find('.submenu:first').css('top',(-presah-20)+'px');
      }
      //alert($(this).position().top);
    });
    $('img').closest('a[href$=jpg]').attr('rel','gallery').lightbox();
    $('.qrkod').lightbox();
    
    if ($('#topmenu').width() == '830'){
      var topsirka = 0;
      $('#topmenu li').map(function(){
        topsirka+=$(this).width();
      });
      if (topsirka > 820){
        $('#topmenu').width(topsirka);
        $('#topmenucover').mousemove(function(e){
          prvnibutton=$('#topmenu li:first').width()/2;
          poslednibutton=$('#topmenu li:last').width()/2;
          framesirka=Math.round(820-prvnibutton-poslednibutton);
          pozice=Math.round(Math.min(e.pageX-this.parentNode.offsetLeft+prvnibutton,820-poslednibutton+$("#topmenu li").size()));
          finpos=Math.min(0,Math.round((820-topsirka)*(pozice/framesirka)+(prvnibutton/2)));
          $('#topmenu').css('left',finpos+'px');
        });
      }
    }
    
    $('#newsintro li:not(:first)').hide();
    setTimeout('slide()',slidespeed);

});

function slide(){
  pocet = $('#newsintro li').size();
  $('#newsintro li').fadeOut('slow');
  actnews = (actnews+1)%pocet;
  $('#newsintro li:eq('+actnews+')').fadeIn('slow');
  setTimeout('slide()',slidespeed);
}
