
/* = MAIN NAVIGATION
---------------------------------------------------------------
	parse the url and hightlight the correct nav item
---------------------------------------------------------------*/
function prepMainNav() {
	if(!document.getElementById) return false;
	if(!document.getElementsByTagName) return false;
	
	/* parse the url */
	var url = new String(location);
	var urlArray = new Array();
	urlArray = url.split("/");
	var dirFirst = urlArray[3];
	var dirSecond = urlArray[4];
	
	/* set item to search for */
	if(dirSecond) {
		var directory = dirSecond;
	} else if(dirFirst) {
		var directory = dirFirst;
	} else {
		selectItem("nav-home");
		return 0;
	}
	
	if(directory) {
		/* check  links */
		switch(directory) {
			case "products":
				selectItem("nav-products");
				break;
			case "aggregate":
				selectItem("nav-aggregate");
				break;
			case "block":
				selectItem("nav-block");
				break;
			case "concrete":
				selectItem("nav-concrete");
				break;
			case "about":
				selectItem("nav-way");
				break;
			case "locations":
				selectItem("nav-map");
				break;
			case "careers":
				selectItem("nav-careers");
				break;
			case "community":
				selectItem("nav-community");
				break;
			case "tools":
				selectItem("nav-tools");
				break;
			case "customer_service":
				selectItem("nav-customer");
				break;
			case "projects":
				selectItem("nav-projects");
				break;
			case "greener":
				selectItem("nav-greener");
				break;
			default:
				break;
		}
	}
}

/* select the nav item */
function selectItem(navItem) {
	if(document.getElementById(navItem))
		var temp = document.getElementById(navItem);
		var item = temp.getElementsByTagName("a")[0];
		if(item.className) {
			item.className += " selected";
		}
		else {
			item.className = "selected";
		}
}


/* = BANNER NAVIGATION
---------------------------------------------------------------
	add shadows to the selected tab
---------------------------------------------------------------*/
function prepBannerNav() {
	if(!document.getElementById("banner")) return false;
	if(!document.getElementById("banner").getElementsByTagName("ul")[0]) return false;
	
	/* parse the url */
	var url = new String(location);
	var urlArray = new Array();
	urlArray = url.split("/");
	var currDir = urlArray[4];
	var currPage = urlArray[5];
	
	if(currPage) {
		switch(currPage) {
			case "ordering.html":
				selectItem(2);
				break;
			case "locations.php?product=aggregate":
				selectItem(3);
				break;
			case "locations.php?product=block":
				selectItem(4);
				break;
			case "locations.php?product=concrete":
				selectItem(3);
				break;
			case "technical_specs.html":
				selectItem(4);
				break;
			case "projects.html":
				selectItem(4);
				break;
			case "rules_thumb.html":
				selectItem(6);
				break;
			case "technical_details.html":
				selectItem(5);
				break;
			case "technical-specs.html":
				selectItem(5);
				break;
			case "products.html":
				selectItem(2);
				break;
			case "architectural.html":
				selectItem(2);
				break;
			case "brick.html":
				selectItem(2);
				break;
			case "building-supplies.html":
				selectItem(2);
				break;
			case "concrete-masonry.html":
				selectItem(2);
				break;
			case "erosion-control.html":
				selectItem(2);
				break;
			case "concrete-clay-permeable-pavers.html":
				selectItem(2);
				break;
			case "glazed-tile-masonry.html":
				selectItem(2);
				break;
			case "natural-manufactured-stone.html":
				selectItem(2);
				break;
			case "hardscapes.html":
				selectItem(2);
				break;
			case "retaining-walls.html":
				selectItem(2);
				break;
			case "turf-block.html":
				selectItem(2);
				break;
			case "masonry.html":
				selectItem(2);
				break;
			case "block_ordering.html":
				selectItem(3);
				break;
			case "aggregate.html":
				selectItem(2);
				break;
			case "block.html":
				selectItem(3);
				break;
			case "concrete.html":
				selectItem(4);
				break;
		  default:
		    selectItem(1);
		    break;
		}
		
	} else if(currDir && !currPage) {
		selectItem(1);
	}
	
	/* select the nav item */
	function selectItem(navItem) {
		navItem--;
		
		var list = document.getElementById("banner");
		var listItem = list.getElementsByTagName("li")[navItem];
		if(listItem.className) {
			listItem.className += " selected";
		}
		else {
			listItem.className = "selected";
		}
		
		selectBannerNav();
	}
}

function selectBannerNav() {
	if(!document.getElementById || !document.getElementsByTagName) return 0;
	if(!document.getElementById("banner")) return 0;
	
	var list = document.getElementById("banner");
	var listContainer = list.getElementsByTagName("UL");
	var listItem = list.getElementsByTagName("LI");
	
	for( var i = 0; i < listItem.length; i < i++ )
	{
		if(listItem[i].className.match("selected")) {
				var itemOffset = listItem[i].offsetLeft;
				var itemWidth = listItem[i].offsetWidth;
				
				/* left shadow */
				var shadowLeft = document.createElement("img");
				shadowLeft.setAttribute("src","/images/header_nav_selected_left.gif");
				shadowLeft.style.position = "absolute";
				
				var containerOffset = listItem[i].parentNode.offsetLeft;
				shadowLeft.style.left = (containerOffset+itemOffset-146)+"px"
				shadowLeft.style.bottom = "0px";
				
				list.appendChild(shadowLeft);
				
				/* right shadow */
				var shadowRight = document.createElement("img");
				shadowRight.setAttribute("src","/images/header_nav_selected_right.gif");
				shadowRight.style.position = "absolute";
				
				var containerOffset = listItem[i].parentNode.offsetLeft;
				shadowRight.style.left = (containerOffset+itemOffset+itemWidth)+"px"
				shadowRight.style.bottom = "0px";
				
				list.appendChild(shadowRight);
				
				/* end shadow */
				var shadowEnd = document.createElement("img");
				shadowEnd.setAttribute("src","/images/header_nav_selected_end.png");
				shadowEnd.style.position = "absolute";
				shadowEnd.style.right = "0px"
				shadowEnd.style.bottom = "0px";
				shadowEnd.className = "endShadow";
				
				list.appendChild(shadowEnd);
		}
	}
}


/* INITIALIZE ALL FUNCTION AFTER WINDOW ONLOAD
-------------------------------------------------*/
function init() {
	if(!document.getElementById || !document.getElementsByTagName) return 0;
	// prep functions
	prepBannerNav();
	prepMainNav();
}

addLoadEvent(init);


/* = ON LOAD
---------------------------------------------------------------
	add the on load events
---------------------------------------------------------------*/
function addLoadEvent(func) {
	var oldOnLoad = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}	else {
		window.onload = function() {
			oldOnLoad();
			func();
		}
	}
}