
$(document).ready(function(){

	//----------- Search animation

	$('#trigger').toggle(function() {
		$('#search').animate({ top: "0" }, 200, function() { $('#trigger').find('img').attr('src','assets/templates/default_tpl/images/close.gif') } );						   
    },function() {
		$('#search').animate({ top: "-38px" }, 200, function() { $('#trigger').find('img').attr('src','assets/templates/default_tpl/images/trigger.gif') } );			
	})	

	//----------- Main Slideshow
	
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   1500, 
		timeout: 5000, 
		next:   '#next',
        prev:   '#prev',
		before:  onBefore, 
		after:   onAfter
	 });
	
	function onBefore() { 
		$('#output').animate({  
			height: "0",
			opacity: 0
		}, 500 );
		$('#output').html("");
	}
	
	function onAfter(curr,next,opts) { 
		if (this.alt != '') {
			$('#output').animate({ 
				height: "26px",
				opacity: 0.7
			}, 500 );
			//console.log(opts.slideCount);
			$('#output').append('<h2>' + this.title + '</h2><p>' + this.alt + '</p>'); 
		}
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}
	}
	
	$('#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
	$('#loading').hide();
	$('#slideshowWrapper').fadeIn('slow');

});
