
var cssMenu = null;
var currId = "";
var currTitleId = "";
var newId = "";
var newTitleId = "";
var currO = 1.0;
var new0 = 0.0;
var isChanging = false;

function _cssMenu()
{
	this.browserSetup();
	this.menus = [];
	this.container = null;
	this.top = 0;
	this.left = 0;
	this.selectedItem = null;
	
	this.foreColor = "rgb(0,3,97)";
	this.foreSubColor = "rgb(0,3,97)";
	this.foreHigh = "rgb(2,111,167)";
	this.foreSel = "rgb(255,255,255)";
	this.foreSubSel = "rgb(86,241,255)";
}

_cssMenu.IE = 'ie';
_cssMenu.Konqueror = 'kq';
_cssMenu.Mozilla = 'mo';
_cssMenu.Netscape = 'ns';
_cssMenu.Opera = 'op';
_cssMenu.Safari = 'sf';

_cssMenu.prototype = {

	browserSetup : function()
	{
		var agent = navigator.userAgent.toLowerCase();
		var sType;
		
		if (agent.indexOf('konqueror') != -1)
			sType = _cssMenu.Konqueror;
		else if (agent.indexOf('opera') != -1)
			sType = _cssMenu.Opera;
		else if (agent.indexOf('netscape') != -1)
			sType = _cssMenu.Netscape;
		else if (agent.indexOf('msie') != -1)
			sType = _cssMenu.IE;
		else if (agent.indexOf('safari') != -1)
			sType = _cssMenu.Safari;
		else
			sType = _cssMenu.Mozilla;
			
		this.browserType = sType;
	},

	browserIs : function()
	{
		for (var i=0; i < arguments.length; i++)
			if (this.browserType == arguments[i])
				return true;
				
		return false;
	},
	
	browserName : function()
	{
		if (this.browserType == _cssMenu.IE)
			return "Internet Explorer";
		else if (this.browserType == _cssMenu.Netscape)
			return "Netscape";
		else if (this.browserType == _cssMenu.Opera)
			return "Opera";
		else if (this.browserType == _cssMenu.Safari)
			return "Safari";
		else if (this.browserType == _cssMenu.Konqueror)
			return "Konqueror";
		else
			return "Mozilla";
	},
	
	contains : function(obj)
	{
		for (i=0; i < this.menus.length; i++)
		{
			if (this.menus[i] == obj || this.menus[i].anchor == obj)
				return true;
		}
		
		return false;
	},
	
	getMenuByNode : function(obj)
	{
		for (i=0; i < this.menus.length; i++)
		{
			if (this.menus[i] == obj || this.menus[i].anchor == obj)
				return this.menus[i];
		}
		
		return null;
	},
	
	addMenu : function(caption, href, cssNormal, cssOver, width, height, adjTop, txtIndent,
		isCurrent, repeat, isSub)
	{
		var menu = this.menus[this.menus.length] = document.createElement("DIV");
		this.container.appendChild(menu);
				
		menu.className = cssNormal;
		menu.cssNormal = cssNormal;
		menu.cssOver = cssOver;
		menu.style.position = 'absolute';
		menu.style.top = this.top;
		menu.style.left = this.left;
		menu.style.height = height;
		menu.style.width = width;
		menu.style.backgroundRepeat = (repeat == true ? "repeat" : "no-repeat");
		menu.isSub = isSub;
		menu.mainMenu = this;
		
		if (cssOver != "")
		{
			if (this.browserType == _cssMenu.IE)
			{
				menu.attachEvent('onmouseover', onMouseOver);
				menu.attachEvent('onmouseout', onMouseOut);
			}
			else
			{
				document.addEventListener("mouseover", onMouseOver, true);
				document.addEventListener("mouseout", onMouseOut, true);
			}
		}
		
		if (caption != "" && href != "")
		{
			var a = menu.anchor = document.createElement("A");
			a.appendChild( document.createTextNode(caption) );
			
			if (href.substring(0, 4) == "fnc=")
			{
				a.internalLink = true;
				a.href = "#";
				menu.clickEvent = href.substring(4);
				if (this.browserType == _cssMenu.IE)
					a.attachEvent('onclick', onClick);
				else
					document.addEventListener("click", onClick, true);
			}
			else
			{
				a.internalLink = false;
				a.href = href;
				menu.clickEvent = null;

				if (this.browserType == _cssMenu.IE)
					a.attachEvent('onclick', onClick);
				else
					document.addEventListener("click", onClick, true);
			}
			
			a.style.position = 'absolute';
			a.style.top = (this.top - 8 + adjTop) + "px";
			a.style.left = this.left;
			a.style.width = width;
			a.style.height = height;
			a.style.textDecoration = "none";
			a.style.textIndent = txtIndent + "px";
			a.style.paddingTop = '14px';
			a.style.verticalAlign = "middle";
			a.style.fontFamily = "Arial, Tahoma";
			a.style.fontSize = "10pt";
			a.style.fontWeight = "bold";
			a.isCurrent = isCurrent;
			if (isCurrent == true)
				a.style.color = this.foreSel;
			else if (isSub)
				a.style.color = this.foreSubColor;
			else
				a.style.color = this.foreColor;

			if (this.browserType == _cssMenu.IE)
			{
				a.attachEvent('onmouseover', onMouseOver);
				a.attachEvent('onmouseout', onMouseOut);
			}
			else
			{
				a.addEventListener("mouseenter", onMouseOver, true);
				a.addEventListener("mouseout", onMouseOut, true);
			}
					
			this.container.appendChild( a );
		}
		else
			menu.anchor = null;
		
		this.top += height;
	},
	
	addSeparator : function(cssSep, width, height, repeat)
	{
		var menu = this.menus[this.menus.length] = document.createElement("DIV");
		this.container.appendChild(menu);
				
		menu.className = cssSep;
		menu.style.position = 'absolute';
		
		menu.style.left = this.left;
		menu.style.top = this.top;
		menu.style.height = height;
		menu.style.width = width;
		menu.style.backgroundRepeat = (repeat ? "repeat" : "no-repeat");
		
		this.top += height;
	},
	
	setSubsToNormal : function()
	{
		for (var i=0; i < this.menus.length; i++)
		{
			var menu = this.menus[i];
			
			if (menu.isSub == true && menu.anchor)
				menu.anchor.style.color = this.foreSubColor;
		}
	}
}

function getEventElement(evt)
{
	var node = null;
	
	if (evt.srcElement)
		node = evt.srcElement;
	else
		node = (evt.target.tagName ? evt.target : evt.target.parentNode);
		
	return node;
}

function onMouseOver(evt)
{
	var node = getEventElement(evt);
	
	var menu = cssMenu.getMenuByNode(node);
	
	if (menu != null && menu.cssOver)
	{
		menu.className = menu.cssOver;
		if (menu.anchor && menu.anchor.isCurrent == false && menu.mainMenu.selectedItem != menu)
			menu.anchor.style.color = menu.mainMenu.foreHigh;
	}
}

var isInternal = true;

function onMouseOut(evt)
{
	if (!isInternal)
		return;
		
	var node = getEventElement(evt);
	
	var menu = cssMenu.getMenuByNode(node);
	
	if (menu != null && menu.cssNormal)
	{
		menu.className = menu.cssNormal;
		if (menu.anchor && menu.anchor.isCurrent == false && menu.mainMenu.selectedItem != menu)
			menu.anchor.style.color = menu.mainMenu.foreColor;
	}
}

function onClick(evt)
{
	var node = getEventElement(evt);
	
	var menu = cssMenu.getMenuByNode(node);
	
	if (menu != null)
	{
		menu.mainMenu.setSubsToNormal();
		menu.mainMenu.selectedItem = menu;
		if (menu.isSub == true)
		{
			if (menu.anchor)
				menu.anchor.style.color = menu.mainMenu.foreSubSel;
		}
		
		if (menu.clickEvent)
		{
			if (menu.internalLink)
				isInternal = menu.internalLink;
			node.blur();
			eval(menu.clickEvent);
			
			return false;
		}
		else
		{
			node.blur();
		}
	}
	
	return true;
}

cssMenu = new _cssMenu();


function setToHidden(obj)
{
	if (obj != null)
	{
		obj.style.visibility="hidden";
		obj.style.opacity = 0;
		obj.style.MozOpacity = 0;
		obj.style.KhtmlOpacity = 0;
	}
}

function setToVisible(obj)
{
	if (obj != null)
	{
		obj.style.visibility="visible";
		obj.style.opacity = 1;
		obj.style.MozOpacity = 1;
		obj.style.KhtmlOpacity = 1;
	}
}

function changeOpacity()
{
	var obj1 = document.getElementById(currId);
	var obj2 = document.getElementById(currTitleId);
	var obj3 = document.getElementById(newId);
	var obj4 = document.getElementById(newTitleId);
	
	if (obj3 != null)
	{
		if (obj3.style.visibility == "" || obj3.style.visibility == "hidden")
			obj3.style.visibility = "visible";
	}
	if (obj4 != null)
	{
		if (obj4.style.visibility == "" || obj4.style.visibility == "hidden")
			obj4.style.visibility = "visible";
	}
		
	if (curr0 > 0 || new0 < 1)
	{
		if (curr0 > 0)
			curr0 -= .1;	
		else if (new0 < 1)
			new0 += .1;
	}
	
	if (curr0 < 0) curr0 = 0;
	if (new0 > 1) new0 = 1;
					
	if (cssMenu.browserType != _cssMenu.IE)
	{
		if (obj1 != null && (curr0 > 0 || new0 == 0))
		{
			obj1.style.opacity = curr0;
			obj1.style.MozOpacity = curr0;
			obj1.style.KhtmlOpacity = curr0;
		}
		if (obj2 != null && (curr0 > 0 || new0 == 0))
		{
			obj2.style.opacity = curr0;
			obj2.style.MozOpacity = curr0;
			obj2.style.KhtmlOpacity = curr0;
		}
		if (obj3 != null)
		{	
			obj3.style.opacity = new0;
			obj3.style.MozOpacity = new0;
			obj3.style.KhtmlOpacity = new0;
		}
		if (obj4 != null)
		{		
			obj4.style.opacity = new0;
			obj4.style.MozOpacity = new0;
			obj4.style.KhtmlOpacity = new0;
		}
	}
	
	if (curr0 > 0 || new0 < 1)
	{
		if (curr0 == 0)
		{
			setToHidden(obj1);
			setToHidden(obj2);
		}
		window.setTimeout(changeOpacity, 5);
	}
	else
	{
		currId = newId;
		currTitleId = newTitleId;
		newId = "";
		newTitleId = "";
		isChanging = false;
	}	
}

function toggle(cont, useFilter)
{
	var obj1 = document.getElementById(currId);
	var obj2 = document.getElementById(currTitleId);
	var obj3 = document.getElementById(newId);
	var obj4 = document.getElementById(newTitleId);
	
	if (useFilter == false || (cont.filters && cont.filters.length > 0) )
	{
		if (useFilter)
		{
			cont.filters[0].Apply();
			cont.filters[0].enabled = true;
		}
		
		setToHidden(obj1);
		setToHidden(obj2);
		setToVisible(obj3);
		setToVisible(obj4);
		
		if (useFilter == true)
		{
			cont.filters[0].Play();
		}
	}
	
	currId = newId;
	currTitleId = newTitleId;
	newId = "";
	newTitleId = "";
	isChanging = false;
}
