function LogFlash(str) {
  Mp3Player.LogFlash(str);
}

var Mp3Player = new function ()
{
  
  this.init = function(swf_file, playlist, div_target, options){
    this.volume = 0.5;
    this.flash_log = "Log of flash functions:´n";

    this.unibango = new Date().getTime();
    if (div_target){
    	this.id = div_target;
    	var target = document.getElementById(this.id);
 	 	target.id = this.id;
    }else{
	    this.id = "Mp3Player"+this.unibango;
	    var target = document.createElement('div')
	  	target.id = this.id;
	  	document.body.appendChild(target);
	}

    this.swfObject = new SWFObject(swf_file, this.id, 320, 180, "9", "#000000");
    this.swfObject.addVariable( "lcId", this.unibango );
    this.swfObject.addVariable( "volume", this.volume );
    if (playlist){
      if (typeof playlist != 'string'){
        playlist = playlist.join('|');
      }
      this.swfObject.addVariable( "playlist",playlist);
    }
//    this.swfObject.addVariable( "SONG_COMPLETE", "Mp3Player.OnSongComplete");
    if (options){
      for (var key in options)
      {
        this.swfObject.addVariable(key, options[key]);
      }
    }
    this.swfObject.write(this.id);
	
    this.currentSong = '';
    this.onComplete = null;
  }	
  this.flash = function()
  {
    var name = this.id;
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[name] : document[name];
  }
  this.OnSongComplete = function(e)
  {
    if (this.onComplete != null){
    	eval(''+this.onComplete+"();");
    }
  }
  this.Play = function (onFinish)
  {
    if (onFinish)
	    this.onComplete = onFinish;
	try {
	    var state = this.flash().Start();
	    this.currentSong = this.flash().GetTitle();
	}
	catch (e)
	{
	}
  }
  this.Pause = function(){
    this.flash().Pause();
  }
  this.Stop = function(){
    this.flash().Halt();
  }
  this.Eject = function() {
    this.flash().Eject();
  }		
  this.AddToPlaylist = function (mp3s){ 
    this.flash().AddToPlaylist(mp3s); 
  }
  this.Next = function(){
    this.flash().Next();
  }
  this.Prev = function(){
    this.flash().Prev();
  }
  this.VolumeUp = function(){
    this.volume += 0.1; 
    this.SetVolume(this.volume);
  }
  this.VolumeDown = function(){
    this.volume -= 0.1; 
    this.SetVolume(this.volume);
  }
  this.SetVolume = function (volume)
  {
    if (typeof volume == 'number'){
      this.volume = volume;
	  if (this.volume > 2.0)
	    this.volume = 2.0;
	  else if (this.volume < 0)
	    this.volume = 0;
	  this.flash().SetVolume(volume);
	}
  }
  this.SetShuffle = function (doShuffle){
    this.flash().SetShuffle(doShuffle?true:false);
  }
  this.SetRepeat = function (doRepeat){
    this.flash().SetRepeat(doRepeat?true:false);
  }
  this.GetPosition = function(){
    return this.flash().GetPosition();
  }
  this.LogFlash = function(str) {
    this.flash_log = this.flash_log + str + "´n";
  }
}