$(document).ready(function(){
//function initShowcase(){
//pageTracker._trackPageview($(".image_reel div:first").attr("rel") + "/_show");

$("#showcase .paging").show();
$("#showcase .paging a:first").addClass("active");

var imageWidth = $("#showcase .window").width();
var imageSum = $("#showcase .image_reel div").size();
var imageReelWidth = imageWidth * imageSum + 100;



$("#showcase .image_reel").css({'width':imageReelWidth});
var image_reelPosition;

rotate = function(){
  var triggerID = $active.attr("rel") - 1;
  var prevTriggerID = triggerID - 1;
  if (prevTriggerID < 0) {
    prevTriggerID = imageSum - 1;
  }
  image_reelPosition = triggerID * imageWidth;
  $("#showcase .paging a").removeClass('active');
  $active.addClass('active');
  $("#showcase .image_reel").fadeOut(200, function(){
    $("#showcase .image_reel").animate({left:-image_reelPosition});
    $("#showcase .image_reel").fadeIn(200);
  });
  //pageTracker._trackPageview($(".image_reel div:eq("+triggerID+")").attr("rel") + "/_show");
  return false;
};

var play;
rotateSwitch = function(){
  play = setInterval(function(){
    $active = $('#showcase .paging a.active').next();
    if ( $active.length === 0) {
      $active = $('#showcase .paging a:first');
    }
    rotate();
  }, 5000);
};
rotateSwitch();

//On Hover
$("#showcase .image_reel a").hover(function(){clearInterval(play);},function(){rotateSwitch();});

//On Click
$("#showcase .paging a").click(function(){
  $active = $(this);
  clearInterval(play);
  rotate();
  rotateSwitch();
  return false; //Prevent browser jump to link anchor
});

//$(".image_reel div").click(function(){
//  pageTracker._trackPageview($(this).attr('rel')+'/_click');
//});
});

//window.onload = initShowcase;

