
function flashJsMp3Player(id){

		this.id = id;
		
		this.init = function(){
			this.element = document.getElementById(this.id);
			this.playListIndex = 0;

		}
		
		this.onInit = function(){
			
			this.position = 0;
	
		};
		this.onUpdate = function()
		{

			this.bytes = this.bytesLoaded + "/" + this.bytesTotal + " (" + this.bytesPercent + "%)";
			this.remaining = parseInt(((this.duration - this.position)/this.duration) * 100);
			this.completed = 100 - this.remaining;
			if(this.completed==100){
				this.next();		
			}
			if(this.onProgress){this.onProgress();}
		//		document.getElementById("playerslider").style.left = sliderPosition+"px";
		};


		this.play = function(){
			
			if(this.playListIndex==null){this.playListIndex=0;}
			this.playListURL = this.playList[this.playListIndex];
			
			if (!this.isPlaying) {
					this.element.SetVariable("method:setUrl", this.playListURL);	
			}
		
				this.element.SetVariable("method:play", "");	
				this.element.SetVariable("enabled", "true");
				this.isPlaying = true;
			
		}
		this.next = function (){
			this.stop();
			this.playListIndex++;
			if(this.playListIndex == this.playList.length){this.playListIndex=0;}
			this.play();
		}
		this.previous = function(){
			this.stop();
			this.playListIndex--;
			if(this.playListIndex < 0){this.playListIndex=this.playList.length-1;}
			this.play();
		}
		this.pause = function(){
			this.element.SetVariable("method:pause", "");
		}
		this.stop = function(){
			this.element.SetVariable("method:stop", "");
			this.element.SetVariable("method:setPosition", 0);
			this.isPlaying = false;
		}
		this.setPosition = function(position){
			this.element.SetVariable("method:setPosition", position);
		}
		this.setVolume = function(volume){
			this.element.SetVariable("method:setVolume", volume);
		}

		this.changeVolume =  function(e,obj){
			var v = this.volume;
			
			var coords = this.getClickCoordsWithinTarget(e);
			var positionRel = coords.x;
			var w = $(obj).innerWidth();
			// get div percentage
			var posP = parseInt(100 - (((w-positionRel)/w) * 100));
			this.setVolume(posP);
		}	

		this.changePosition = function(e,obj){

			var p = this.position;
			var d = this.duration;
			
			var coords = this.getClickCoordsWithinTarget(e);
			var positionRel = coords.x;
			var w = $(obj).innerWidth();
			// get div percentage
			var posP = 100 - (((w-positionRel)/w) * 100);
			var posF = parseInt(d * (posP/100));
			this.setPosition(posF);
		}	


		this.getClickCoordsWithinTarget = function(event){
		  var coords = { x: 0, y: 0};

		  if(!event) // then we're in a non-DOM (pro'ly IE) browser
		  {
			event = window.event;
			coords.x = event.offsetX;
			coords.y = event.offsetY;
		  }
		  else // we assume DOM modeled javascript
		  {
			var Element = event.target ;
			var CalculatedTotalOffsetLeft = 0;
			var CalculatedTotalOffsetTop = 0 ;

			while (Element.offsetParent)
			{
			  CalculatedTotalOffsetLeft += Element.offsetLeft;
			  CalculatedTotalOffsetTop += Element.offsetTop;
			  Element = Element.offsetParent ;
			}

			coords.x = event.pageX - CalculatedTotalOffsetLeft;
			coords.y = event.pageY - CalculatedTotalOffsetTop;
		  }

		  return coords;
		}

		return this;
}
