AXController = function(topicsId)
{
	this.topicsULId = topicsId != null ? topicsId : "topics";
	this.currentPosition = -1;
	this.topics = new Array();
	this.currentTopic = null;
	this.currentTopicIndex = -1;
	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.getTopics3(this.topicsULId);
			}
			else
			{
				if(this.topicsUL != null)
				{
					this.topicsUL.style.display = "none";
				}	
			}
		}
		catch(e)
		{
		}
	};
	
	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(obj.parentNode.nodeName == "A")
					{
						obj = obj.parentNode;
					}
					if(this.topics[i].linkObj == obj)
					{
						selectedTopic = i;
						break;
					}
				}
			}
		}
		else
		{
			selectedTopic = e;
		}
		
		if(selectedTopic == this.currentTopicIndex)
		{
			return;
		}
		
		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];
					this.currentTopicIndex = 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;
						}
					}
					
					//scroll into view
					//this will scroll the whole page - do not use. problem with iframes
					//this.topics[i].linkObj.parentNode.scrollIntoView(true);
					
					if(useAutomaticMenuPositioning)
					{
						var offset = (automaticMenuPositioningOffsetTop != null) ? automaticMenuPositioningOffsetTop:50;
						var menu = this.topics[i].linkObj.parentNode.parentNode.parentNode;
						var x = this.topics[i].linkObj.offsetTop-offset;
						x = (x>-1)?x:0;
						if(x < menu.scrollHeight)
						{
							menu.scrollTop = x;
						}
					}
				}
				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.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);
				}
			}
		}
	};
	
	// time format hh:mm:ss
	this.getTopics3 = function(id)
	{
		var o = document.getElementById(id);
		if(o != null && o.nodeName == "UL")
		{
			var li = o.getElementsByTagName('li');
			var imageUrl = null;
			for(var i=0; i<li.length; i++)
			{
				try
				{
					var obj
					var title = null;
					var slideId = null;
					var beginTime = null;
					
					
					obj = li[i].getElementsByTagName('a');
					if(obj.length > 0)
					{
						title = obj[0];
					}
					else
					{
						title = li[i];
					}
					
					obj = getElementsByClassName(li[i], 'slideId');
					if(obj.length > 0)
					{
						slideId = parseInt(obj[0].innerHTML);
					}
				
					obj = getElementsByClassName(title, 'beginTime');
					if(obj.length > 0)
					{
						beginTime = obj[0].innerHTML;
						beginTime = beginTime.replace("(", "");
						beginTime = beginTime.replace(")", "");
						beginTime = toSeconds(beginTime);
					}
					
					obj = getElementsByClassName(li[i], 'imageId');
					if(obj.length > 0)
					{
						imgUrl = obj[0].innerHTML;
						//alert(imgUrl);
					}
					
					//imgUrl = (li[i].getElementsByTagName('img')!=null)?li[i].getElementsByTagName('img').src:null;
					
					if(beginTime != null)
					{
						this.addTopic(beginTime, title.innerHTML, slideId, title, imgUrl);
					}
					
					if(beginTime != null)
					{
						EventManager.Add(li[i],'click',this.selectTopic);
					}
				}
				catch(ex)
				{
				
				}	
			}
		}
	};
	
	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.currentTopicIndex;
				}
				
				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.currentTopicIndex > 0)
		{
			this.selectTopic(this.currentTopicIndex-1);
		}
	};
	
	this.next = function()
	{
		if(this.currentTopicIndex < this.topics.length)
		{
			this.selectTopic(this.currentTopicIndex+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);
			//alert(i + " " + this.currentTopicIndex);
			
			if(i > -1 && (this.currentTopicIndex == -1 || i != this.currentTopicIndex))
			{
				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();
}
