//On page load start this function.

$(document).ready(function() {
	
	$(".paging").css('visibility','visible');
	$(".paging").show();
	$(".paging a:first").addClass("active");
	var imageWidth = 219;
	var imageSum = 657;
	var imageReelWidth = imageWidth * imageSum;
	$("#slideshow").css({'width' : imageReelWidth});
	rotate = function(){
		var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * imageWidth;
		$(".paging a").removeClass('active');
		$active.addClass('active');
		$("#slideshow").animate({ 
			left: -image_reelPosition
		}, 500 );
	};
	rotateSwitch = function(){		
		play = setInterval(function(){			
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first				
			}
			rotate(); //Trigger the paging and slider function
		}, 4000); //Timer speed in milliseconds (3 seconds)
	};
	rotateSwitch(); //Run function on launch
	$("#slideshow").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	$(".paging a").click(function() {	
		$active = $(this);
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});
	
});
