$(document).ready(function(){

  if (jQuery.browser.safari && document.readyState != "complete"){
    setTimeout( arguments.callee, 100 );
    return;
  }
  
  var MySlideDeck = window.deck;

  MySlideDeck = $('.slidedeck').css({
    width:'907px',
    height:'249px'
  }).slidedeck({
    speed: 750,
    scroll: false,
    start: 1
  });
  
    // Select all the activeCorner elements, then iterate through them and add ids.
  $('.slidedeck div.activeCorner').each(function(i){
    $(this).attr('id','corner_' + (i+1));
  });
  
  // initialize an autoplay switch
  var autoPlay = true;
 
  function myLoop(){
    // only advance slides when the mouse is over.
    if(autoPlay){
      // Check to see if the current slide is the last slide
      if(MySlideDeck.current == MySlideDeck.slides.length){
      // This is the last slide, go to the first slide
      MySlideDeck.goTo(1);
      } else {
      // This is not the last slide, go to the next slide
      MySlideDeck.next();
      }
    }
  }
 
  setInterval(myLoop,10000); // Run the myLoop() function every 2 seconds (2000 miliseconds)

  // set autoplay to on when the mouse enters
  $('.slidedeck').mouseenter(function(){
    autoPlay = true;
  });
  // set autoplay to off when the mouse leaves
  $('.slidedeck').mouseleave(function(){
    autoPlay = true;
  });
  // set autoplay to off when the mouse clicks
  $('.slidedeck').click(function(){
    autoPlay = false;
  });

});
