Navigation = function(argumentsGot)
{
	this.initialize=function(argumentsGot)
	{
		this.html={};//Container for HTML Tags
		this.html.navi=document.body.appendChild(Util.createTag('div','id=navigation',null));
		this.navigationNodes=new Object();
		this.navigationContainer=new Object();
		this.xml=argumentsGot.xml;
		this.counterDepth=0;
		this.createEmptyContainers=true;
		this.autoPositionLevels='2';//this.xml.firstChild.getAttribute('autoPositionLevels');
		this.createNavigation();
		this.home=this.navigationNodes[this.xml.nodeName+'_'+this.xml.firstChild.nodeName];
	}
	this.showHome=function()
	{
		this.showNavigation(this.home);
	}
	this.createNavigation=function(entryNodeGot,pathGot,parentNodeGot)
	{
		if(entryNodeGot==null)
			entryNodeGot=this.xml;
		var tmpParent=this.navigationNodes[pathGot];
		if(typeof(tmpParent)=='undefined')
			tmpParent=null;
		if(typeof(pathGot)=='undefined')
			pathGot=entryNodeGot.nodeName+'_';
		else
			pathGot+='_';
		this.counterDepth++;
		var strNavContainer=pathGot+'container';//+'level'+this.counterDepth;
		var tmpNavigationContainer=new NavigationContainer({id:strNavContainer,counterDepth:this.counterDepth,parent:tmpParent,autoPositionLevels:this.autoPositionLevels});
		this.navigationContainer[tmpNavigationContainer.id]=tmpNavigationContainer;
		if(this.counterDepth==this.autoPositionLevels)
			website.autoWidthElements[tmpNavigationContainer.id]=tmpNavigationContainer.html;
		this.html.navi.appendChild(tmpNavigationContainer.html);
		var currentNode;
		var tmpTag;
		for(var i=0;i<entryNodeGot.childNodes.length;i++)
		{
			currentNode=entryNodeGot.childNodes[i];
			if(currentNode.nodeType==1)
			{
				var tmpForward=currentNode.getAttribute('forward');
				var tmpLink=currentNode.getAttribute('link');
				var strNaviPath = pathGot;
				var tmpContent=currentNode.getAttribute('title');
				if(tmpContent==null)
					tmpContent=currentNode.nodeName;
				var tmpName=currentNode.getAttribute('name');
				if(tmpName==null)
					tmpName=currentNode.nodeName;
				var tmpStyle=currentNode.getAttribute('style');
				if(tmpStyle==null)
					tmpStyle='default';
				strNaviPath+=currentNode.nodeName;
				var tmpNavigationNode=new NavigationNode({id:strNaviPath,title:tmpContent,name:tmpName,style:tmpStyle,counterDepth:this.counterDepth,parent:tmpNavigationContainer,forward:tmpForward,link:tmpLink})
				if(parentNodeGot!=null)
					parentNodeGot.childs.push(tmpNavigationNode);
				this.navigationNodes[tmpNavigationNode.id]=tmpNavigationNode;
				tmpNavigationContainer.html.appendChild(tmpNavigationNode.html);
				//this.html.navi['id'+i+currentNode.nodeName]=tmpTag;
				if(currentNode.hasChildNodes() || this.createEmptyContainers)
					this.createNavigation(currentNode,strNaviPath,tmpNavigationNode);
			}
			else if(currentNode.nodeType==3)
			{
				entryNodeGot.removeChild(currentNode);
				i--;
			}
		}
		this.counterDepth--;
	}
	this.showNavigation=function(navElementGot)
	{
		if(typeof(navElementGot)=='string')
			navElementGot=this.navigationNodes[navElementGot];
		this.hideChilds(navElementGot);
		this.showChilds(navElementGot);
	}
	this.hideChilds=function(navElementGot)
	{
		for(var navigationContainer in this.navigationContainer)
		{
			var currentContainer=this.navigationContainer[navigationContainer];
			if(currentContainer.counterDepth>navElementGot.counterDepth)
				currentContainer.hide();
			/*if(currentContainer.id.indexOf(navElementGot.id+'_container')>=0)
				currentContainer.hide();*/
		}
	}
	this.showChilds=function(navElementGot)
	{
		for(var navigationContainer in this.navigationContainer)
		{
			var currentContainer=this.navigationContainer[navigationContainer];
			if(currentContainer.id.indexOf(navElementGot.id+'_container')>=0)
				currentContainer.show();
		}
		for(var navigationNode in this.navigationNodes)
			if(this.navigationNodes[navigationNode].parent==navElementGot.parent || navElementGot.counterDepth<this.navigationNodes[navigationNode].counterDepth)
				this.navigationNodes[navigationNode].hide();
		navElementGot.show();
	}
	this.initialize(argumentsGot);
};
AbstractNavigationElement=function(argumentsGot)
{
	this.initialize=function(argumentsGot)
	{
		this.id=null;
		this.title=null;
		this.html=new Object();
	}
	this.show=function()
	{
		Util.log('not yet implemented');
	}
	this.hide=function()
	{
		Util.log('not yet implemented');
	}
	this.initialize(argumentsGot);
}
NavigationNode=function(argumentsGot)
{
	this.constructor();
	this.initialize=function(argumentsGot)
	{
		this.id=argumentsGot.id;
		this.title=argumentsGot.title;
		this.name=argumentsGot.name;
		this.style=argumentsGot.style;
		this.forward=argumentsGot.forward;
		this.link=argumentsGot.link;
		this.counterDepth=argumentsGot.counterDepth;
		this.html=Util.createTag('div','id='+this.id,this.title);
		this.childs=new Array();
		if(this.link!=null)
			this.html.onclick=website.openExternalLink.bind(this.link);
		else if(this.forward!=null)
			this.html.onclick=website.showChildPage.bind(this);
		else
			this.html.onclick=website.showPage.bind(this);
		this.parent=argumentsGot.parent;
	}
	this.show=function()
	{
		this.html.className+=' selected';
	}
	this.hide=function()
	{
		this.html.className=this.html.className.replace(/selected/g,'');
	}
	this.initialize(argumentsGot);
}
NavigationNode.prototype=new AbstractNavigationElement();

NavigationContainer=function(argumentsGot)
{
	this.constructor();
	this.initialize=function(argumentsGot)
	{
		this.id=argumentsGot.id;
		this.title=argumentsGot.title;
		this.counterDepth=argumentsGot.counterDepth;
		this.parent=argumentsGot.parent;
		this.html=Util.createTag('div','id='+this.id+',class=level'+this.counterDepth,null);
		this.autoPositionLevels=false;
		if(argumentsGot.autoPositionLevels.indexOf(this.counterDepth.toString())>=0)
			this.autoPositionLevels=true;
	}
	this.show=function()
	{
		if (this.autoPositionLevels && this.parent != null)
		{
			this.html.style.left = this.parent.html.offsetLeft - parseInt($(this.html).getStyle('padding-left'));
		}
		//this.html.style.visibility='visible';
		this.html.style.display='block';
		//this.html.className+=' selected';
	}
	this.hide=function()
	{
		//this.html.style.visibility='hidden';
		this.html.style.display='none';
	}
	this.initialize(argumentsGot);
}
NavigationContainer.prototype=new AbstractNavigationElement();
