// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

// these functions are caught by the JavascriptView object of the player.
//function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,pid) {
	if(typ == "time") { currentPosition = pr1; }
	else if(typ == "volume") { currentVolume = pr1; }
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); playItem(pr1, false); }
	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 = "(received from the player with id <i>"+pid+"</i>)";
	}
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("ply").loadFile(obj); };
function addItem(obj,idx) { thisMovie("ply").addItem(obj,idx); }
function removeItem(idx) { thisMovie("ply").removeItem(idx); }
function getItemData(idx) {
	var obj = thisMovie("ply").itemData(idx);
	var nodes = "";
	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];
	}
};


var activeVideoId = 0;
function playItem(number, external) {
	if(number > -1)
	{
		if(external)
		{
			sendEvent('playitem', number);			
		}
		var playlistItems = document.getElementById('playlist').childNodes;
		for(var i=0;i<playlistItems.length;i++)
		{
			playlistItems[i].className="";
		}
		document.getElementById('playlistItem'+number).className="active";
		activeVideoId=document.getElementById('videoId'+number).value;
	}
}

function sendEvent(typ,prm) { thisMovie("ply").sendEvent(typ,prm); }

var s0;
function createPlayer(theFile, theImg, start, icons) {
	var theImg = "";
	s0 = new SWFObject("../flv/mediaplayer.swf","ply","368","227","8");
	s0.addParam("allowfullscreen","true");
	//s0.addParam("wmode","transparent");
	s0.addVariable("file","../flv/playlist.xml");
	s0.addVariable("width","368");
	s0.addVariable("height","227");
	//s0.addVariable("displayheight","350");
	//s0.addVariable("backcolor","0x000000");
	//s0.addVariable("frontcolor","0xCCCCCC");
	//s0.addVariable("lightcolor","0x3333AA");
	s0.addVariable("autoBuffering","true");
	s0.addVariable("enablejs","true");
	s0.addVariable("shuffle","false");
	//s0.addVariable("thumbsinplaylist","true");
	if (start) s0.addVariable("autostart", "true");
	if (! icons) s0.addVariable("showicons", "false");
	if (theImg != "") s0.addVariable("image", theImg);
	s0.write("video");
}