
	var musicPlayer = Class.create({
		initialize:function(container){
			this.instID = 'musicPlayer_' + parseInt(Math.random()*1000000);
			this.options = 	{
					width : 1,
					height : 1,
					autostart : false,
					fullscreen : false,
					controlbar : "bottom",
					stretching : "fill"
			}
			this.container = $(container);
			this.path = "/upload/tracks/";
			this.isPlaying = '';
		},

		play : function(elem, file){
			if (this.isPlaying == file){
				this.player.sendEvent("PLAY", false);
				this.isPlaying = '';
				return false;
			}
			var uri = this.path + file + '.mp3';
			this.player.sendEvent("LOAD", uri);
			this.player.sendEvent("PLAY", true);
			this.isPlaying = file;
			return true;
		},

		drawPlayer : function(){
			var playerContainer = new Element('div', {id:this.instID+"_player", name:this.instID+"_player", className:'player'});
			this.container.insert(playerContainer);
			
			var flashvars = this.options;
			flashvars.playerready = playerReady;

			var params = { allowfullscreen:'true', allowscriptaccess:'always', wmode:"transparent"};
			var attributes = { id:this.instID+"_player", name:this.instID+"_player"};
			swfobject.embedSWF("/js/3rd/jwplayer/player4.swf", this.instID+"_player", this.options.width, this.options.height, "9.0.0", '/js/3rd/jwplayer/expressInstall.swf', flashvars, params, attributes);
			$(this.instID+"_player").srcObj = this;
			
			setTimeout(
				(function(){
					$(this.instID+"_player").srcObj = this;
				}).bind(this),
				500
			)
		},
		
		playerTimeCallback : function(position, duration){
			this.currTime = position;
			this.duration = duration;
		}

		
	})
		
	function playerReady(obj) {
		player = document.getElementById(obj.id);
		if (!player.srcObj){
			setTimeout(
					function(){
						playerReady(obj);
					},
					500
			);
			return;
		}
		player.srcObj.player = player;
		player.addModelListener("TIME", "playerTime");
	}
	
	function playerTime(obj){
		player = document.getElementById(obj.id);
		if (!player.srcObj){
			setTimeout(
					function(){
						playerTime(obj);
					},
					500
			);
			return;
		}		
		player.srcObj.player = player;
		player.srcObj.playerTimeCallback(obj.position, obj.duration);
	}	
