


jQuery(document).ready(function() {		

	slideShow('#presentation .right');
});


	


function slideShow(slideShowObj) {
	
	//Set the opacity of all images to 0
	jQuery(slideShowObj + ' span.slide').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	jQuery(slideShowObj + ' span.slide:first').css({opacity: 1.0});
	
	//Get next image caption
	var caption = jQuery(slideShowObj + ' span.slide:first').find('img').attr('alt');	
	var description = jQuery(slideShowObj + ' span.slide:first').find('span.desc').text();	
	var link = jQuery(slideShowObj + ' span.slide:first span.desc').find('a').attr('href');
    
    jQuery(slideShowObj + ' span.slide:last a.slide-link').attr('href',link);
    
	//Get the caption of the first image from REL attribute and display it
	$('#presentation .left h1').html(caption);
	$('#presentation .left h2').html(description);
	$('#presentation .left a').attr('href', link);
    
	//update the Font using Cufon
    Cufon.set('fontFamily', 'HelveticaNeue').replace('div#presentation h1')('div#presentation h2');
	//Display the caption
	$('#presentation .left').css({left:20});
	
	setInterval('gallery(\'' + slideShowObj + '\')',6000);
}

function gallery(slideShowObj) {
	//if no IMGs have the show class, grab the first image
	var current = (jQuery('#presentation .right span.slide.show')?  jQuery('#presentation .right span.slide.show') : jQuery('#presentation .right span.slide:first'));
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? jQuery('#presentation .right span.slide:first') :current.next()) : jQuery('#presentation .right span.slide:first'));	
	//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}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

	//Get next image caption
	var caption = next.find('img').attr('alt');
    var descElement = next.find('span.desc');
	var description = descElement.text();	
	var link = descElement.find('a').attr('href');
    
	//Hide the caption first, and then set and display the caption
	$('#presentation .left').animate({left:-350}, 300, function () {
			//Display the content
			$('#presentation .left h1').html(caption);
			$('#presentation .left h2').html(description);
			$('#presentation .left a').attr('href',link);
            
            jQuery(slideShowObj + ' span.slide:last a.slide-link').attr('href',link);
            
			//update the Font using Cufon
            Cufon.set('fontFamily', 'HelveticaNeue').replace('div#presentation h1')('div#presentation h2');
			$('#presentation .left').animate({left:20}, 500);	
	});		

}
