$(document).ready(function() {

  // lightbox
  $(function() {
    $('a[rel*=lightbox]').lightBox({
     fixedNavigation:true,
     containerResizeSpeed: 350,
     txtImage: 'Obrázek',
     txtOf: 'z'
   });
  });

  // external links
  $(function() {
    $("a:not([href*='karavan-forum.cz'])").click(function(){
      window.open(this.href);
      return false;
    }).attr("title", this.title + " [externí odkaz]");
  });

  // inits slideshow
  $('div.slider-stage').each(function(index){

    ++index;

    $('div#slider-stage-' + index).carousel('a#slideshow-previous-' + index, 'a#slideshow-next-' + index);

    var intervalId;
    function automaticSlideshow() {
      intervalId = window.setInterval(simulatedClick, 4000);
    }

    function simulatedClick() {
      $('a#slideshow-next-' + index).click();
    }

    automaticSlideshow();
    $('div#slider-stage-' + index + ' a.theme, a#slideshow-previous-' + index + ', a#slideshow-next-' + index).bind('mouseenter', function(){
      window.clearInterval(intervalId);
    }).bind('mouseleave', function(){
      automaticSlideshow();
    });

  });

  $('a.slideshow-previous').bind('click', function() { return false; });
  $('a.slideshow-next').bind('click', function() { return false; });

});

