//Photoslider with captions compliments of [Queness]

//----------------------Slideshow - Top Stories -------[fix later to combine all slideshows AFTER calculating individual widths and heights]
$(document).ready(function() {	
	
	//Execute the slideShow, set milliseconds for each images
	slideShow_topstories(5000);

});

function slideShow_topstories(speed) { 
	
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow_topstories').append('<li id="slideshow-caption_topstories" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
	
	//Set the opacity of all images to 0
	$('ul.slideshow_topstories li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow_topstories li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption_topstories h3').html($('ul.slideshow_topstories a:first').find('img').attr('title'));
	$('#slideshow-caption_topstories p').html($('ul.slideshow_topstories a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#slideshow-caption_topstories').css({opacity: 0.7, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery_topstories()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow_topstories').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery_topstories()',speed);			
		}
	);
	
}

function gallery_topstories() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow_topstories li.show')?  $('ul.slideshow_topstories li.show') : $('#ul.slideshow_topstories li:first'));
	
	//trying to avoid speed issue
	if(current.queue('fx').length == 0) {	
	
	//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().attr('id') == 'slideshow-caption_topstories')? $('ul.slideshow_topstories li:first') :current.next()) : $('ul.slideshow_topstories 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, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption_topstories').slideToggle(300, function () { 
		$('#slideshow-caption_topstories h3').html(title); 
		$('#slideshow-caption_topstories p').html(desc); 
		$('#slideshow-caption_topstories').slideToggle(500); 
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');
	
	}
}



//-----------------------On Site
$(function() {		
	
	//Execute the slideShow, set milliseconds for each images
	slideShow_onsite(4000);

});

function slideShow_onsite(speed) { 
	
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow_onsite').append('<li id="slideshow-caption_onsite" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
	
	//Set the opacity of all images to 0
	$('ul.slideshow_onsite li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow_onsite li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption_onsite h3').html($('ul.slideshow_onsite a:first').find('img').attr('title'));
	$('#slideshow-caption_onsite p').html($('ul.slideshow_onsite a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#slideshow-caption_onsite').css({opacity: .7, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery_onsite()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow_onsite').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery_onsite()',speed);			
		}
	);
	
}

function gallery_onsite() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow_onsite li.show')?  $('ul.slideshow_onsite li.show') : $('#ul.slideshow_onsite li:first'));
	
	//trying to avoid speed issue
	if(current.queue('fx').length == 0) {	
	
	//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().attr('id') == 'slideshow-caption_onsite')? $('ul.slideshow_onsite li:first') :current.next()) : $('ul.slideshow_onsite 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, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption_onsite').slideToggle(300, function () { 
		$('#slideshow-caption_onsite h3').html(title); 
		$('#slideshow-caption_onsite p').html(desc); 
		$('#slideshow-caption_onsite').slideToggle(500); 
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');
	}
}





//---------------------Upcoming Events 
$(function() {		
	
	//Execute the slideShow, set milliseconds for each images
	slideShow_upcoming(3000);

});

function slideShow_upcoming(speed) { 
	
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow_upcoming').append('<li id="slideshow-caption_upcoming" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
	
	//Set the opacity of all images to 0
	$('ul.slideshow_upcoming li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow_upcoming li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption_upcoming h3').html($('ul.slideshow_upcoming a:first').find('img').attr('title'));
	$('#slideshow-caption_upcoming p').html($('ul.slideshow_upcoming a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#slideshow-caption_upcoming').css({background: "#000", opacity: 1, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery_upcoming()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow_upcoming').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery_upcoming()',speed);			
		}
	);
	
}

function gallery_upcoming() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow_upcoming li.show')?  $('ul.slideshow_upcoming li.show') : $('#ul.slideshow_upcoming li:first'));
	
	//trying to avoid speed issue
	if(current.queue('fx').length == 0) {	
	
	//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().attr('id') == 'slideshow-caption_upcoming')? $('ul.slideshow_upcoming li:first') :current.next()) : $('ul.slideshow_upcoming 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, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1500);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption_upcoming').slideToggle(300, function () { 
		$('#slideshow-caption_upcoming h3').html(title); 
		$('#slideshow-caption_upcoming p').html(desc); 
		$('#slideshow-caption_upcoming').slideToggle(500); 
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 1500).removeClass('show');
	}
}

