/////////// Script para el reproductor de video /////////////////////////////
/////////// Lee XML y arma el menu debajo del Reproductor ///////////////////


		
		function importXML(theFile, ancho, largo, theImage, flag) {
			if (theFile.indexOf('xml')!= -1){ // si lo que viene dentro de theFile no es una playlist evita el AJAX y solo llama al Player
				xmlDoc = null; 
				xmlHttp = null; 	
				file = theFile;
				initPlayer(theFile,ancho,largo); // llamada al reproductor desde acá y sigo con AJAX
			
				if ((flag)
				||(theFile.substring(0,4).toLowerCase() == "http")
				||(location.protocol.substring(0,4).toLowerCase() == "http")) { 
					httpFlag = true;
					httpXMLDoc(theFile); 
				} else { 
					httpFlag = false;
					loadXMLDoc(theFile); 
				}
			} else {
			createPlayer(theFile,ancho,largo,theImage); // llamada al reproductor desde acá y salgo de la funcion de AJAX
			}
		}
		

		
		function loadXMLDoc(file) { if (debug()) { alert("xmlDoc.load: "+file); }
			if ((document.implementation)&&(document.implementation.createDocument)) { 
				xmlDoc = document.implementation.createDocument("", "", null);  
				xmlDoc.onload = loaded;	
			} else if (window.ActiveXObject) { 
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
				xmlDoc.onreadystatechange = loadStat; 
			} 
		
			if (xmlDoc != null) {xmlDoc.load(file);} 
			else if (! stealth) { alert(msg1); return; } 
		}
		
		
		function loadStat() { if (xmlDoc.readyState == 4) loaded(); }
		
		
		function httpXMLDoc(file) {
			if (window.XMLHttpRequest) { 
				xmlHttp = new XMLHttpRequest(); 
			} else if (window.ActiveXObject) { 
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
		
			if (xmlHttp != null) {
				xmlHttp.onreadystatechange = getStat;
				xmlHttp.open("GET", file, true);
				xmlHttp.send(null);
			} else if (! stealth) { alert(msg1); return; } 
		}
		
		
		function getStat() { if(checkReadyState(xmlHttp)) { xmlDoc = xmlHttp.responseXML.documentElement; loaded(); } }
		
		
		function checkReadyState(obj) { 
			if(obj.readyState == 4) {
				if(obj.status == 200) { return true; } 
				else { if (! stealth) { alert(msg2); } return; }
			} 
		}


		function loaded() {	
		  showTags('track','writeroot');
		};


		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="0" cellspacing="0" width="100%">'; 
	
		  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 border="0" cellPadding="3" cellspacing="1" width="100%"><tr>';
			txt+='<td width="31%" valign="top"><a href="javascript:loadNplay('+i+')"><img src="'+getTag("image")+'" width="80px" height="61px" border="0" alt="Click para ver el video"></a></td><td width="69%" valign=top>';
			//txt+='<p><b>'+getTag("title")+'</b><br></p>';
			txt+='<strong>'+getTag("creator")+'</strong><br>';
			txt+=getTag("title")+'';
			txt+='</td></tr><tr><td height="7" colspan="2" valign="top"><img src="imagenes/tranpic.gif" width="1" height="1" /></td></tr></table></td></tr>';
		  }
		  txt+="</table>";
	
		  document.getElementById(thePlace).innerHTML=txt; 
		};
	
// específico para API  V.4 del reproductor-----

// ------------------------------------
		function playerReady(obj)
		{
		player = gid(obj.id);
		//shufflePlaylist();
		displayFirstItem();
		};
// ------------------------------------
		function itemMonitor(obj)
		{
		gid('titulete').innerHTML = '<span>' + player.getPlaylist()[obj.index].title + '</span>';
		gid('theAutor').innerHTML = '<span>(' + player.getPlaylist()[obj.index].author + ')</span>';
		gid('theCaption').innerHTML = '<span>' + player.getPlaylist()[obj.index].description + '</span>';
		//gid('duration').innerHTML = '<span>' + player.getPlaylist()[obj.index].duration + ' segs.</span>';
		};
// ------------------------------------
		function displayFirstItem()
		{
		if(player.getPlaylist())
		{
		  //itemMonitor({index:0});
		  itemMonitor({index:player.getConfig()['item']}); // por si está el shuffle en true o false, funciona igual
		  player.addControllerListener('ITEM', 'itemMonitor');
		}
		else
		{
		  setTimeout("displayFirstItem()",100);
		}
		};
// ------------------------------------
		function gid(name)
		{
		return document.getElementById(name);
		};
// ------------------------------------
		function loadNplay(idx)
		{
		player.sendEvent('ITEM', idx);
		//setTimeout("player.sendEvent('PLAY', 'true')", 100);
		};

// fin update para V.4 -----------------------------

	
          ///////////////////////// reproductor /////////////////////////

function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}
 
 
function createPlayer(theFile, ancho, largo, theImage) {


        var flashvars = {
                file:theFile,
				image:theImage,
                autostart:"false",
				skin: "/multimedia/skins/stylish_slim.swf",
				displayclick:"true",
				controlbar:"bottom",
				shuffle:"true",
				stretching:"fill",
				icons:"true"
        }
        var params = {
                allowfullscreen:"true",
                allowscriptaccess:"always",
				wmode:"opaque"
        }
        var attributes = {
                id:'mpl',
                name:'mpl'
        }
        swfobject.embedSWF("/multimedia/player.swf", "player", ancho, largo, "9.0.115", false, flashvars, params, attributes);
}
  
function initPlayer(theFile, ancho, largo) { 
        deletePlayer('wrapper', 'player', 'mpl'); 
        createPlayer(theFile, ancho, largo);
}


// fin reproductor V4.5 -----------------------------
