$(document).ready(function() {

	$(".paging").show();
	$(".paging a:first").addClass("active");
	var imageWidth = 800;
	var imageSum = $(".slideContent img").size();
	var imageReelWidth = imageWidth * imageSum;

	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider 
	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
		}, 300 );
		
	}; 
	

	rotateSwitch = function(){		
		play = setInterval(function(){ 
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { 
			$('.slide').fadeOut('slow');
							var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < 500);
$('.slideDesc').hide('fast');
				$active = $('.paging a:first'); 


do { curDate = new Date(); }
while(curDate-date < 200);
				$('.slide').delay(400).fadeIn('fast');
			}
			rotate(); 
		}, 3000); 
	};
	
	rotateSwitch(); 	
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	$(".slide").each(function () {
			$(this).hover(function(){
			$(this).children('.slideDesc').show('fast');	
			});	
	});

	
	//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
	});	
	
});
