var JWFPlayers = [];
var playerID; 
var playerPlaying = false;

function sendEvent(thePlayer, typ, prm) { thisMovie(thePlayer).sendEvent(typ,prm); };
function loadFile(thePlayer, obj) { thisMovie(thePlayer).loadFile(obj); };

function getUpdate(typ, pr1, pr2, pid) {	
	if ((pid != "null") && (typ == "state") && (pr1 == 2)) {
		if (playerID != pid && playerPlaying == true) sendEvent(playerID, "playpause");
		playerID = pid;
		playerPlaying = true;
	}
	if ((pid != "null") && (typ == "state") && (pr1 == 0)) playerPlaying = false;
};

function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};

function startPlayer(thePlayer, obj) {
	sendEvent(thePlayer, "stop");
	thisMovie(thePlayer).loadFile(obj);
	sendEvent(thePlayer, "playpause");
}

function stopAllPlayers() {
	var PlayersCount = JWFPlayers.length;
	for (var i = 0; i < PlayersCount; i++) {
		sendEvent(JWFPlayers[i], "stop");
		if (JWFPlayers[i] == playerID) playerPlaying = false;
	}
}

function pausePlayer() {
	if (playerID && playerPlaying == true) {
		sendEvent(playerID, "playpause");
		playerPlaying = false;
	}
}

function createPlayer(thePlace, thePlayer, theFile, theImg, start, icons) {
	var s1 = new SWFObject("mediaplayer.swf", thePlayer, "280","240","7");
	s1.addParam("allowfullscreen", "true");
	s1.addVariable("enablejs","true");
	s1.addVariable("repeat","true");
	s1.addVariable("shuffle","false");
	s1.addVariable("file", theFile);
	s1.addVariable("javascriptid",thePlayer);
	s1.addVariable("width", "280");
	s1.addVariable("height", "240");
	s1.addVariable("displaywidth", "280");
	s1.addVariable("displayheight", "176");
	if (start) s1.addVariable("autostart", "true");
	if (! icons) s1.addVariable("showicons", "false");
	if (theImg != "") s1.addVariable("image", theImg);
	s1.write(thePlace);
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
