
$(document).ready(init);
onload = initOnLoad;

function init()
{
  $('#header-menu a img').each(function()
  {
    this.srcOrig = this.src;
    this.srcOver = this.src.replace('/menu/', '/menu-over/');
    var img = new Image();
    img.src = this.srcOver; 
  }).mouseover(function()
  {
    this.src = this.srcOver;
  }).mouseout(function()
  {
    this.src = this.srcOrig;
  });
  $('#banner-menu a img').each(function()
  {
    this.srcOrig = this.src;
    this.srcOver = this.src.replace('/banner-menu/', '/banner-menu-over/');
    var img = new Image();
    img.src = this.srcOver; 
  }).mouseover(function()
  {
    this.src = this.srcOver;
  }).mouseout(function()
  {
    this.src = this.srcOrig;
  });  
  
  $('input[hint]').each(function()
  {
    var hint = $(this).attr('hint');
    var val = $(this).val();
    if ( hint.length && !val.length )
    {
      $(this).val(hint);
      $(this).focus(function()
      {
        $(this).val('');
      });
      $(this).blur(function()
      {
        if ( !this.value.length )
        {
          this.value = $(this).attr('hint');
        }
      });
    }
  });
  
  
  $('.over').each(function()
  {
    this.srcOrig = this.src;
    this.srcOver = this.src.replace(/\.([^.]*)$/,'-over.$1');
    var img = new Image();
    img.src = this.srcOver; 
  }).mouseover(function()
  {
    this.src = this.srcOver;
  }).mouseout(function()
  {
    this.src = this.srcOrig;
  });
  
  $('#popup').hide();
  
  $('a[rel=lightbox]').lightbox();
  
  homeLokale();
  
  $('.news-title').click(function()
  {
    newsToggle(this);
  });
  $('.news-content').not('.news-a').hide();
}

function newsToggle(newsTitle)
{
  $(newsTitle).next().toggle();
}

function initOnLoad()
{
  $('#popup').slideDown(1000);
}

var homeLokaleCount = 0;
var homeLokaleCurrent = -1;

function homeLokale()
{
  $('.home-box2-lokale a').hide();
  homeLokaleCount = $('.home-box2-lokale a').size(); 
  if ( homeLokaleCount )
  {
    homeLokaleNastepny();
  }
}

function homeLokaleNastepny()
{
  $('.home-box2-lokale a:eq(' + homeLokaleCurrent + ')').fadeOut();
  homeLokaleCurrent++;
  if ( homeLokaleCurrent >=  homeLokaleCount )
  {
    homeLokaleCurrent = 0;
  }
  $('.home-box2-lokale a:eq(' + homeLokaleCurrent + ')').fadeIn();
  setTimeout(homeLokaleNastepny, 3000);
}


function popupClose()
{
  $('#popup').hide();
  document.cookie = 'hidepopup';
}

