/*
Title:      Navi JS Page
Author:     Ben Babics, bbabics@gmail.com
Copyright:  © Copyright 2007, Ben Babics Websites. All Rights Reserved.
Notes:      Controlls Page Navigation
*/



//identify page
var page = document.location.href;
var active;
var active_gParent;


	//temp fix
	if (page.indexOf('.php') == -1) page = page + "index.php";


function Navi_Selected()
{
	//create vars
	var nav = document.getElementById('nav');
	var li = nav.getElementsByTagName('li');
	var a = nav.getElementsByTagName('a');
	
	//loop through anchor & list item elements
	for (i=0; i < a.length; i++)
	{
		//find parent and grand parent nodes
		var parent = li[i].parentNode;
		var gParent = parent.parentNode;
		
		//assign attributes to anchor tag
		var a_href = a[i].getAttribute('href');
		var a_id = a_href.replace(/ /, '_');
		a_id = a_id.split('/');
		var a_id_len = a_id.length - 1;
		a_id = a_id[a_id_len];
		a_id = a_id.split('.html') || a_id.split('.php');
		a_id = a_id[0];
		a_id = a_id.toLowerCase();

		
				
		//match page and id
		if (page.indexOf(a_id) != -1)
		{
			//if 'li' is in the sub-nav
			if (parent.getAttribute('id') != "nav")
			{
				gParent.className = "selected";
				li[i].className = "selected";
				
				//set active var as sub-nav ul
				active = parent;
				
				//set var for grandparent value sidepannel
				active_gParent = gParent.childNodes[0].childNodes[0].nodeValue;
			}
			//if 'li' is in the main nav
			else
			{
				li[i].className = "selected";
				active_gParent = li[i].firstChild.childNodes[0].nodeValue;
			}
			
			//escape whitespace
			active_gParent = escape(active_gParent);
		}
		
		
		
	}
	
}



function Over_Item(obj)
{
	//set current class to .over
	Add_Class(obj, 'over');
	
	//kill if item is in main-nav
	if (!active) return false;
	
	if (obj.getElementsByTagName('ul')[0])
	{
		//get sub-nav
		var obj_ul = obj.getElementsByTagName('ul')[0];

		//if current's sub-nav is not active sub-nav, hide it
		if (obj_ul != active) active.style.display = "none";
	}
}



function Off_Item(obj)
{
	//remove current class .over
	Remove_Class(obj, 'over');
	
	//kill if item is in main-nav
	if (!active) return false;
	
	if (obj.getElementsByTagName('ul')[0])
	{
		//get sub-nav
		var obj_ul = obj.getElementsByTagName('ul')[0];

		//if current's sub-nav is not active sub-nav, show it
		if (obj_ul != active) active.style.display = "block";
	}
}