// JavaScript Document

var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var isMSIE = /*@cc_on!@*/false;


//Function returns the X co-ordinate of a given element.
function findPosX(obj){ 
	var curleft = 0;
	if(obj.offsetParent)
		while(1){
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
	}
	
//Function returns the Y co-ordinate of give element.
function findPosY(obj){
var curtop = 0;
if(obj.offsetParent)
	while(1){
	  curtop += obj.offsetTop;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.y)
	curtop += obj.y;
return curtop;
}
//Function to set opacity of a given element
function setOpacity(elementID, value){
	elementID.style.opacity = value/10;
	elementID.style.filter = 'alpha(opacity=' + value*10 + ')';
}
function navControl(element, x){
	var firstDivElement; //Variable to store the first child div element of the passed in (li) item. The div should be the one with class 'subnav'
	for (var i=0; i<element.childNodes.length; i++){
		if ( element.childNodes[i].nodeType == 1 && element.childNodes[i].nodeName == 'DIV' ) { //If element has a nodeType == 1 (Element) and is a DIV
			firstDivElement = element.childNodes[i];
			break;
		} 
	}
	var secondDivElement; //Variable to store the second child div element of the passed in (li) item. The div should be the one with class 'subnav_inner'
	for (var i=0; i<firstDivElement.childNodes.length; i++){
		if ( firstDivElement.childNodes[i].nodeType == 1 && firstDivElement.childNodes[i].nodeName == 'DIV' ) { //If element has a nodeType == 1 (Element) and is a DIV
			secondDivElement = firstDivElement.childNodes[i];
			break;
		}
	}
	//Set subnav holder (class="subnav") to width of clients window.
	var windowWidth = document.body.clientWidth;
	firstDivElement.style.width = windowWidth+'px';
	//setOpacity(firstDivElement, 8);
	//Set 'div' with the class 'subnav_inner' to align left with its parent list item.
	secondDivElement.style.marginLeft = findPosX(element) + 'px';
	//Switch sub-navigation display state according to the paramater passed on mouseover/out.
	var state = new Array("none","block");
	firstDivElement.style.display = state[x];
	//Control parent list item background so it shows then hovering over subnav
	if (x == 1){
		if (IE6 != true){
			element.childNodes[0].style.background = "url(_assets/_images/_navigation/transparent_active_bg.png)";
			element.childNodes[0].style.backgroundPosition = "bottom";
			element.childNodes[0].style.backgroundRepeat = "repeat-x";
		} else {
			element.childNodes[0].style.background = "url(_assets/_images/_navigation/ie6_active_bg.png)";
			element.childNodes[0].style.backgroundPosition = "bottom";
			element.childNodes[0].style.backgroundRepeat = "repeat-x";
		}
	} else {
		if (isMSIE == true){
			var activeClass = element.childNodes[0].getAttribute('className');
			if (activeClass != 'active'){
				element.childNodes[0].style.background = "none";
			}
		}else{
			var activeClass = element.childNodes[0].getAttribute('class');
			if (activeClass != 'active'){
				element.childNodes[0].style.background = "none";
			}
		}
	}
}

function positionIcons(){
	var element = document.getElementById("navbox");
	for( var i=0; i < element.childNodes.length; i++ ){
		if ( element.childNodes[i].nodeType == 1 && element.childNodes[i].nodeName == 'DIV' ) { //If element has a nodeType == 1 (Element) and is a DIV
			var temp = element.childNodes[i];
			for (var j=0; j < temp.childNodes.length;j++){
				if ( temp.childNodes[j].nodeType == 1 && temp.childNodes[j].nodeName == 'A' ) {
					var AElement;
					AElement = temp.childNodes[j];
					AElement.style.backgroundPosition = 'center 30px';
				}
			}
		} 
	}
}