// http://designm.ag/tutorials/image-rotator-css-jquery
var q=jQuery.noConflict();


q(function(){   
	

	
	q(".main_image .desc").show(); //Show Banner
	q(".main_image .block").animate({ opacity: 0.85, marginBottom: 0 }, 1 ); //Set Opacity
	q(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)

	q(".image_thumb ul li").click(function(){
		$active = q(this);
		slideSwitchClick();
		}).hover(function(){ //Hover effects on list-item
				q(this).addClass('hover'); //Add class “hover” on hover
			}, function() {
				q(this).removeClass('hover'); //Remove class “hover” on hover out
	});
	
	//runs function, set timer here
	q(function() {
		setInterval( 'slideSwitchTimed()', 10000 );
	});
	
	// Toggle the Hide/Show Option
	q("a.collapse").click(function(){
		q(".main_banner .block").slideToggle(); //Toggle the description (slide up and down)
		q("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
	});

	
	q('.main_image').click(function(){
		var url = q(this).find('.desc .block span').html();
		if (url) {
			window.location.href = url;
		}
	});
});

function slideSwitchTimed() {
	$active = q('.image_thumb ul li.active').next();
	if ( $active.length == 0 ) $active = q('.image_thumb ul li:first'); //goes back to start when finishes
	slideSwitch();
}

function slideSwitchClick() {
	slideSwitch();
}
function slideSwitch() {
	var $prev = q('.image_thumb ul li.active');
	
	//Show active list-item
	$prev.removeClass('active');
	$active.addClass('active');

	//Set Variables
	var imgAlt = $active.find('img').attr('alt'); //Get Alt Tag of Image
	var imgTitle = $active.find('a').attr('href'); //Get Main Image URL
	var imgDesc = $active.find('.block').html(); //Get HTML of the “block” container
	var imgDescHeight = q('.main_image').find('.block').height(); //Find the height of the “block”
	
	if (q(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
		q(".main_image img").animate({ opacity: 0}, 250 );
		q(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
			q(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
			q(".main_image img").attr({ src: imgTitle , alt: imgAlt}).animate({ opacity: 1}, 250 ); //Switch the main image (URL + alt tag)
		});
	}
	return false;
}
	

