AXPositionBar = function(divId)
{
	this.positionBar = findObj(divId);
	this.timeTxt = findObj('time');
	this.playStateTxt = findObj('playstate');
	this.positionArrow = findObj('arrow');
	this.bufferDiv = findObj('buffer');
	this.positionDiv = findObj('position');
	
	this.duration = 0;
	this.durationText = "";
	this.position = -1;
	this.playState = 0;
	this.bufferProgress = "0%";
	//events
	this.positionChange = null;
	
	this.mouseDown = function mouseDown(e){
    if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };

		e = (e) ? e : window.event;
		if (typeof e.offsetX != 'undefined')
			var x = e.offsetX;
		else if (typeof e.pageX != 'undefined')
			var x = e.pageX - this.positionBar.offsetLeft;
	 	if(x > this.positionBar.clientWidth) x = this.positionBar.clientWidth;
	 	var pos = this.duration*(x/this.positionBar.clientWidth);
	 	
	 	//fire event
	 	if(this.positionChange != null)
		{
			this.positionChange(pos);
		}
  };
	
	this.mouseDown._oScope = this;
	
	if(EventManager != null){
		EventManager.Add(findObj('position-bar'), 'mouseover', this.mouseRollOver);
		EventManager.Add(findObj('position-bar'), 'mouseout', this.mouseRollOut);
		EventManager.Add(findObj('position-bar'), 'mousedown', this.mouseDown);
	}
	
	this.bufferDiv.style.width = "0%";
	this.positionDiv.style.visibility = "hidden";
	this.positionDiv.style.width = "0%";
	this.positionDiv.style.visibility = "hidden";
	this.timeTxt.innerHTML = "";
	this.timeTxt.style.visibility = "hidden";
}
AXPositionBar.prototype.setBuffering = function(p)
{
	if(p >= 0)
	{
		if(p >= 100)
		{ 
			p = "100%";
		}
		else
		{
			 p = p+"%";
		}
	}
	else
	{
		p = "0%";
	}
	this.bufferProgress = p;
	this.bufferDiv.style.width = p;
	this.bufferDiv.style.visibility = "visible";
}
AXPositionBar.prototype.setDownloadProgress = function(p)
{
	if(p >= 0)
	{
		if(p >= 100)
		{ 
			p = "100%";
		}
		else
		{
			 p = p+"%";
		}
	}
	else
	{
		p = "0%";
	}
	this.bufferProgress = p;
	this.bufferDiv.style.width = p;
	this.bufferDiv.style.visibility = "visible";
}
AXPositionBar.prototype.setDuration = function(sec)
{
	if(sec > -1)
	{
		this.duration = sec;
		this.durationText = this.toTime(sec);
		this.timeTxt.style.visibility = "visible";
		this.positionDiv.style.width = "0%";
		this.positionDiv.style.visibility = "visible";
		this.positionArrow.style.left = "0%";
	}
	else
	{
		this.durationText = "";
	}
}
AXPositionBar.prototype.setPosition = function(sec)
{
	if(sec >= 0 && this.position != sec)
	{
		this.position = this.toTime(sec);
		if(this.durationText != "")
		{
			this.timeTxt.innerHTML = this.position + " / " + this.durationText;
		}
		else
		{
			this.timeTxt.innerHTML = this.position;
		}
		
		
		var x = (this.duration > 0) ? 100*(sec/this.duration):0;
		this.positionDiv.style.width = x+"%";
		
		this.positionArrow.style.left = x-2+"%";
		//this.timeTxt.blur();
	 	//this.playStateTxt.blur();
	}
}
AXPositionBar.prototype.setPlayState = function(state)
{
	var playStateTxt = "Stopped";
	switch(state)
	{
		case 1://stopped
		{
			playStateTxt = "Press play to start webcast";
			break;
		}
		case 2://pause
		{
			playStateTxt = "Paused";
			break;
		}
		case 3://playing
		{
			playStateTxt = "Playing";
			break;
		}
		case 6://buffering
		{
			playStateTxt = "Buffering "+this.bufferProgress;
			break;
		}
		case 9://transitioning
		{
			playStateTxt = "Connecting";
			break;
		}
		case 10://ready
		{
			playStateTxt = "Press play to start webcast";
			break;
		}
		case 11://download progress
		{
			
			break;
		}
	}
	if(state == 2 || state == 3)
	{
		this.timeTxt.style.visibility = "visible";
		this.positionDiv.style.visibility = "visible";
		if(this.playState == 6)
		{
			this.bufferDiv.style.visibility = "hidden";
		}
		if(isLive != null && isLive)
		{
			playStateTxt = "Live webcast";
			if(this.positionArrow != null)
			{
				this.positionArrow.style.display = "none";
			}
		}
	}
	else
	{
		this.timeTxt.style.visibility = "hidden";
		this.positionDiv.style.visibility = "hidden";
	}
	this.playState = state;
	this.playStateTxt.innerHTML = playStateTxt;
}
AXPositionBar.prototype.mouseRollOver = function()
{
	var o = findObj('arrow');
	o.style.visibility = "visible";
}
AXPositionBar.prototype.mouseRollOut = function()
{
	var o = findObj('arrow');
	o.style.visibility = "hidden";
}
AXPositionBar.prototype.toTime = function(s)
{
	if(s == 0)
	{
		return "00:00";
	}
	var h = Math.floor(s/3600);
	if(h > 0)
	{
		s = s - h*3600;
	}
	var min = Math.floor(s/60);
	if(min < 10)
	{
		min = "0" + min;
	}
	var sec = s - min * 60;
	if(sec < 10)
	{
		sec = "0" + sec;
	}
	sec = sec.toString();
	sec = (sec.length > 2)?sec.substring(0,2):sec;
	
	var time;
	if(h > 0)
	{
		time = h + ":" + min + ":" + sec;
	}
	else
	{
		time = min + ":" + sec;
	}
	return time;
}