jQuery(function(){

	$('.main div').show();
	$('.main div').animate({ opacity: 1 }, 1 );
	$('#slider ul li:first').addClass('active');

	$('#slider ul li').click(function () {
		$active = $(this);
		slideSwitchClick();
	}).hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

// no pause code	
/*	$(function() {
		setInterval( 'slideSwitchTimed()', 7500 );
	});
*/

// pause on hover code
	playSlideshow = setInterval("slideSwitchTimed()", 7500 );
	$('#slider li').hover(function() {
		clearInterval(playSlideshow);
	}, function() {
		playSlideshow = setInterval("slideSwitchTimed()", 7500 );
	});
});

function slideSwitchTimed() {
	$active = $('#slider ul li.active').next();
	if ( $active.length == 0 ) $active = $('#slider ul li:first'); //goes back to start when finishes
	slideSwitch();
}

function slideSwitchClick() {
	slideSwitch();
}

function slideSwitch() {
	var $prev = $('#slider ul li.active');
	
	$prev.removeClass('active');
	$active.addClass('active');
	
	//Set Variables
	var imgAlt = $active.find('img').attr('alt');
	var imgTitle = $active.find('img').attr('rel');
	var imgDesc = $active.find('div').html();
	var imgDescHeight = $('.main').find('div').height();
	var aHref = $active.find('div a').attr('href');
	
	if ($(this).is('.active')) {
		return false; // Prevents repetitive animations on active/selected list-item
	} else {
		$('.main img').animate({ opacity: 0}, 250 );
		$('.main div').animate({ opacity: 0, marginBottom: -imgDescHeight }, 500 , function() {
			$('.main div').html(imgDesc).animate({ opacity: 0.85, marginBottom: '0' }, 500 );
			$('.main a').attr({href:aHref});
			$('.main img').attr({ src: imgTitle , alt: imgAlt}).animate({ opacity: 1}, 500 );
		});
	}
	return false;

}
