AXController = function(topicsId)
{
	this.topicsULId = topicsId != null ? topicsId : "topics";
	this.currentPosition = -1;
	this.topics = new Array();
	this.currentTopic = null;
	this.topicsUL = findObj('topics');
	this.duration = 0;
	this.xmlDoc = null;
	//Events
	this.topicChange = null;
	this.topicPositionChange = null;
	
	//Methods
	this.init = function()
	{
		try
		{
			if(!isLive)
			{
				this.getTopics2(this.topicsULId);
			}
			else
			{
				if(this.topicsUL != null)
				{
					this.topicsUL.style.display = "none";
				}	
			}
		}
		catch(e)
		{
		}
	};
	
	this.getTopics2 = function(id)
	{
		var o = document.getElementById(id);
		if(o != null && o.nodeName == "UL")
		{
			var links = o.getElementsByTagName('a');
			for (var i=0;i<links.length;i++)
			{
				if(links[i].name != "")
				{
					var x = links[i].name;
					if(x.indexOf(";") != -1)
					{
						x = x.split(";");
						this.addTopic(parseInt(x[0]), links[i].innerHTML, i, links[i], x[1]);
					}
					else
					{
						this.addTopic(parseInt(x), links[i].innerHTML, i, links[i], "");
					}
				}
				if(EventManager != null)
				{
					EventManager.Add(links[i],'click',this.selectTopic);
				}
			}
		}
	};
	
	this.addTopic = function addTopic(beginTime, text, slideId, linkObj, imageUrl)
	{
		var o = new Object();
		o.id = slideId;
		o.text = text;
		o.beginTime = Number(beginTime);
		o.imageUrl = imageUrl;
		o.linkObj = linkObj;
		this.topics.push(o);
	};
	
	this.selectTopic = function selectTopic(e)
	{
		if(this != arguments.callee._oScope){
			return arguments.callee.apply(arguments.callee._oScope, arguments);
		};
		
		var selectedTopic = null;
		if(typeof(e) != "number")
		{
			var obj = null;
			if (e.target){obj = e.target;}
			else if (e.srcElement){obj = e.srcElement;}
			if(obj != null && obj.id != null){
				//get topic id
				for(var i=0; i<this.topics.length; i++)
				{
					if(this.topics[i].linkObj == obj)
					{
						selectedTopic = i;
						break;
					}
				}
			}
		}
		else
		{
			selectedTopic = e;
		}
		
		var selectId = null;//old selection show?
		
		if(selectedTopic >= 0 && selectedTopic < this.topics.length)
		{
			for (var i=0;i<this.topics.length;i++)
			{
				if(i == selectedTopic)
				{
					if(this.topics[i].linkObj.parentNode.style.display == "none")
					{
						//dont hide current selected
						selectId = this.currentTopic.id;
					}
					this.topics[i].linkObj.parentNode.className = "topic-selected";					
					this.currentTopic = this.topics[i];
					
					if(this.currentTopic != null)
					{
						if(this.topics.length > i+1)
						{
							this.currentTopic.duration = this.topics[i+1].beginTime-this.topics[i].beginTime;
						}
						else
						{
							this.currentTopic.duration = this.duration-this.topics[i].beginTime;
						}
					}	
				}
				else if(this.topics[i].linkObj != null)
				{
					this.topics[i].linkObj.parentNode.className = "topic";
				}
			}
			
			//show old link
			if(selectId != null)
			{
				this.topics[selectId].linkObj.parentNode.className = "topic-selected";	
			}
			
			//fire event
			if(this.topicChange != null) 
			{
				this.topicChange(this.currentTopic);
			}
		}
	};
	
	this.selectTopic._oScope = this;
	
	this.getTopics = function()
	{
		//get topics data from menu
		var ul = this.topicsUL;
		if (ul != null && ul.childNodes || ul.childNodes.length > 0)
		{
			for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
				var item = ul.childNodes[itemi];
				if(item != null && item.nodeName == "LI")
				{
					var a = item.getElementsByTagName('a')[0];
					if (a != null) {
						var s = null;
						if(a.id != null)
						{
							var o = new Object();
							//innerHTML for ff
							o.id = this.topics.length;
							o.text = a.innerHTML;
							o.beginTime = parseInt(a.id);
							this.topics[this.topics.length] = o;
						}
					}
				}
			}
		}
	};
	
	this.getTopicIndex = function(s)
	{
		if(s != null)
		{
			if(s != null && s >= 0)
			{
				var found = false;
				var i = 0;
				
				if(this.currentTopic != null && s >= this.currentTopic.beginTime)
					i = this.currentTopic.id;
				
				for(i; i < this.topics.length; i++)
				{
					if(i + 1 < this.topics.length)
					{
						if(s >= this.topics[i].beginTime && s < this.topics[i+1].beginTime)
						{
							found = true;
							break;
						}
					}
					else if(this.topics[i].beginTime <= s)
					{
						found = true;
						break;
					}
				}
				
				if(found) 
					return i;
				else 
					return -1;
			}
		}
	};
	
	this.previous = function()
	{
		if(this.currentTopic != null && this.currentTopic.id > 0)
		{
			this.selectTopic(this.currentTopic.id-1);
		}
	};
	
	this.next = function()
	{
		if(this.currentTopic != null && this.currentTopic.id < this.topics.length)
		{
			this.selectTopic(this.currentTopic.id+1);
		}
	};
	
	this.setDuration = function(s)
	{
		this.duration = s;
	};
	
	this.setPosition = function(pos)
	{
		if(pos != null && pos != this.currentPosition)
		{
			this.currentPosition = pos;
			var i = this.getTopicIndex(pos);
			if(i != -1 && (this.currentTopic == null || i != this.currentTopic.id))
			{
				this.selectTopic(i);
			}
			/*
			if(this.currentTopic != null)
			{
				this.currentTopic.position = pos-this.topics[i].beginTime;
				//fire event
				if(this.topicPositionChange != null) this.topicPositionChange(this.currentTopic.position);
			}
			*/
		}
	};
	
	this.init();
}
