$(document).ready(function() {
	$(".paging").show();
	$(".paging a:first").addClass("active");
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	$(".image_reel").css({'width' : imageReelWidth});
	rotate = function(){	
	var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;
		$(".paging a").removeClass('active');
		$active.addClass('active'); 
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 1000 );
	}; 
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ 
	$active = $('.paging a.active').next();
			if ( $active.length === 0) { 
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); 
		}, 6000); //milliseconds
	};
	rotateSwitch(); //Run function on launch
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
});
