var ie = document.all;
var nn6 = document.getElementById&&!document.all;

function getEventTarget(evt)
{
	return (evt.target) 
		? evt.target
        : (evt.srcElement) 
		? evt.srcElement 
		: null;
}

function init()
{
	menuSetup();
	
	document.onclick = function(e)
    {   
		evt = e || window.event;
		var el = getEventTarget(evt);
		
		if (el && !el.id)
		{
			var obj = el;
			while (!obj.id && obj.tagName != 'BODY' && obj.tagName != 'HTML')
			{
				obj = obj.parentNode;
			}
			el = obj;
		}
		if (el.id)
		{
			var id = el.id;
			var arg = id.split('-');

			switch (arg[0])
			{
				case "logo":
					location.href = domain + "/" + webroot;
				case "menu_bar":
					menuEvents(evt);
				case "tog":
					toggleDisplayEm(el, arg[1]);
				case "pflist":
					showPortfolioText(arg[1]);
				default: break;
			}
		}
	};

}

function menuSetup()
{
	var menu_bar = document.getElementById('menu_bar');
	for (var i=0; i < menu_bar.childNodes.length; i++)
	{
		if (menu_bar.childNodes[i].tagName == 'UL')
		{
			for (var j=0; j < menu_bar.childNodes[i].childNodes.length; j++)
			{
				if (menu_bar.childNodes[i].childNodes[j].tagName == 'LI')
				{
					for (var k=0; k < menu_bar.childNodes[i].childNodes[j].childNodes.length; k++)
					{
						if (menu_bar.childNodes[i].childNodes[j].childNodes[k].tagName == 'A')
						{
							menu_bar.childNodes[i].childNodes[j].childNodes[k].onmouseover = menuEvents;
							menu_bar.childNodes[i].childNodes[j].childNodes[k].onmouseout = menuEvents;
							
							var arg = menu_bar.childNodes[i].childNodes[j].childNodes[k].id.split('-');

							menu_bar.childNodes[i].childNodes[j].childNodes[k].className = arg[1] == section
								? 'on'
								: 'off';
							break;
						}
					}
				}
			}
		}
	}
	var submenu_bar = document.getElementById('submenu_bar');
	if (submenu_bar)
	{
		for (var i=0; i < submenu_bar.childNodes.length; i++)
		{
			if (submenu_bar.childNodes[i].tagName == 'UL')
			{
				for (var j=0; j < submenu_bar.childNodes[i].childNodes.length; j++)
				{
					if (submenu_bar.childNodes[i].childNodes[j].tagName == 'LI')
					{
						for (var k=0; k < submenu_bar.childNodes[i].childNodes[j].childNodes.length; k++)
						{
							if (submenu_bar.childNodes[i].childNodes[j].childNodes[k].tagName == 'A')
							{
								submenu_bar.childNodes[i].childNodes[j].childNodes[k].onmouseover = submenuEvents;
								submenu_bar.childNodes[i].childNodes[j].childNodes[k].onmouseout = submenuEvents;
								
								var arg = submenu_bar.childNodes[i].childNodes[j].childNodes[k].id.split('-');

								submenu_bar.childNodes[i].childNodes[j].childNodes[k].className = arg[1] == page
									? 'on'
									: 'off';
								break;
							}
						}
					}
				}
			}
		}
	}
}

function menuEvents(e)
{
	evt = e || window.event;
	var el = getEventTarget(evt);
	
	var arg = el.id.split('-');
	
	if (evt.type == 'mouseover' && arg[1] != section)
	{
		el.className = 'on';
	}
	else if (evt.type == 'mouseout' && arg[1] != section)
	{
		el.className = 'off';
	}
}

function submenuEvents(e)
{
	evt = e || window.event;
	var el = getEventTarget(evt);
	
	var arg = el.id.split('-');
	
	if (evt.type == 'mouseover' && arg[1] != page)
	{
		el.className = 'on';
	}
	else if (evt.type == 'mouseout' && arg[1] != page)
	{
		el.className = 'off';
	}
}

function toggleDisplayEm(el, str)
{
	var tog_em = document.getElementById(str);
	
	tog_em.style.display = tog_em.style.display != 'none'
		? 'none'
		: 'block';
		
	el.innerHTML = tog_em.style.display != 'none'
		? '< Less'
		: 'More >';
}

_scrollbar_id = 1;

function setupScroll(num)
{
	var scrollbar = document.getElementById('scrollbar' + num);
	var content = document.getElementById('content' + num);
	var up = document.getElementById('up' + num);
	var down = document.getElementById('down' + num);
	
	up.onclick = function() { dw_scrollObj.initScroll('wn' + this.id.substring((this.id.length-1), this.id.length),'up'); };
	up.onmouseover = function() { dw_scrollObj.initScroll('wn' + this.id.substring((this.id.length-1), this.id.length),'up'); };
	up.onmouseout = function() { dw_scrollObj.stopScroll('wn' + this.id.substring((this.id.length-1), this.id.length)); };
	up.onmousedown = function() { dw_scrollObj.doubleSpeed('wn' + this.id.substring((this.id.length-1), this.id.length)); };
	up.onmouseup = function() { dw_scrollObj.resetSpeed('wn' + this.id.substring((this.id.length-1), this.id.length)); };

	down.onclick = function() { dw_scrollObj.initScroll('wn' + this.id.substring((this.id.length-1), this.id.length),'down'); };
	down.onmouseover = function() { dw_scrollObj.initScroll('wn' + this.id.substring((this.id.length-1), this.id.length),'down'); };
	down.onmouseout = function() { dw_scrollObj.stopScroll('wn' + this.id.substring((this.id.length-1), this.id.length)); };
	down.onmousedown = function() { dw_scrollObj.doubleSpeed('wn' + this.id.substring((this.id.length-1), this.id.length)); };
	down.onmouseup = function() { dw_scrollObj.resetSpeed('wn' + this.id.substring((this.id.length-1), this.id.length)); };
	
	var j = 0;
	for (var i=0; i < content.childNodes.length; i++)
	{
		if (content.childNodes[i].tagName == 'LI')
		{
			content.childNodes[i].id = 'pflist-' + j;
			if (j % 2)
			{
				// do odd stuff
				content.childNodes[i].className = 'right';
			}
			else
			{
				// do even stuff
				content.childNodes[i].className = 'left';
			}
			j++;
		}
	}
	content.style.visibility = 'visible';
	scrollbar.style.visibility = 'visible';
}

function showPortfolioText(num)
{
	var texth = document.getElementById("textholder");
	for (var i=0; i < texth.childNodes.length; i++)
	{
		if (texth.childNodes[i].tagName == 'DIV')
		{
			var arg = texth.childNodes[i].id.split('-');
			texth.childNodes[i].style.display = arg[1] == num
				? 'block'
				: 'none';
		
		}
	}
}