var hide_video = function( callback ) {
	$('#flash-wrapper').fadeOut('slow', function() {
		$('#flash-player')
		.empty()
		.createAppend('div',{'id':'flash-placeholder'});
		if( callback ) callback();
	});
};
var play_video = function( video ) {
	hide_video( function() {
		swfobject.embedSWF( 'flash/video-large.swf', 'flash-placeholder', '100%', '100%', '9.0.0', null, { 'hero': 'flash/' + video + '.swf' }, { 'quality': 'highest', 'wmode': 'transparent', 'menu': false, 'allowScriptAccess': 'sameDomain' }, {} );
		$('#flash-wrapper').fadeIn('slow');
	} );
};
var play_youtube_video = function( key, width, height ) {
	width = width || '100%';
	height = height || '100%';
	hide_video( function() {
		swfobject.embedSWF( 'http://www.youtube.com/v/' + key + '&hl=en&amp;fs=1&autoplay=1', 'flash-placeholder', width, height, '9.0.0', null, {}, { 'quality': 'highest', 'allowFullScreen': true, 'wmode': 'transparent', 'menu': false, 'allowScriptAccess': 'sameDomain' }, {} );
		$('#flash-wrapper').fadeIn('slow');
	} );
};
$(function() {
   $('body').createAppend('div',{'id':'flash-wrapper'})
   .hide()
   .height( '100%' )
   .width( '100%' )
   .click( function() { hide_video(); } )
   .createAppend('div',{'id':'flash-player'})
   .click( function( e ) {
		e.stopImmediatePropagation();
	} );
	var price = $('form[action^="https://checkout.google.com/"] input[name="item_price_1"]');
	var do_validate = function() {
		return price.val().match( /^[0-9]+(\.[0-9]{2})?$/ ) && ( parseFloat( price.val() ) > 0 );
	};
	$('form[action^="https://checkout.google.com/"]')
	.submit( function( e ) {
		if( !do_validate() ) {			
			e.preventDefault();
			price.focus();
			alert( 'You must enter a valid donation.' );
		}
	} );
	price.one( 'focus', function( e ) {
		$(this).data( 'default value', $(this).val() )
		.val( '' )
		.focus( function() {
			if( $(this).val() == $(this).data( 'default value' ) ) $(this).val( '' );
			$(this)
			.removeClass( 'populated' )
			.addClass( 'selected' );
		} )
		.blur( function() {
			if( $(this).val() && do_validate() ) {
				$(this)
				.addClass( 'populated' );
			} else {
				$(this)
				.val( $(this).data( 'default value' ) )
				.removeClass( 'populated' );	
			}
			$(this).removeClass( 'selected' );
		} );
	} );
});