/* SWIM2.0 :: Simple website menu
****************************************************************
* DOM scripting by brothercake -- http://www.brothercake.com/
* Licensed under GPL -- http://www.gnu.org/copyleft/gpl.html
****************************************************************
* For professional menu solutions visit -- http://www.udm4.com/ 
****************************************************************
*/

// This version modified by KC-Luck
// http://www.codingforums.com/showthread.php?t=19289&page=7

// Minor edits by Heikki / Nemein


window.onload = function()
{
	var horizontals = new simpleMenu('menu-h', 'horizontal');
};

function simpleMenu(navid, orient)
{
	if(typeof document.getElementById == 'undefined' || /opera[\/ ][56]/i.test(navigator.userAgent)) { return; }
	this.iskde = navigator.vendor == 'KDE';
	this.isie = typeof document.all != 'undefined' && typeof window.opera == 'undefined' && !this.iskde;
	this.isoldsaf = navigator.vendor == 'Apple Computer, Inc.' && typeof XMLHttpRequest == 'undefined';
	this.tree = function() {
	  return document.getElementById(navid);
	}
	
	//if it exists
	if(this.tree() != null)
	{
		//get trigger elements
		this.items = this.tree().getElementsByTagName('li');
		this.itemsLen = this.items.length;
		var i = 0; 
		do
		{
			this.init(this.items[i], this.isie, this.isoldsaf, this.iskde, navid, orient);
		}
		while (++i < this.itemsLen);
	}
}

//trigger initialiser
simpleMenu.prototype.init = function(trigger, isie, isoldsaf, iskde, navid, ishoriz)
{
	trigger.menu = 
	  trigger.getElementsByTagName('ul').length ? 
	  trigger.getElementsByTagName('ul')[0] : null;

	trigger.link = trigger.getElementsByTagName('a')[0];
	trigger.issub = trigger.parentNode.id == navid;
	trigger.ishoriz = ishoriz == 'horizontal';
	this.openers = { 'm' : 'onmouseover', 'k' : (isie ? 'onactivate' : 'onfocus') };
	for(var i in this.openers)
	{
		trigger[this.openers[i]] = function(e)
		{
			//set rollover persistence classname 
			// Nemein: Added check for trigger, because not all main level items have links
			if(!iskde && trigger) { this.link.className += (this.link.className == '' ? '' : ' ') + 'rollover'; }

			if(this.menu != null)
			{
				if(this.ishoriz) { this.menu.style.left = (isie || isoldsaf) ? this.offsetLeft + 'px' : 'auto'; }
				this.menu.style.top = (this.ishoriz && this.issub) ? 
				  (isie || (this.ishoriz && isoldsaf)) ? 
				    this.link.offsetHeight + 'px' : 'auto' : 
				  (isie || (this.ishoriz && isoldsaf)) ? 
				    this.offsetTop + 'px' : '0';
			}
		};
	}

	this.closers = { 'm' : 'onmouseout', 'k' : (isie ? 'ondeactivate' : 'onblur') };

	for(i in this.closers)
	{
		trigger[this.closers[i]] = function(e)
		{
			this.related = (!e) ? window.event.toElement : e.relatedTarget;
			if(!this.contains(this.related))
			{
				if(!iskde && trigger) { this.link.className = this.link.className.replace(/[ ]?rollover/g, ''); }
				if(this.menu != null)
				{
					this.menu.style[(this.ishoriz ? 'left' : 'top')] = 
					  this.ishoriz ? '-10000px' : '-100em';
				}
			}
		};
	}

	if(!isie)
	{
		trigger.contains = function(node)
		{
			if (node == null) { return false; }
			if (node == this) { return true; }
			else { return this.contains(node.parentNode); }
		};
	}
	// stop IE memory leak
	trigger = null;
}
