/*
 * Taken from: http://www.jeroenwijering.com/extras/javascript.html
 */


	// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;
	var movieID = "mplayer";

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm)
	{
		if ( !thisMovie(movieID) )
			return;
		
		thisMovie(movieID).sendEvent(typ,prm);
	}
	
	function getUpdate(typ,pr1,pr2,pid)
	{
		if ( !thisMovie(movieID) )
			return;
		
		if(typ == "time") { currentPosition = pr1; }
		else if(typ == "volume") { currentVolume = pr1; }
		else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(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 = "(received from the player with id <i>"+pid+"</i>)";
		}
	}

	// These functions are caught by the feeder object of the player.
	function loadFile(obj)
	{
		if ( !thisMovie(movieID) )
			return;
		
		thisMovie(movieID).loadFile(obj);
	}
	function addItem(obj,idx)
	{
		if ( !thisMovie(movieID) )
			return;
		
		thisMovie(movieID).addItem(obj,idx);
	}
	function removeItem(idx)
	{
		if ( !thisMovie(movieID) )
			return;
		
		thisMovie(movieID).removeItem(idx);
	}
	function getItemData(idx)
	{
		if ( !thisMovie(movieID) )
			return;
		
		var obj = thisMovie(movieID).itemData(idx);
		var nodes = "";
		for(var i in obj) { 
			nodes += "<li>"+i+": "+obj[i]+"</li>"; 
		}
		
		var dataObj = document.getElementById("data");
		if ( dataObj )
			dataObj.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];
		}
	}
