/**
 * utf8 (ěščřžýáíéúů)
 * animace banneru na titulni strance 
 */
var anim_stopped = false;
var tts = 2; // time to switch - cas do premeny obrazku
var counter = tts;
var countdown = function() {
  if(counter > 0) {
    counter--;
  } else {
    if(!anim_stopped) {
      show_next();
      counter = tts;
    }
  }
}
var show_next = function() {
  var actual = $('.banner .image-nav a.active').removeClass('active');
  var next = actual.next();
  if(!next.length) {
    next = $('.banner .image-nav a:first');
  }
  if(!next.length) return;
  next.addClass('active');
  $('.banner .images img').eq(actual.attr('poradi')).fadeOut();
  $('.banner .images img').eq(next.attr('poradi')).fadeIn();
}
var show_prev = function() {
  var actual = $('.banner .image-nav a.active').removeClass('active');
  var prev = actual.prev();
  if(!prev.length) {
    prev = $('.banner .image-nav a:last');
  }
  if(!prev.length) return;
  prev.addClass('active');
  $('.banner .images img').eq(actual.attr('poradi')).fadeOut();
  $('.banner .images img').eq(prev.attr('poradi')).fadeIn();
}
$(document).ready(function() {
  $('.titulka #col h3').click(function() {
    $('.titulka #col ul').toggle();
  });
  $('.banner .images img').hide().filter(':first').show();
  var i = 0;
  $('.banner .image-nav a').click(function() {
    return false;
  }).each(function() {
    this.poradi = i;
    i++;
  }).filter(':first').addClass('active');
  $('.banner .image-nav a').mouseenter(function() {
      anim_stopped = true;
      if($('.banner .images img').eq(this.poradi).filter(':visible').length) return;
      $('.banner .images img:visible').fadeOut();
      $('.banner .images img').eq(this.poradi).fadeIn();
      $('.banner .image-nav a').removeClass('active').filter(this).addClass('active');
  }).mouseleave(function() {
      anim_stopped = false;
      counter = tts;
  });
  $('.banner .images img').mouseenter(function() {
      anim_stopped = true;
  }).mouseleave(function() {
      anim_stopped = false;
      counter = tts;
  });
  if($('.titulka').length) setInterval(countdown, 1000);
});

