// some variables to save
var currentPosition;
var currentRemaining;
var currentVolume;
var currentItem;
var currentState;
var currentLoad;
var currentXsize;
var currentYsize;
var currentFile;
var prevFile;

function setTracking(videoName){
	videoName = extractVideoName(videoName);
	videoName = videoName.replace(" ", "+");
//alert("movie " + videoName + " is being loaded, can tag here (line 17, mediaplayer.js)");// we're loading the movie
	_hbPageView("/photography_masterclasses","/Solutions/duracellrecharge/" + videoName);
}


// this function is caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };

function extractVideoName(fileName){
	var tmp = fileName.split("/");
	if (tmp.length > 0){
		return(tmp[tmp.length-1]);
	}else{
		return fileName;
	}
	
}


// these functions is called by the JavascriptView object of the player.
function getUpdate(typ,pr1,pr2,swf) {
	//alert("updating");
	if(typ == "time") { currentPosition = pr1; pr2 == undefined ? null: currentRemaining = Math.round(pr2); }
	else if(typ == "volume") { currentVolume = pr1; } 
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100);}
	else if(typ == "state") { currentState = pr1; }
	else if(typ == "load") { currentLoad = pr1; }
	else if(typ == "size") { currentXsize = "X=" + pr1; pr2 == undefined ? null: currentYsize = "Y=" + Math.round(pr2); } 
	
	if (currentState == 2 && (prevFile != currentFile)){ //defaults the start to video 2
	//document.getElementById("video-heading").innerHTML = itemData("mpl", currentItem); 
		prevFile = currentFile;
		setTracking(currentFile);
		alert(currentNumber);
	}
};

function getItemData(idx) {
	
	var obj = thisMovie("mpl").itemData(idx);
	currentFile = obj["file"];
};
//function getItemData(idx) {
	//var obj = thisMovie("mpl").itemData(idx);
//	document.getElementById("video-heading").innerHTML = obj["title"]; 
//}


// 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 getLength(swf) { return(thisMovie(swf).getLength()); };


// 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 xmlhttp;
var xmlDoc;

function loadXMLDoc(theFile) {
  xmlhttp=null;
  if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } 
  else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

  if (xmlhttp!=null) {
    xmlhttp.onreadystatechange=loaded;
    xmlhttp.open("GET",theFile,true);
    xmlhttp.send(null);
  } else { alert('Sorry, your browser can\'t handle this script'); return; }
}

function checkReadyState(obj) {
  if(obj.readyState == 4) {
    if(obj.status == 200) { return true; }
    else { alert("Problem retrieving XML data"); }
  }
}

function loaded() {	
  if(checkReadyState(xmlhttp)) {
    xmlDoc=xmlhttp.responseXML.documentElement;
    showTags('track','player-panel');
    createPlayer(Urls[0], Imgs[0], false, true);
  }
}


var Urls = new Array();
var Imgs = new Array();

function showTags(theTag,thePlace) {

  function getTag(tag) { 
    var tmp='';
    xx=x[i].getElementsByTagName(tag);     
    try { tmp=xx[0].firstChild.data; } 
    catch(er) { tmp=''; }    
    return(tmp); 
  }

  var xx; var x; var txt; 
  x = xmlDoc.getElementsByTagName(theTag);
  txt='<table border="0" cellPadding="2" width="210">'; 
  txtheading='getTag("title")';

  for (i=0; i<x.length; i++) { 
    Urls[i]=getTag("location"); Imgs[i]=getTag("image");  //getTag("title"); getTag("creator"); getTag("info");

    txt+='<tr><td><table width="333" onclick="play('+i+')" class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';"><tr>';
    txt+='<td><img src="'+getTag("image")+'" width="125" height="70" border="0" alt="Click to Play"></td><td width="200" valign=top>';
    txt+='<p><br>&nbsp;<b>'+getTag("title")+'</b><br>';
    txt+='&nbsp; '+getTag("creator")+'...<br>';
    txt+='</td></tr></table></td></tr>';
  }
  txt+="</table>";

  document.getElementById(thePlace).innerHTML=txt; 
  
}

function createPlayer(theFile, theImg, start, icons){
	var so = new SWFObject('flash/mediaplayer.swf','mpl','382','265','8');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addVariable("autostart","false");
	so.addVariable('height','265');
	so.addVariable('width','382');	
//so.addVariable("file", "mediaplayer.xml");
	so.addVariable("file", theFile);
	so.addVariable('backcolor','0x383838');
	so.addVariable('frontcolor','0xFFFFFF');
	so.addVariable('lightcolor','0xFFFFFF');
	so.addVariable('screencolor','0x000000');
	so.addVariable("enablejs","true");
	so.addVariable("javascriptid","mpl");
	so.addVariable("volume","100");
	//so.addVariable('displayheight','240');
	so.addVariable('showdigits','false');
	so.addVariable('usefullscreen','false');
	so.addVariable('autoscroll','true');
	if (start) so.addVariable("autostart", "true");
	if (! icons) so.addVariable("showicons", "false");
	if (theImg != "") so.addVariable("image", theImg);
	so.write('player');
}
function play(number) { 
  createPlayer(Urls[number], Imgs[number], true, true);
}

