$(document).ready(function() {

  // external links
/*
  $(function() {
    $("a:not([href*='ms-haus.cz'])").click(function(){
      window.open(this.href);
      return false;
    }).attr("title", this.title + " [externí odkaz]");
  });
*/

  // illustration
	$('#illustration ul').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence'
	});

  // slideshow
	$('#slider-stage').carousel('#slideshow-previous', '#slideshow-next');

  // automatic slideshow
  var intervalId;
  function automaticSlideshow() {
    intervalId = window.setInterval(simulatedClick, 5000);
  }
  function simulatedClick() {
    $('#slideshow-next').click();
  }
  automaticSlideshow();
  $('#slider-stage, #slideshow-previous, #slideshow-next').bind('mouseenter', function(){
    window.clearInterval(intervalId);
  }).bind('mouseleave', function(){
    automaticSlideshow();
  });

  // button swap
  function buttonSwap(elm,state)
  {
  	switch (state) {
  		case 'over': $('#' + elm).attr('src', './_layout/_www/' + elm + '-' + state + '.png'); break;
  		case 'out': $('#' + elm).attr('src', './_layout/_www/' + elm + '.png'); break;
  	}
  }
  $('#search-button').mouseover(function(){
    buttonSwap('search-button', 'over');
  }).mouseout(function(){
    buttonSwap('search-button', 'out');
  });

  // search form
  $('#search').submit(function(){
    if ($('#search-text').val() == '') {
      alert('Zadejte prosím hledaný výraz');
      return false;
    }
    if ($('#search-text').val().length < 4) {
      alert('Hledaný výraz musí obsahovat alespoň tři znaky');
      return false
    }
  });

  // lightbox
  $(function() {
    $('a[rel*=lightbox]').lightBox({
     fixedNavigation:true,
	   containerResizeSpeed: 350,
	   txtImage: 'Obrázek',
	   txtOf: 'z'
   });
  });

});

