$(document).ready(function() {
	
	// IF THE #NEWS-ROTATOR-LIST ELEMENT IS PRESENT
	// THEN START UP THE NEWS ROTATOR
	
	if($("#news-rotator-list").is("*")) {
	
		$("#news-rotator-list").list_ticker({
			effect: "fade",
			speed: 6000
		});
		
		$("#news-rotator-list").fadeIn('slow');
	
	}
	
	if($("#slideshow").is("*")) {
		
		slideShow(8000);
		
	}
	
});



function slideShow(speed) {  

	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p class="desc"></p><p class="link"></p></div></li>');
	$('ul.slideshow li').css({opacity: 0.0}); 
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	$('#slideshow-caption h3').html($('ul.slideshow li:first').find('span.title').html());
	$('#slideshow-caption p.desc').html($('ul.slideshow li:first').find('span.desc').html());  
	if($('ul.slideshow li:first').find('span.link').length > 0) {
		$('#slideshow-caption p.link').html('<a href="' + $('ul.slideshow li:first').find('span.link').html() + '">&gt; Read More</a>');
	}
	
	$('#slideshow-caption').css({opacity: 0.7, bottom:0});
	
	var timer = setInterval('gallery()',speed);  
	  
	$('ul.slideshow').hover(  
		function () {  
			clearInterval(timer);     
		},    
		function () {  
			timer = setInterval('gallery()',speed);           
		}  
	);  
	  
} 

function gallery() {  
 
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));  
  	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));  
	var title = next.find('span.title').html();   
	var desc = next.find('span.desc').html(); 
	var link = next.find('span.link').html();
		  
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);  
	  
	$('#slideshow-caption').animate({bottom:-70}, 300, function () {
			$('#slideshow-caption h3').html(title);  
			$('#slideshow-caption p.desc').html(desc);
			if($('ul.slideshow li:first').find('span.link').length > 0) {
				$('#slideshow-caption p.link').html('<a href="' + $('ul.slideshow li:first').find('span.link').html() + '">&gt; Read More</a>');
			}
			$('#slideshow-caption').animate({bottom:0}, 500);     
	});       
  
	current.animate({opacity: 0.0}, 1000).removeClass('show');  
  
} 

