$(document).ready(function() {		
	
	//Execute the slideShow
	slideShow();
	
	


});


   

function slideShow() {
	var play = setInterval('gallery()',3500);
	var pauseFunc = function() {
        clearInterval(play);
      }
	 
//$("#nav-level2 a").removeAttr("title");

	

	//Set the opacity of all images to 0
	$('#gallery li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery li:first').animate({opacity: 1.0}, 1000);
	
	//Set the caption background to semi-transparent
	$('#gallery li:first .caption').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').animate({opacity: 1.0}, 400);
		
	// Insert left and right arrow controls in the DOM
 	$('.slide-links a')
    .after('<span class="control rightControl">Next &raquo;</span>');

	$('.control').click(function(){
	gallery();
	pauseFunc();
	
    });
	play();
}



function gallery() {
		
	  	//if no LIs have the show class, grab the first image
	var current = ($('#gallery li.show') ? $('#gallery li.show') : $('#gallery 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')) ? $('#gallery li:first') : current.next()) : $('#gallery li: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');
		
}