$(document).ready(function() {
	
	//----------- Slideshow
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   1500, 
		timeout: 5000,
		next:   '#next',
		prev:   '#prev',
		before:  onBefore, 
		after:   onAfter
	 });
	
	function onBefore() { 
		$('#slideshow_captions').animate({  
			height: "0"
		}, 500 );
		$('#slideshow_captions').html(""); 	
	} 
	
	function onAfter(curr,next,opts) { 
		if (this.alt != '') {
			$('#slideshow_captions').animate({ 
				height: "30px"
			}, 500 );
			//console.log(opts.slideCount);
			$('#slideshow_captions').append('<span class="slideshow_caption"><strong>' + this.title + '</strong> - <i>' + this.alt + '</i></span>'); 
		}
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}		
	}
	
	//Not used
	function onAfterHome() { 
		$('#slideshow_captions').animate({ 
			height: "16px",
			opacity: 0.7
		}, 500 );
		$('#slideshow_captions').append('<h2 class="homeSlideCaption">' + this.alt + '</h2>'); 
	}
	
	//----------- Controls
	$('#controls').fadeTo(0, 0.7);
	
	$('#controls').hover(function() {
		$(this).fadeTo('slow', 1);
	},function() {
		$(this).fadeTo('slow', 0.7);
	});
	
	$('#pause').click(function() {
		$('#slideshow').cycle('pause');
		return false;
	});
	
	$('#play').click(function() {
		$('#slideshow').cycle('resume');
		return false;
	});

}); //Close document.ready

$(window).bind("load", function() {
    //-----------  Preload images for slideshows
	$('#slideshow_loading').hide();
	$('#slideshow_wrapper').fadeIn(2000);
});
