
  var aktobr=0;
  var speed=6000;
  var timer=false;
  
  $(document).ready(function(){

    nums="";
    $('#gal4 img:not(:first)').hide();
    pocet=$('#gal4 img').size();
    if (pocet>1){
      for (i=0;i<pocet;i++){
        nums+="<li><a href=\"javascript:;\" onclick=\"showimage("+i+",true);\">"+(i+1)+"</a></li>";
      }
      $('#gal4 ul').prepend(nums);
      showimage(0);
      setTimeout("playslideshow()",speed);
    }
    
    
    $('.popupimage').lightbox();
  });
  
  function showimage(idx,pause){
    pause=(pause)?pause:false;
    if (pause){
      if (timer){      
        clearTimeout(timer);
        $('.play').text('Play');
        timer=false;
      }
    }
    $('#gal4 ul li a:not([class=play])').attr('class','noactive');
    $('#gal4 ul li a:eq('+idx+')').attr('class','active');
    if (idx!=aktobr){
      $('#gal4 img').fadeOut('slow');
      $('#gal4 img:eq('+idx+')').fadeIn('slow');
      aktobr=idx;
    }
  }
  
  function playpause(){
    if (timer){      
      clearTimeout(timer);
      $('.play').text('Play');
      timer=false;
    } else {
      playslideshow();
      $('.play').text('Pause');
    }
  }
  
  function playslideshow(){
    $('.play').text('Pause');
    pocet=$('#gal4 img').size();
    nidx=(aktobr+1)%pocet;
    showimage(nidx);
    timer=setTimeout('playslideshow()',speed);
  }
