$(document).ready(function() {			
	//Execute the hpslideShow
	hpslideShow();
});
function hpslideShow() {
	//Set the opacity of all images to 0
	$('#hpgallery a').css({opacity: 0.0});	
	//Get the first image and display it (set it to full opacity)
	$('#hpgallery a:first').css({opacity: 1.0});		
	//Call the hpgallery function to run the hpslideShow, 6000 = change to next image after 6 seconds
	setInterval('hpgallery()',6000);	
}
function hpgallery() {	
	//if no IMGs have the show class, grab the first image
	var current = ($('#hpgallery a.show')?  $('#hpgallery a.show') : $('#hpgallery a:first'));
	//Get next image, if it reached the end of the hpslideShow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#hpgallery a:first') :current.next()) : $('#hpgallery a:first'));		
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 3000);
	//Hide the current image
	current.animate({opacity: 0.0}, 800)
	.removeClass('show');	
}
