//*************************
//     NAVIGATION
//*************************

//Creates a drop-down navigation menu, where poorer browsers struggle with css hover. 
function dropDown() {
	if (document.getElementById) {
		var navRoot = document.getElementById("nav");
		if(navRoot){
			for (i=0; i<navRoot.childNodes.length; i++) {
				var node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
	  				node.onmouseout=function() {
						this.className="";
						this.className.replace(" over", "");
	   				}
				}
			}
		}
	}
}
addLoadEvent(dropDown);

function shadow() {
	var subNavItems = getElementsByClass("first", document, "li"); //Get first LI in each drop-down UL.
	for (var i=0; i< subNavItems.length; i++){
		var subNav = subNavItems[i].parentNode; //The parent UL of each LI.
		var subNavHeight = subNav.offsetHeight*0.14 +"em"; //The height of the UL plus a bit more (optional amount).
		var subNavWidth = subNav.offsetWidth*0.12 +"em"; //The width of the UL plus a bit more (optional amount).

		var shadowBg = document.createElement("img"); //Create an img that is as big as the newly-calculated width and height.
		shadowBg.setAttribute("alt","");
		shadowBg.setAttribute("class", "shadow");
		shadowBg.setAttribute("className", "shadow");
		shadowBg.style.height = subNavHeight;
		shadowBg.style.width = subNavWidth;
		if((navigator.userAgent.indexOf("IE")>=0) && (navigator.userAgent.indexOf("MSIE 7")==-1) && (navigator.userAgent.indexOf("Opera") == -1)) { //Just to check it is Internet Explorer but not IE7.
			shadowBg.src = "http://www.amactive.co.uk/btns/nav/transparent.gif"; //A small transparent gif, used as a placeholder.
			shadowBg.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.amactive.co.uk/btns/nav/nav_bubble_shadow.png', sizingMethod='scale')"; //The filtered transparent image.
		} else {
			shadowBg.setAttribute("src","http://www.amactive.co.uk/btns/nav/nav_bubble_shadow.png");
		}
		/* IE HACK TO ALLOW DROP-DOWN NAV TO OVERLAP FORM ELEMENTS */
		if((navigator.userAgent.indexOf("IE")>=0) && (navigator.userAgent.indexOf("MSIE 7")==-1) && (navigator.userAgent.indexOf("Opera") == -1)) {
			var iframeFix = document.createElement("iframe");
			iframeFix.style.height = subNavHeight;
			iframeFix.style.width = subNavWidth;
			subNav.insertBefore(iframeFix, subNavItems[i]);
		}
		
		subNav.insertBefore(shadowBg, subNavItems[i]); //Insert the img into the UL before the first LI. The width and height of this pushes 
																			//the UL outwards to accommodate it.
	}
}
//addLoadEvent(shadow);