// 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, id) {
	thisMovie(id).sendEvent(typ, prm);
};

function getUpdate(typ, pr1, pr2) {
	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>)";
	}
	alert("getUpdate: "+pid)

	if (typ == "time") {
		currentPosition = pr1;
	} else if (typ == "volume") {
		currentVolume = pr1;
	} else if (typ == "item") {
		currentItem = pr1;
		setTimeout("getItemData( currentItem, pid)", 100);
	}

};

// These functions are caught by the feeder object of the player.
function loadFile(obj, play, id) {

	//alert(" obj.file = "+obj.file+", obj.image = "+obj.image);

	thisMovie(id).loadFile(obj);
	if (play == true || play == "true") {
		//setTimeout("thisMovie('"+id+"').sendEvent('play', 1)", 10);
		thisMovie(id).sendEvent('playpause',1);
	}

};

function addItem(obj, idx, id) {
	thisMovie(id).addItem(obj, idx);
}
function removeItem(idx, id) {
	thisMovie(id).removeItem(idx);
}
function getItemData(idx, id) {
	var obj = thisMovie(id).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];
	}
};

