/***
*
*  Controls for Audio and Video  
*
***/
var MediaList = new Class({
        scrubState: null, 
        //
		//  initialize
		//
		Implements: [Options,Events,EventManager],
        options: {
				line_class:"list_line",
				name_class:"list_name",
				artist_class:"list_artist",
				year_class:"list_year",
				album_class:"list_album",
				current_color:"#069",
				over_color:"#333",
				normal_color:"#000"
        },
        initialize: function(container,player,include,options){
                this.setOptions(options)
				this.player = player
				this.include = include
				this.container = document.id(container)
				this.container.empty()
				this.lines = [] 
				this.player.playlist.each(this.addmedia.bind(this))
				this.pushEvents(this.player,"TRACK_LOADED",function(){
						this.setcurrent()
				}.bind(this))
				this.setcurrent()
		},
        //
        //  setup
        //
		addmedia: function(elm,id){
				var line = new Element("div",{"class":this.options.line_class})
				line.setStyles({
						cursor:"pointer",
						"background-color":this.options.normal_color
				})
				this.include.each(function(typ){
						var span = new Element("span",{"class":this.options[typ+"_class"]})
						span.set("html",elm[typ])
						line.grab(span)
				}.bind(this))
				this.pushEvents(line,"mouseover",function(){
						line.setStyle("background-color",this.options.over_color)
				}.bind(this))
				this.pushEvents(line,"mouseout",function(){
						var clr = this.player.index == id ? this.options.current_color : this.options.normal_color
						line.setStyle("background-color",clr)
				}.bind(this))
				this.pushEvents(line,"click",function(){
						this.player.loadTrack(id)
						this.player.play()
				}.bind(this))
				this.lines.push(line)
				this.container.grab(line)
		},
		setcurrent: function(){
				if (this.currentLine) this.currentLine.setStyle("background-color",this.options.normal_color)
				this.currentLine = this.lines[this.player.index]
				this.currentLine.setStyle("background-color",this.options.current_color)
		}
		
});
