$(document).ready(function() {		
	
	//Execute the smallboxL, set 4 seconds for each images
	smallboxL(8000);

});

function smallboxL(speed) {


	//append a LI item to the UL list for displaying caption
	$('ul.smallboxL').append('<li id="smallboxL-caption" class="caption"><div class="smallboxL-caption-container"><h3></h3><p></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.smallboxL li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.smallboxL li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#smallboxL-caption h3').html($('ul.smallboxL a:first').find('img').attr('title'));
	$('#smallboxL-caption p').html($('ul.smallboxL a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#smallboxL-caption').css({opacity: 0.7, bottom:0});
	
	//Call the gallery function to run the smallboxL	
	var timer = setInterval('smallLgallery()',speed);
	
	//pause the smallboxL on mouse over
	/*$('ul.smallboxL').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('biggallery()',speed);			
		}
	);*/
	
}

function smallLgallery() {


	//if no IMGs have the bigshow class, grab the first image
	var current = ($('ul.smallboxL li.smallLshow')?  $('ul.smallboxL li.smallLshow') : $('#ul.smallboxL li:first'));

	//Get next image, if it reached the end of the smallboxL, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'smallboxL-caption')? $('ul.smallboxL li:first') :current.next()) : $('ul.smallboxL li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//Set the fade in effect for the next image, bigshow class has higher z-index
	next.css({opacity: 0.0}).addClass('smallLshow').animate({opacity: 1.0}, 2000);
	
	//Hide the caption first, and then set and display the caption
	$('#smallboxL-caption').slideToggle(300, function () { 
		$('#smallboxL-caption h3').html(title); 
		$('#smallboxL-caption p').html(desc); 
		$('#smallboxL-caption').slideToggle(1000); 
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 2000).removeClass('smallLshow');

}
