// 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); }

	var id = document.getElementById(typ);
    
   if(typ == "state") { id.innerHTML = "<img src='"+Math.round(pr1)+"_button.gif'>"  ; }
     
//	id.innerHTML = typ+ ": "+Math.round(pr1);
	pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
	
	if(typ == "time") { 
//	pr2 == undefined ? null: id.innerHTML =  "<img src='dark.gif'  height='10' width='"+Math.round(100/(pr2+pr1)*pr1)+"'><img src='playhead.gif' height='10' ><img src='light.gif' height='10' width='"+Math.round(100/(pr2+pr1)*pr2)+"'>";
		
		pr2 == undefined ? null: id.innerHTML =  " <div id='progress' style='height:4px;width:"+(Math.round(100/(pr2+pr1)*pr1))+"px'></div><div id='phead' style='height:8px; width:14px'></div>"; }
							

											
						
	if(typ == "load") {
		 //		pr2 == undefined ? null: id.innerHTML = typ+ ": "+Math.round(pr1)+": "+Math.round(pr2);
		 if (pr1 == "100") {
		// 	id.innerHTML =  "<img src='light.gif'  height='10' width='"+Math.round(pr1)+"'><img src='dark.gif' height='10' width='"+(100-Math.round(pr1)+10)+"'> loaded";
	//	 	id.innerHTML =  "<div id='playhead' style='width="+(100-Math.round(pr1))+"px'>"+(100-Math.round(pr1))+"</div>";
	id.innerHTML = "";
		 }
		 else {
	//	id.innerHTML =  "<img src='light.gif'  height='10' width='"+(10+Math.round(pr1))+"'><img src='dark.gif' height='10' width='"+(100-Math.round(pr1))+"'> loading";
		id.innerHTML =  "<div style='background-color:lightgrey; height:4px; width:"+(100-Math.round(pr1))+"px;'> loading "+(100-Math.round(pr1))+"</div>";
		}
	}
	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("mpl").loadFile(obj); };
function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
function removeItem(idx) { thisMovie("mpl").removeItem(idx); }
function getItemData(idx) {
	var obj = thisMovie("mpl").itemData(idx);
	var nodes = "";
	var itemstoprint = "";
for(var i in obj) {  
	if(i == "title") { titleToPrint = "<strong>"+obj[i]+"</strong>"; }
//	if(i == "author") { authorToPrint = obj[i]; } 
	if(i == "link") { linkToPrint = "<br/><a href='"+obj[i]+"'><img src='buynow.gif' border='0'></a>"; }
	if(i == "description") { descToPrint = obj[i]; }
	if(i == "image") { imageToPrint = obj[i]; }
 
	nodes = "NODES";
	nodes += "<li style='background-color:lightgrey; border-bottom:1px solid white;'>"+i+": "+obj[i]+"</li>"; 
	} 
	
	 

 //   document.getElementById("data").innerHTML = nodes; 
			document.getElementById("detailTitle").innerHTML = ""+titleToPrint;
			document.getElementById("detailDesc").innerHTML =""+descToPrint;
	//		document.getElementById("detailAuth").innerHTML =""+authorToPrint;
			document.getElementById("detailLink").innerHTML =""+linkToPrint;
 	// 		document.getElementById("detailImage").innerHTML ="<br /><strong>image:</strong> "+imageToPrint; 
};

// 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];
	}
};


 
// javascript function to copy the clipboard
function SelectAll(id)
{
	document.getElementById(id).focus();
	document.getElementById(id).select();
}