// 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="";
  var lastGlobalPathToFlash="";

	function writePlayer(id, mp3, pathToFlash, row){
		globalPathToFlash = pathToFlash;
		if(mp3.substr(0,7)!="http://"){
			mp3 = "http://"+mp3;
		}
		var bigPlayer = false;
		if(id.substr(0,9)=="playerBig"){
			bigPlayer = true;
		}
		
		// function to reset the last played player
			if(lastPlayedVarId!="" && lastPlayedVarMP3!="" && lastPlayedVarRow!="")
			{
				clearPlayer(lastPlayedVarId, lastPlayedVarMP3, lastPlayedVarRow);
			}
			lastPlayedVarId=id;
			lastPlayedVarMP3=mp3;
			lastPlayedVarRow=row;
			lastGlobalPathToFlash=pathToFlash;
	
		if(bigPlayer==true){
			var so = new SWFObject(pathToFlash+"player.swf?id=" + mp3 + "&context=" + id + "&row=" + row, 'embed' + id , "29", "30", "8", "#FFF");	
		}else{
			var so = new SWFObject(pathToFlash+"player.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 + "','"+ lastGlobalPathToFlash+"','" + row + "')";

    linknode.setAttribute('href', linktext);
    linknode.className = "flashLink";
    
    var image = document.createElement('img');
    image.setAttribute('src',lastGlobalPathToFlash+'/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);
  }
