$(function(){

var $imageDivs = $("#intro").css("position","relative").children(".carousel").css({"position":"absolute","top":"0px","left":"0px"});

repeat($imageDivs);

$("#intro").hover(function(){
   clearTimeout(window.timerId);
},function(){
   repeat($imageDivs);
})

});

window.current = 0;
window.currentZIndex = 1;
window.timerId = null;

function getNext($imageDivs) {
   if(window.current+1 == $imageDivs.length) {
      window.current = 0;
      return window.current;
   }
   return ++window.current;
}

function showNext($imageDivs) {
   var current = window.current;
   $($imageDivs.get(getNext($imageDivs))).css("zIndex",++window.currentZIndex).fadeIn(1000, function(){
      $($imageDivs.get(current)).hide();
   });
}

function repeat($imageDivs) {
   window.timerId = setTimeout(function(){
      if(!window.pauseTimer) {
         showNext($imageDivs);
         repeat($imageDivs);
      }
   },3000);
}

