$( document ).ready( function() {

	var movieHtml = '	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="REPLACE_WIDTH" height="REPLACE_HEIGHT" id="flashMovie" align="middle">' +
	'	<param name="allowScriptAccess" value="sameDomain" />' +
	'	<param name="allowFullScreen" value="false" />' +
	'	<param name="movie" value="REPLACE_HREF.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#C0C0C0" />	<embed src="REPLACE_HREF.swf" quality="high" wmode="opaque" bgcolor="#C0C0C0" width="REPLACE_WIDTH" height="REPLACE_HEIGHT" name="flashMovie" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
	'	</object>';
	var ytMovieHtml = '<object width="REPLACE_WIDTH" height="REPLACE_HEIGHT"><param name="movie" value="REPLACE_HREF&autoplay=1&rel=0"></param><param name="wmode" value="transparent"></param><embed src="REPLACE_HREF&rel=0&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="REPLACE_WIDTH" height="REPLACE_HEIGHT"></embed></object>'
	var width = 480;
	var height = 360;

	$( '.movieLink' ).click( function() {
		// Raise another 'window' to show the movie in
		var href = $( this ).attr( 'href' );
		var i = href.indexOf( '.html' );
		if( i ) {
			href = href.substring( 0, i );
		}
		var html = movieHtml.replace( /REPLACE_HREF/g, href )
							.replace( /REPLACE_WIDTH/g, 480 )
							.replace( /REPLACE_HEIGHT/g, 360+45 );
		
		$( '#movieWindow' )
			// Position window in the left/right center of the viewport
			// Assumes: #everything is 900px wide, movie is 640px wide
			.css({ left: '130px', top: $( "#header" ).height() + 10 + 'px' })
			.find( '.movie' )
				.html( html )
			.end()
			.slideDown( 'normal' )
			.find( 'a' )		// close link
				.click( function() { 
					$( '#movieWindow' )
						.slideUp( 'slow' )
						.find( '.movie' )
							.html( '' );	// Kills flash player
					return( false ); 
				});
		
		return( false );
	});
	
	dumpit( $( "#name" ).value );
	$( "#name" ).value = "Not a test...";

	$( "form" ).submit( function() {
		var errStr = "";
		$( ":input", $( this )).each( function() {
			var type = this.type;
			var val = $( this ).val();
			if( (( "text" == type ) || ( "textarea" == type )) && ( "" == val )) {
				errStr += "\tThe " +this.id+ " field is required.\n";
			} else if(( "email" == this.id ) && ( !isValidEmail( val ))) {
				errStr += "\t'" +val+ "' is not a valid email address\n";
			} 
		});
		if( "" == errStr ) {
			return( true );
		} else {
			alert( "Please correct the following errors: \n\n" +errStr );
			return( false );
		}
	});
	
/*	$( '.YTmovieThumbnail a' ).click( function() {
		var html = ytMovieHtml.replace( /REPLACE_HREF/g, $( this ).attr( 'href' ))
							  .replace( /REPLACE_WIDTH/g, 480 )
							  .replace( /REPLACE_HEIGHT/g, 360 );
		$( '#movieWindow' )
			// Position window in the left/right center of the viewport
			// Assumes: #everything is 900px wide, movie is 640px wide
			.css({ left: '50px', top: $( "#header" ).height() + 10 + 'px' })
			.find( '.movie' )
				.html( html )
			.end()
			.show( 'slow' )
			.find( 'a' )		// close link
				.click( function() { 
					$( '#movieWindow' )
						.hide( 'slow' )
						.find( '.movie' )
							.html( '' );	// Kills flash player
					return( false ); 
				});
		
		return( false );
	});*/

	//alert( 'done.' );

});

function dumpit( obj ) {
	if ( obj ) {
		$.each (obj, function (key, val) {
			console.log( "\t" +key+ " = " +val );
		});
	}
}

function isValidEmail( email ) {
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/i;
	if( email.match( re )) {
		return( true );
	} else {
		return( false );
	}
}
