var currentIcon = 0;
var previousIcon = 0;
var repeater;

jQuery(document).ready(function() {
  size = jQuery("#slideshow > .slide").length;
  random = Math.floor(Math.random() * size);
  currentIcon = previousIcon = random;
  jQuery("#slide-" + (currentIcon +1)).removeClass("hidden");
  repeater = jQuery.timer(7000, function(timer) { nextSlide(size); });
});

function showSlide(index) {    
  previousIcon = currentIcon;
  currentIcon = index;
  
  if (currentIcon != previousIcon) {
    jQuery("#slide-" + (previousIcon + 1)).fadeOut(1800);
    jQuery("#slide-" + (currentIcon + 1)).fadeIn(1800);
  }
}

function nextSlide(size) {
  var index = 0;
  
  if(currentIcon < size - 1) {
    index = currentIcon + 1;
  } else {
    index = 0;
  }

  showSlide(index);
}



