function slideShow(e,speed) {	
	//Set the opacity of all images to 0
	$(e+' li').animate({opacity: 0}, 50);
	//Get the first image and display it (set it to full opacity)
	$(e+' li:first').animate({opacity: 1}, 50);
	bindSlideAction( $(e+' li:first') ) // Add links

	if ($(e).children().size() > 1)	setInterval('gallery("'+e+'")',speed); // only activate the gallery when needed
}

function gallery(e) {
	//if no IMGs have the show class, grab the first image
	var current = ($(e+' li')?  $(e+' li.show') : $(e+' li: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')) ? $(e+' li:first') : current.next() ) : $(e+' li:first'));
	
	bindSlideAction(next)	

	//Set the fade in effect for the next image, show class has higher z-index
	next.animate({opacity: 0}, 50);
	next.addClass('show');
	next.animate({opacity: 1}, 750);
	//Hide the current image
	current.animate({opacity: 0}, 750)
	current.removeClass('show');		
}

function bindSlideAction(obj)
{	
	if ( obj.children('div').children('a').attr('href') != null )
	{
		obj.addClass('clickable');
		obj.bind('click',function(){
			window.location = $(this).children('div').children('a').attr('href') ;
		});
	}
}
