function loadXMLDoc(fname)
{
  var xmlDoc;
  // code for IE
  if (window.ActiveXObject)
  {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
  // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xmlDoc=document.implementation.createDocument("","",null);
   }
  else
  {
    alert('Your browser cannot handle this script');
  }
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

function displayResult()
{
if(!document.getElementById('tracklisting') || !document.getElementById('xslt')) return false;
if (window.ActiveXObject)
  {
xml=loadXMLDoc(document.getElementById('tracklisting').innerHTML);
xsl=loadXMLDoc(document.getElementById('xslt').innerHTML);
  }
  
else if (document.implementation
  && document.implementation.createDocument)  
 {
var xmlRequest = new XMLHttpRequest();
xmlRequest.open("GET", document.getElementById('tracklisting').innerHTML, false);
xmlRequest.send(null);
xml= xmlRequest.responseXML;

var xslRequest = new XMLHttpRequest();
xslRequest.open("GET", document.getElementById('xslt').innerHTML, false);
xslRequest.send(null);
xsl = xslRequest.responseXML;

 }



if (window.ActiveXObject)
  {
    ex=xml.transformNode(xsl);
    document.getElementById("example").innerHTML=ex;
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

  }
  // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
    document.getElementById("example").appendChild(resultDocument);
  }
  $("#example").css("height","auto");//this resets the height which was needed for the ajax loader gif positioning
  //set the play button image src's
  generateLocations();
  $("td.musicplayer img").attr("src",venda_entmediaadd + "/ebiz/" + venda_bsref + "/resources/images/playmp3.gif"); 
}



function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(displayResult);

addLoadEvent(mediaPlayerInit);


var mp3PlayButton;
var mp3StopButton;
var currentTrack = -1;
function mediaPlayerInit() {
					generateLocations();
					mp3PlayButton = venda_entmediaadd + "/ebiz/" + venda_bsref + "/resources/images/playmp3.gif";
					mp3StopButton = venda_entmediaadd + "/ebiz/" + venda_bsref + "/resources/images/pausemp3.gif";
					var streamURL;
					
					/*if ($("table.albumTable").length > 0){
						//download
						streamURL = "rtmp://llsalestr.fcod.llnwd.net/a711/o16/jan/";
						
					}else{*/
						var loc = $(".musicplayer a").attr("class")+"";
						streamURL = loc.substring(0,loc.indexOf("/audio_clip"))
						
					//}
					
					embedEncoder(streamURL);
					
					if ($("table.albumTable").length > 0){
						//download
						$("#player").css({"position":"relative","z-index":"0","top":"95px", "left":"10px"});
						//$(".addbuybutton").css({"position":"relative","z-index":"0"});
						
					}else{
						$("#player").css({"position":"relative","z-index":"0","top":"10px","left":" 10px"});
						//$(".addbuybutton").css({"position":"relative","z-index":"0"});
						
					}
	
					$(".musicplayer a").click(function(e){
											
									 var index = $(".musicplayer").index( $(this).parent());
									 
									 

												var player = document.getElementById("player");
												if ($(this).find("img").attr("src")==mp3PlayButton){
													
													//this file isn't being played
													
													//parse file to play
													var loc = $(this).attr("class")+"";
												
													/*if ($("table.albumTable").length == 0){
														//download*/
														loc = loc.substring(loc.indexOf("/audio_clip") , loc.length );
												//	}
												//	alert(loc);
													if (currentTrack!=index){
														player.sendEvent("LOAD",loc);
														currentTrack = index
													}
													player.sendEvent("PLAY",true);
													$(".musicplayer img").attr("src",mp3PlayButton);
													$(this).find("img").attr("src",mp3StopButton);
													$(this).attr("title","Pause track");
												}else{
													//this file is already being played, need to pause it
				
													
													currentTrack =index;
													//player.sendEvent("LOAD",$(this).attr("class"));
													player.sendEvent("PLAY",false);
													$(this).find("img").attr("src",mp3PlayButton);		
													$(this).attr("title","Play track");
												}
					});						  
}/**/	
function embedEncoder (streamURL){
	
	var flashvars = {
		  streamer: streamURL,
		  controlbar: "none"
		};
		var params = {
		  allowfullscreen: "true",
		  allowscriptaccess: "always",
		  wmode: "opaque"
		};		
	var attributes = {
		id: "player",
		name:"player"
	  };		  
	swfobject.embedSWF(venda_entmediaadd + "/ebiz/" + venda_bsref + "/resources/tracklisting/player.swf", "player-container", "20", "20", "9.0.0",venda_entmediaadd + "/ebiz/" + venda_bsref + "/resources/tracklisting/expressInstall.swf", flashvars, params,attributes);
}
var venda_entmediaadd;
var venda_bsref;
function generateLocations(){
	
	 venda_entmediaadd = $(".pause-button").attr("name");
	 venda_bsref = $(".pause-button").attr("alt");
	
}
