$(document).ready(function() {	
						   
	 var clicked = true;
	 
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
	
	$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
	$(".image_thumb ul li").click(function(){
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
		var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"
	
		if ($(this).is(".active")) {  //If the list item is active/selected, then...
			return false; // Don't click through - Prevents repetitive animations on active/selected list-item
		} else { //If not active then...
			//Animate the Description
			$(".main_image img").animate({ opacity: 0}, 250 );
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { 
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); 
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt}).animate({opacity:1}, 250); 
			});
		}
		//Show active list-item
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
		$(this).addClass('active');  //Add class of 'active' on the selected list
		clicked = false;
		return false;
	
	}) .hover(function(){ //Hover effects on list-item
		$(this).addClass('hover'); //Add class "hover" on hover
		}, function() {
		$(this).removeClass('hover'); //Remove class "hover" on hover out
	});
	
	//Paging + Slider Function
	if(clicked) {
	rotate = function(){	
		var triggerID = $active.children().attr("rel") - 1; //Get number of times to slide
		//Determines the distance the image reel needs to slide var image_reelPosition = triggerID * imageWidth; 
		$activeContent = $active.find('.block').html();
		var imgTitle = $active.find('a').attr('href');
		var imgAlt = $active.find('img').attr('alt');

		jQuery("#zoom li").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		jQuery(".main_image img").animate({opacity: 0}, 250)
		jQuery(".main_image .block").animate({ opacity: 0 }, 250 , function() {
				jQuery('.main_image .block').html($activeContent).animate({ opacity: 0.85 }, 250 );
				jQuery(".main_image img").attr({ src: imgTitle , alt: imgAlt}).animate({opacity:1},250);
		});		
	}; }
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = jQuery('#zoom li.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = jQuery('#zoom li:first'); //go back to first
			}
			if(clicked) {rotate();} //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch

});
