/**
 * @author	Allex Smith
 * @email	allex.smith@chelanpud.org
 * @date	Jan 25, 2008
 * 
 * @updated	Feb 19, 2008
 * 			Updated flashvars for flvplayer to stretch video to fit properly
 * @updated	Jun 30, 2008
 *			Added code to handle web site survey, comment out when not in use
 * @updated	2008
 *			Added code to redirect email links to email form page
 * 
 */
$(function(){
	/* Video Player Function */
	// iterate over each element that is a '.video-player'
	$('.video-player').each(function(){
		// get the metadata out of the class
		$(this).html('');
		var videoData = $(this).metadata();
		$(this).flash(
	        { 
	          src: 'video/flvplayer.swf',
	          width: videoData.width,
	          height: videoData.height,
			  
	          flashvars: {file:videoData.video,overstretch:'true',image:videoData.image}
	        },
	        { version: 8 }
	    );
	});
	
	/* Image Cycle Transitions */
	$('#main-feature').cycle({ 
		fx:	'fade',
		pause:	1,
	    	speed:	5000
	});

	/* Mailto Function */
	// regular expression jQuery selector with bound click event
	$('a[@href^="mailto:"][@href*="chelanpud.org"]:not(.email-exception)').click(function(){
		var $mailto = $(this).attr('href');
		var $holder = $mailto;
		// drop the 'mailto:'
		$mailto = $mailto.replace(/mailto:/,'');
		// replace the '?' with a '&'
		$mailto = $mailto.replace(/\?/,'&');
		// this will eventually send the user to a coldfusion
		// page that will parse the 'mailto' string for the
		// relevant information
		//alert('You clicked on an email link:\n '+'http://www.chelanpud.org/?email=' + $mailto);
		$mailto = 'http://www.chelanpud.org/email-us.cfm?email=' + $mailto + '&ref=' + window.location;
		window.location = $mailto;
		// override defaul behavior
		return false;
	});

	/*
	 * Code that handles the survey
	 * Uncomment and update the survey link and image
	 * image should fit perfectly over the top of the #main-feature image
	 * simply comment out the code when no longer in use.
	 */
	/*
	$('#main-feature').append('<a href="http://www.surveymonkey.com/s.aspx?sm=gx5FRR2C9E14GIJOTRBz_2fg_3d_3d" title="Tell us what you think!" target="_blank"><img id="survey-image" src="/departments/communications/survey/survey_July08.gif" title="Tell us what you think!" alt="Tell us what you think!" /></a>');
	$('#main-feature').css({position:"relative"});
	$('#survey-image').css({position:"absolute",top:"15px",left:"0"});
	*/
});