// JavaScript Document


// This occurs right before the photo starts to fade out, and the next one fades in
function onBefore() {
	// The # in "fadeOut(####," is the number of milliseconds it will take for the drop-shadow text to fade out
	// This *must* be lower than the photo's fade out value (speed: below), due to the IE issue mentioned below
	$('#masthead-text').fadeOut(1500, function() { $('#masthead-text').html("").hide() });
}
function onAfter() {
	//currSlideElement, nextSlideElement, options, forwardFlag

	// gets the title attribute of the photo, which must match the image of the text/overlay image
	var theText = $(this).attr('title');

	// Uncomment this line and comment the next to simply use text, instead of an image, as the overlay
	//theText = theText.replace('\\n','<br />'); // keeps our HTML valid, while still allowing line breaks.
	theText = '<img src="/images/mastheads/' + theText + '.png" />';
	
	$('#masthead-text').attr( 'class', $(this).attr('id') + '-text' );
	
	// This resolves a known issue in IE, where the transparent PNGs were showing a 'blob of black'
	// We set the background of the PNGs container to the currently displayed photo, then fade it out
	// faster (see above) than the photo to prevent display issues
	$('#masthead-text').css('background-image','url('+$(this).attr('src')+')');
	
	// Add the overlay and fade it in (in milliseconds)
	$('#masthead-text').html( theText );
	// nope $('#masthead-text').css('zoom','1');
	// nope $('#masthead-text').css('filter','alpha(opacity = 0)');
	// nope $('#masthead-text').toggle();
	$('#masthead-text').fadeIn(1000);
	// almost... :P $('#masthead-text').fadeTo(1000,1);
}

$(document).ready( function(){
	// append our overlay container
	$("#masthead").prepend('<div id="masthead-text"></div>');

	// Start the cycle plugin, and go to town
	//$('#masthead-images img:first').fadeIn(2000, function() {
		$("#masthead-images").cycle({
			before:  onBefore, 
			after:   onAfter,
			timeout: 2000,
			speed:   4000,
			delay:   -4000 // fix: makes the first text fade out match the rest of the animation - should be negative value of speed
		});
	//});


});