/*
	JW FLV Player functions, manipulation and event handling - JWC 09-20-2008
*/

function fetchForm(element) {
	new Ajax.Updater(element, '/leads/add', { method: 'post', evalScripts: 'true', onLoading:function(request) {Element.show('LoadingDiv');}, onComplete:function(request, json) {Element.hide('LoadingDiv');} });
}

var currentState = "NONE";
var previousState = "NONE";

var player = null;
function playerReady(thePlayer) {
	player = document.getElementById(thePlayer.id);
	addListeners();
}

function addListeners() {
	if (player) {
		player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate;
	previousState = obj.oldstate;
	if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
		fetchForm('body-content');
	}
}

function createPlayer(theFile,theWidth,theHeight) {
	var flashvars = {
		file:theFile,
		autostart:"true",
		controlbar:"over",
		stretching:"none",
		bufferlength:"10",
		quality:"false"
	}

	var params = {
		allowfullscreen:"false",
		allowscriptaccess:"always"
	}

	var attributes = {
		id:"player1",
		name:"player1"
	}

	swfobject.embedSWF("/flash/player4-1.swf", "noflash", theWidth, theHeight, "9.0.115", "/flash/expressInstall.swf", flashvars, params, attributes);
}
