$(document).ready(function(){
	
	//----------- Home Content Vertical Alignment
	$('#main_content.home').vAlign();
	
	//----------- Main Slideshow
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   1500, 
		timeout: 0, 
		next:   '#next',
        prev:   '#prev',
		before:  onBefore, 
		after:   onAfter
	 });
	
	$('#home_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).find('img').attr('alt')) {
			$('#output').animate({ 
				height: "32px",
				opacity: 0.7,
				paddingTop: '8px'
			}, 500 );
			//console.log(opts.slideCount);
			//$('#output').append('<h2>' + $(this).find('img').attr('title') + '</h2><p>' + $(this).find('img').attr('alt') + '</p>');
			$('#output').append('<p>' + $(this).find('img').attr('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; });
	
	$('a.fancy').fancybox({
		'overlayShow': true,
		'overlayOpacity': 0.8
	});
	
	$('a.iframe').fancybox({
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'frameWidth': 700,
		'frameHeight': 500
	});
	
	
});

$(window).bind("load", function() {
    //-----------  Preload images for slideshows
	$('#loading').hide();
	$('#slideshowWrapper').fadeIn('slow');
});
