/*
* Quick jQuery Slideshow

* For link add url to rel attribute of slideshow image
*/

var homeTimer;

jQuery.noConflict();

jQuery(document).ready(function() {		
	jQuery('#home_slideshow img').css({opacity: 0.0});
	slideShow();
	jQuery('#home_pager a').click(function(){
		slideClick(jQuery(this));
	});
	jQuery('.pager_target').click(function(){
		var whr = jQuery(this).attr('url');
		window.location = jQuery(this).attr("url");
    	return false;
	});
	
});

function slideShow() {

	//Get the first image
	jQuery('#home_slideshow img:first').css({opacity: 1.0});
	jQuery('#home_pager a:first').addClass('pager_selected');
	
	//set link
	var link = jQuery('#home_slideshow img:first').attr('rel');
	jQuery('#home_slideshow div.pager_target').attr('url', link);
	
	homeTimer = setInterval('gallery()',16000);
	
}

function slideClick(obj){	
	clearInterval(homeTimer);
	gallery(obj);
	homeTimer = setInterval('gallery()',16000);
}

function gallery(obj) {	
	//if no show class, grab the first img
	var current = (jQuery('#home_slideshow img.show')?  jQuery('#home_slideshow img.show') : jQuery('#home_slideshow img:first'));

	//get img object
	if(obj == undefined){
		var next = ((current.next().length) ? ((current.next().hasClass('caption'))? jQuery('#home_slideshow img:first') :current.next()) : jQuery('#home_slideshow img:first'));	
	}
	if(obj != undefined){
		var id = '#' + obj.attr('id');
		var next = jQuery('#home_images').find(id);
	}
		
	//next image fade in effect
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
			
	//deal with pager
	var pagerCount = next.attr('id');
	jQuery('#home_pager a').removeClass('pager_selected');
	jQuery('#home_pager a#' + pagerCount).addClass('pager_selected');

	//set link
	var link = next.attr('rel');
	jQuery('#home_slideshow div.pager_target').attr('url', link);
	
}


