// 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("player0").loadFile(obj); };
function addItem(obj,idx) { thisMovie("player0").addItem(obj,idx); }
function removeItem(idx) { thisMovie("player0").removeItem(idx); }
function getItemData(idx) {
	var obj = thisMovie("player0").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 createSinglePlayer(theFile, theImg, width, height, id) {
	var start = "true";
	var icons = "true";
	
	obj = new SWFObject("jwplayer/mediaplayer.swf","slikVideoPlayer"+id,width,height,"7");
	obj.addParam("allowfullscreen","true");
	//obj.addParam("wmode","transparent");
	obj.addVariable("file",theFile);
	obj.addVariable("width",width);
	obj.addVariable("height",height);
	//obj.addVariable("displayheight",height);
	obj.addVariable("backcolor","0x000000");
	obj.addVariable("frontcolor","0xCCCCCC");
	obj.addVariable("lightcolor","0x3333AA");
	obj.addVariable("autoBuffering","true");
	obj.addVariable("enablejs","false");
	obj.addVariable("shuffle","false");
	if (start) obj.addVariable("autostart", "false");
	if (! icons) obj.addVariable("showicons", "false");
	if (theImg != "") obj.addVariable("image", theImg);
	obj.write("slikVideoPlayerDiv"+id);
}

function tellafriend(ref)
{
	if(ref != '' && activeVideoId)
	{
		ref = "/"+ref+escape('&movie='+activeVideoId);
		window.open(ref, 'Tellafriend', 'width=400, height=480');
		return false;				
	}
}
