function Player(args) {
  if (args != null) {
    var arg
    this.media = []
    this.video = false
    this.repeat = false
    this.thumbnail_src = ""
    this.thumbnail_background_src = ""
    for (arg in args) {
      this[arg]=args[arg]
    }
    this.currentIndex = -1
    this.initialized = false
    Player._players[this.id]=this
  }
}
Player._players={}
Player.prototype._setSongSrc = function() {
  frames[this.id].setSongSrc(this.media[this.currentIndex].src)
}
Player.prototype._getContents = function() {
  var qs=""
  if (this.media.length > 1) {
    qs = qs + "&next_song_function=" + escape("parent.Player.getPlayer('" + this.id + "').nextSong")
  }
  if (this.media.length > 0) {
    if (this.currentIndex == -1) {
      this.setCurrentIndex(0,true)
    }
    qs = qs + "&song_src=" + this.media[this.currentIndex].src
  }
  if ("has_stop_button" in this) {
    qs = qs + "&has_stop_button=" + (this.has_stop_button  ? '1' : '0')
  }
  if ("has_progessbar" in this) {
    qs = qs + "&has_progess_bar=" + (this.has_progress_bar ? '1' : '0')
  }
  if ("repeat" in this) {
    qs = qs + "&repeat=" + (this.repeat ? '1' : '0')
  }
  if ("repeat_delay" in this) {
    qs = qs + "&repeat_delay=" + (this.repeat_delay)
  }
  if ("bgcolor" in this) {
    qs = qs + "&bgcolor=" + this.bgcolor.replace("#","0x")
  }
  return (
    "<div style='margin:0px;padding:0px;border-width:0px'>" +
    "<iframe frameBorder='0' name='" + this.id + 
    "' id='" + this.id + "' style='border:0 none;" +
    "padding:0px;margin:0px;overflow:fixed;" +
    (this.width ? "width:" + this.width + "px;" : "") +
    (this.height ? "height:" + this.height + "px;" : "") +  
    "' src='/images/main/" + window.location.hostname.replace(/(\.exp)?\.local/,'') + "/flash/" +
     (this.video ? "vplayer" : "player") +  
    ".lzx.html?"  + qs +  "'  >" + 
    "</iframe></div>"
  );
}
Player.prototype.setContents = function(elt) {
  elt.innerHTML = ""
  this.container = elt
  elt.innerHTML = (this.thumbnail_src=='')
                ? this._getContents() : this._getThumbnail()
}
Player.prototype.play = function() {
  this.initialized = true
  this.container.innerHTML = ""
  this.container.innerHTML = this._getContents()
}
Player.prototype._getThumbnail = function(elt) {
  
  return (     
    "<div class='" + (this.video ? "v" : "") +  
    "player_thumbnail' align='center' style='margin:0px;padding:0px;" +
    (this.width ? "width:" + this.width + "px;" : "") +
    (this.height ? "height:" + this.height + "px;" : "") +
    (this.thumbnail_background_src 
     ? ('background-image: url("' + this.thumbnail_background_src + 
       '");')
     : "") +
    "' onclick=\"Player._players['" + 
    this.id + "'].play();return false\"" +
    "><img src='" + this.thumbnail_src + 
    "'align='center' border='0'/></div>")
}
Player.prototype.nextSong = function() {
  var idx = this.currentIndex + 1
  if (idx >= this.media.length) {
    if (this.repeat) {
      idx = 0
    } else {
      return
    }
  }
  this.setCurrentIndex(idx) 
}
Player.prototype.setCurrentIndex = function(idx, no_set) {
  this.currentIndex = idx
  if (no_set == null) {
    no_set = false
   }
  if ((idx != -1) && !no_set) {
    if (this.initialized) {
      this._setSongSrc()
    } else {
      this.play()
    }
  }
}
Player.getPlayer = function(id) {
  return Player._players[id]
}