var jquery_load_success	= false;

$(document).ready( function() {
	
	jquery_load_success	= true;
	
	$("#pause").click(function(event) {
	
		event.preventDefault();
	
		pausePlayer()
	
	});
	
	$("#start").click(function(event) {
	
		event.preventDefault();
	
		startPlayer()
	
	});
	
	$('#embed_code_link').click(function(event) {
		
		event.preventDefault();
		
		$('#embed_code').toggle('slow');
	
	});
	
	if( mp_code == '00xx' && video_mp_code != '' ) {
	
		$('html').append('<scr'+'ipt type="text/javascript" src="http://www.flirt4free.com/javascript/tube/referrer.php?mp_code='+video_mp_code+'"></scr'+'ipt>');
	
	}

});

function isReady() {
	
	if( jquery_load_success ) {
	
		return true;
	
	} else {
	
		return false;
	
	}

}
	
function confirmActionScriptReady() {

	actionscript_ready	= true;

}
	
function actionScriptCommand( asDirective, asVariables, objectId ) {

	var asCommand	= "";
	
	if( actionscript_ready ) {
	
		$(document).ready( function() {
			
			asCommand		+= "<action><directive>" + asDirective + "</directive><variables>";
									
			$.each( asVariables, function( key, val ) {
			
				//
				//	Create the variables XML
				//
				asCommand	+= "<" + key + ">" + val + "</" + key + ">";
			
			});
			
			asCommand		+= "</variables></action>";
			
			//flash = ($.browser.msie) ? window[ objectId ] : document[ objectId ];
			
			var flash = false;
			
			if( window.document[ objectId ] && !flash ) {		//	Chrome, Firefox
			
				flash = window.document[ objectId ];
			
			}
			
			if( window[ objectId ] && !flash ) {
			
				flash = window[ objectId ];
			
			}
			
			if( document[ objectId ] && !flash ) {
			
				flash = document[ objectId ];
			
			}
			
			if( document.embeds && document.embeds[ objectId ] && !flash ) {
			
				flash = document.embeds[ objectId ];
			
			}
			
			if( document.getElementById( objectId ) && !flash ) {
			
				flash = document.getElementById( objectId );
			
			}
			
			flash.sendToActionScript( asCommand );
		
		});
	
	}
	
}

function startPlayer()
{
	if( actionscript_ready ) {
		
		asDirective			= "play";
		
		asVariables			= {	"state"	: true	};
		
		actionScriptCommand( asDirective, asVariables, "tube_player" );
	
	}
}

function pausePlayer()
{
	if( actionscript_ready ) {
		
		asDirective			= "play";
		
		asVariables			= {	"state"	: false	};
		
		actionScriptCommand( asDirective, asVariables, "tube_player" );
	
	}
}


