
	// some variables to save
	var currentPosition = 0;
	var currentContent = new Array();
	currentContent['url'] = 1231231;
	currentContent['loaded'] = null;
	var currentVolume;
	var currentItem;
	var controlFile;
	var temp = null;

	var tagsArray = new Array();

	var player;

	function playerReady(obj) {
		var id = obj['id'];
		var version = obj['version'];
		var client = obj['client'];
		player = document.getElementById(id);

		player.addModelListener("TIME","videoTimer");
		//player.addModelListener("STATE","contentLoader");
		//player.addViewListener("LOAD","contentLoader");
		player.addControllerListener("ITEM","contentLoader");
	};




	/**
	 *
	 * @access public
	 * @return void
	 **/
	function contentLoader(obj){
			controlFile = 'metafiles.php?id='+player.getPlaylist()[obj['index']].author;
			tagsArray = new Array();
			parse_control_file(controlFile);
	}

	/**
	 *
	 * @access public
	 * @return void
	 **/
	function videoTimer(obj){
			currentPosition = obj['position'];
			currentContent['loaded'] = null;
			tagsArray.map(showContent);
	}

	// these functions are caught by the JavascriptView object of the player.
	/**
	 *
	 * @access public
	 * @return void
	 **/
	function showContent(el, i, ar){

		if (currentPosition>(el['begin']-1) && currentContent['url'] != el['url'] && currentContent['loaded']==null) {
			//(currentPosition<=tagsArray[(i+1)]['begin'] || !tagsArray[(i+1)]) &&
			if (tagsArray.length>=(i+1)) {
				if ((currentPosition<tagsArray[(i+1)]['begin'])) {
					f('metafiles.php?task=content&data='+el['url'], 'controlContent');
					currentContent['url'] = el['url'];
					currentContent['loaded'] = 1;
				}
			}
		}
	}



	function sendEvent(typ,prm) { player.sendEvent(typ,prm); };

	function getUpdate(typ,pr1,pr2) {
		if(typ == "time") {
			currentPosition = pr1;
			currentContent['loaded'] = null;
			tagsArray.map(test1);
		}
		else if(typ == "volume") { currentVolume = pr1; }
		else if(typ == "item") {
			getItemData(pr1);
			tagsArray = new Array();
			parse_control_file(controlFile);
		}
		else if (typ == "load") {
			//if (pr == 1) {}
			//if (pr == 100) {}
		}else if (typ == "state") {

		}
	}


/**
 *
 * @access public
 * @return void
 **/
var http;
http = null;
function parse_control_file(filename){

	if (window.XMLHttpRequest) {
	   http = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	   http = new ActiveXObject("Microsoft.XMLHTTP");
	}
 if (http != null) {
    http.open("GET", filename, true);
    http.onreadystatechange = handleResponse;
    http.send(null);
 }
}

function handleResponse() {
		if(http.readyState == 4){
			parse_now(http.responseText)
		}
}

/**
 *
 * @access public
 * @return void
 **/
//var data = false;
function parse_now(data){
		if (data) {
				//data =  http.responseText;
				//http = null;
				var xml;
				var k=0;
				  if (window.ActiveXObject) {
		         xml = new ActiveXObject("Microsoft.XMLDOM");
		         xml.loadXML(data);
		      } else if (document.implementation) {
		         xml = (new DOMParser()).parseFromString(data, "text/xml");
		      }

				var tags = xml.getElementsByTagName("loadtag");
	      for (var i = 0; i < tags.length; i++) {
	         var begin, targeturl;
	         var datum = tags[i];
	         for (var j = 0; j < datum.childNodes.length; j++) {
						  with (datum.childNodes[j]) {
								 if (nodeName == "url") {
										tagsArray[k] = new Array();
										tagsArray[k]['url'] = firstChild.nodeValue;
										//targeturl = firstChild.nodeValue;
	               } else if (nodeName == "begin") {
	               		tagsArray[k]['begin'] = firstChild.nodeValue;
								 		k++;
										 //begin = firstChild.nodeValue;
										//tagsArray[begin] = new Array();
	               		//tagsArray[begin]['begin'] = targeturl;
	               } else if (nodeName == "end") {
										//tagsArray[begin]['end'] = firstChild.nodeValue;
								 }

							}

					 }

				}
		}
	tagsArray[k] = new Array();
	tagsArray[k]['begin'] = 99999;
	tagsArray[k]['url'] = 99999;
	xml = null;
	tags = null;
	datum = null;
	return true;
}



// 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 boxload(url, caption, width, height){
			if (!height) height="500";
			if (!width) width="500";
			MOOdalBox.open(
				url,
				caption,
				width + " " + height
			);
		}
