$(document).ready(function() {
  timer = setTimeout("slideshow()", timerValue);
});

function posun(diff) {
  if (!lock) {
    num = o_id + diff + 1;
    if (num > len) num -= len;
    if (num < 1) num += len;
    clearTimeout(timer);
    setPicture(num);
  }
}

function slideshow() {
  if (sldPlay) {
    
    lock = true;
    $('#fadeshowDescriptionBottom').animate({left: -525},{duration:textSpeed, specialEasing: {width: "circEaseIn"}});
    $('#fadeshowDescriptionTop').animate({left: -525},{duration:textSpeed, specialEasing: {width: "circEaseIn"}, complete: function() {
      $("#o" + (o_id + 1)).fadeOut(500, function () {
        o_id++;
    		var numMark = ((o_id % len) + 1) + '';
    		var prev = o_id % len;
    		if (prev <= 0) prev = len;
    		prev += '';
  
    		//document.getElementById(numMark).src = 'image/tlacitko_' + numMark + '_aktivni.png';
     		//document.getElementById(prev).src = 'image/tlacitko_' + prev + '.png';
     		$('#' + numMark).html('<strong>' + numMark + '</strong>');
     		$('#' + prev).html(prev);
     		$("#fadeshowDescriptionTop").html(popisky[(o_id >= len)? 0 : o_id][0]);
     		$("#fadeshowDescriptionBottom").html(popisky[(o_id >= len)? 0 : o_id][1]);
        $('#fadeshowDescriptionTop').animate({left: 32},{duration:textSpeed, specialEasing: {width: "circEaseOut"}, complete: function () {
          $('#fadeshowDescriptionBottom').animate({left: 32},{duration:textSpeed, specialEasing: {width: "circEaseOut"}, complete: function() {
            lock = false;
           }
          });
         }
        });

        if (o_id == len) {
          for (i = 1; i <= len; i++) {
            $("#o" + i).show();
          }
          o_id = 0;
        }
      });
     }
    });
  }

  timer = setTimeout("slideshow()", timerValue);
}

function setPicture(imgNum) {
  if (lock) return;
  var prev = (o_id + 1) % len;
  if (prev <= 0) prev = len;
  //document.getElementById(prev).src = 'image/tlacitko_' + prev + '.png';
  $('#' + prev).html(prev);

  o_id = imgNum - 1;
  clearTimeout(timer);
  lock = true;

  $('#fadeshowDescriptionBottom').animate({left: -525},{duration:textSpeed, specialEasing: {width: "circEaseIn"}}); 
  $('#fadeshowDescriptionTop').animate({left: -525},{duration:textSpeed, specialEasing: {width: "circEaseIn"}, complete: function() {
    for (i = 1; i < imgNum; i++) {
      $("#o" + i).fadeOut();
    }
    for (i = imgNum; i <= len; i++) {
      $("#o" + i).show();
    }
  
  	var numMark = ((o_id % len) + 1) + '';
  	//document.getElementById(numMark).src = 'image/tlacitko_' + numMark + '_aktivni.png';
  	$('#' + numMark).html('<strong>' + numMark + '</strong>');
    $("#fadeshowDescriptionTop").html(popisky[(o_id >= len)? 0 : o_id][0]);
    $("#fadeshowDescriptionBottom").html(popisky[(o_id >= len)? 0 : o_id][1]);

    $('#fadeshowDescriptionTop').animate({left: 32},{duration:textSpeed, specialEasing: {width: "circEaseOut"}, complete: function() {  
      $('#fadeshowDescriptionBottom').animate({left: 32},{duration:textSpeed, specialEasing: {width: "circEaseOut"}, complete: function() {
        lock = false;
       }
      });
     }
    });
    timer = setTimeout("slideshow()", timerValue);
   }
  });
}

function showElement(elm) {
  //if (jQuery('#show').css('display') != 'none' && picRow == lastRow - 1)
    //jQuery(elm).css('position', 'absolute');

  //jQuery('.tArt').slideUp("slow");
    jQuery(elm).slideDown(500, function() {
      lockScroll = false;
    });
    lastImage = elm;
}


function hideElement(elm) {
  jQuery(elm).slideUp(500, function() {
      lockScroll = false;
    });
}

