// id is the id of the tag from which the script is called. The content of this tag will be replaced by the player
// mp3 is the id of the mp3 file
  
  var globalPathToFlash;
  
  var lastPlayedVarId="";
  var lastPlayedVarMP3="";
  var lastPlayedVarRow="";

	function writePlayer(id, mp3, pathToFlash, row){
		globalPathToFlash = pathToFlash;
		if(mp3.substr(0,7)!="http://"){
			mp3 = "http://"+mp3;
		}
		
		// function to reset the last played player
			if(lastPlayedVarId!="" && lastPlayedVarMP3!="" && lastPlayedVarRow!="")
			{
				clearPlayer(lastPlayedVarId, lastPlayedVarMP3, lastPlayedVarRow);
			}
			lastPlayedVarId=id;
			lastPlayedVarMP3=mp3;
			lastPlayedVarRow=row;
				
		var so = new SWFObject(pathToFlash+"player.swf?id=" + mp3 + "&context=" + id + "&row=" + row, 'embed' + id , "17", "16", "8", "#FFF");	
		//var so = new SWFObject(pathToFlash+"opPlayer2.2.swf?id=" + mp3 + "&context=" + id + "&row=" + row, 'embed' + id , "17", "16", "8", "#FFF");	
		so.addParam("allowScriptAccess", "always");
		so.write(id);
	}
	
  // id is the id of the tag which will be cleared and replaced by the initial link. Replace dummy.jpg and it's values by your standard Flash Player jpg 	
  // mp3 is the id of the mp3 file that will played from the cleared tag 
  function clearPlayer(id, mp3, row){
    var linknode = document.createElement('a');
    var linktext = "javascript:writePlayer('" + id + "','" + mp3 + "','"+ globalPathToFlash+"','" + row + "')";

    linknode.setAttribute('href', linktext);
    linknode.className = "flashLink";
    
    var image = document.createElement('img');
    image.setAttribute('src',globalPathToFlash+'/icon_play.png');
    image.setAttribute('alt', 'Flash');
    
    linknode.appendChild(image);
	
	var containerObject = document.getElementById(id);
	var replaceObject = document.getElementById(id).childNodes[0];
	
	containerObject.replaceChild(linknode, replaceObject);	
  }

  function alertString(str)
  {
	alert(str);
  }

