// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

var theID; 
var p1playing;
var p2playing;
var sleeping = true;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(thePlayer, typ, prm) {
	if(typeof thisMovie(thePlayer) != 'undefined') {
		thisMovie(thePlayer).sendEvent(typ,prm);
	}
};

function getUpdate(typ,pr1,pr2,pid) { 
	if ((pid != "null")&&(typ=="state")&&(pr1==2)) {
		if (pid=="player2") { 
			p2playing=true;
			if (p1playing) { sendEvent("player1", 'stop');  p1playing=false; }
		} else { 
			p1playing=true;
			if (p2playing) { sendEvent("player2", 'stop');  p2playing=false; }
		}
	}

	theID=pid; 
	if(typ == "time") { currentPosition = pr1; }
	else if(typ == "volume") { currentVolume = pr1; } 
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(theID, currentItem)",100); }
	var id = document.getElementById(typ);
	id.innerHTML = typ+ ": "+Math.round(pr1);
	pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
	if(pid != "null") {
		//document.getElementById("pid").innerHTML = "(ID: <b><i>"+pid+"</i></b>)";
	}
};


function getItemData(pid, idx) {
	var nodes = "";
	if(pid != "null") {  
		var obj = thisMovie(pid).itemData(idx); 
		for(var i in obj) { 
			nodes += "<li>"+i+": "+obj[i]+"</li>"; 
		}
	} 
	//document.getElementById("data").innerHTML = nodes;
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};


function createPlayer(thePlace, thePlayer, theFile, theImg, start, icons) {
	var s1 = new SWFObject("/player/mp3player.swf", thePlayer, "320","20","7");
	s1.addParam("allowfullscreen", "true");
	s1.addVariable("enablejs","true");
	s1.addVariable("repeat","true");
	s1.addVariable("file", theFile);
	s1.addVariable("javascriptid",thePlayer);
	s1.addVariable("width", "320");
	s1.addVariable("height", "20");
	s1.addVariable("frontcolor","0x232b52");
	s1.addVariable("lightcolor","0x90b5d5");
	s1.addVariable("showdigits","false");
	if (start) s1.addVariable("autostart", "true");
	if (! icons) s1.addVariable("showicons", "false");
	if (theImg != "") s1.addVariable("image", theImg);
	s1.write(thePlace);
}

function createVideoPlayer(thePlace, thePlayer, theFile, theImg, start, icons) {
	var s1 = new SWFObject("/player/mp3player.swf", thePlayer, "214","160","7");
	s1.addParam("allowfullscreen", "true");
	s1.addVariable("enablejs","true");
	s1.addVariable("displaywidth","214");
	s1.addVariable("displayheight","160");
	s1.addVariable("repeat","true");
	s1.addVariable("file", theFile);
	s1.addVariable("javascriptid",thePlayer);
	s1.addVariable("width", "214");
	s1.addVariable("height", "160");
	s1.addVariable("frontcolor","0x232b52");
	s1.addVariable("lightcolor","0x90b5d5");
	s1.addVariable("showdigits","false");
	if (start) s1.addVariable("autostart", "true");
	if (! icons) s1.addVariable("showicons", "false");
	if (theImg != "") s1.addVariable("image", theImg);
	s1.write(thePlace);
}