/**
 * @author Chris Yap DHAP Digital
 * NAV CONTROLLER
 */


var NavController = Class.create();

Object.extend(NavController.prototype, {
	initialize: function(){
	
		
		// test for existence of flag for HTML SELECT IE fix
		if(htmlSelectFix == true){
			this.initFormsFix();
		}

	},
	
	findPosY: function(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;

	},
	
	initFormsFix: function() {
		
		var ieULs = document.getElementsByClassName('navChildUL');
	
		for (i=0; i<ieULs.length; i++) {
		
			var currentWidth = ieULs[i].offsetWidth;
			var currentHeight = ieULs[i].offsetHeight;
			var iframeVar = document.createElement('iframe');
			ieULs[i].appendChild(iframeVar);
			iframeVar.style.width = currentWidth + 'px';
			iframeVar.style.height = currentHeight + 'px';
			
		}
		
		//$('loadingPanel').style.display = 'none';
	

	}
	
});

// for nav links to popups
function popupNavLink(url, name, w, h) {
	// calculating the center of the browser window, so that we can center the popup over the window
	var windowWidth = (document.all) ? document.body.offsetWidth : window.innerWidth;
	var windowHeight = (document.all) ? document.body.offsetHeight : window.innerHeight;
	var left = Math.round( (windowWidth - w) / 2 ) + "px";
	var top =  Math.round( (windowHeight - h) / 2 ) + "px";
    // opens a new window and sets the object o your popup variable
	popupNavWin = window.open(url+'',name+'','width='+w+',height='+h+ ',top='+top+',left='+left);
	// make sure the popup is the focused window
	if (popupNavWin) popupNavWin.focus(); 
}

//For News section - hide select dropdown on rollover of global nav in IE6
document.observe("dom:loaded", function() {
	if ((document.all) && (!window.XMLHttpRequest)) {
		if ($('categorySelect')) {
			$$('#diversityItem .levelOneNav .parentClass').first().observe('mouseover', function() {
				$('categorySelect').style.visibility = "hidden";
			});
			$$('#diversityItem .levelOneNav .parentClass').first().observe('mouseout', function() {
				$('categorySelect').style.visibility = "visible";
			});
			
			$$('#philanthropyItem .levelOneNav .parentClass').first().observe('mouseover', function() {
				$('categorySelect').style.visibility = "hidden";
			});
			$$('#philanthropyItem .levelOneNav .parentClass').first().observe('mouseout', function() {
				$('categorySelect').style.visibility = "visible";
			});
			
			$$('#philanthropyItem .levelOneNav .parentClass')[1].select('.parentClass')[0].observe('mouseover', function() {
				$('categorySelect').style.visibility = "hidden";
			});
			$$('#philanthropyItem .levelOneNav .parentClass')[1].select('.parentClass')[0].observe('mouseout', function() {
				$('categorySelect').style.visibility = "visible";
			});
			$$('#philanthropyItem .levelOneNav .parentClass')[1].select('.parentClass')[1].observe('mouseover', function() {
				$('categorySelect').style.visibility = "hidden";
			});
			$$('#philanthropyItem .levelOneNav .parentClass')[1].select('.parentClass')[1].observe('mouseout', function() {
				$('categorySelect').style.visibility = "visible";
			});
			$$('#philanthropyItem .levelOneNav .parentClass')[1].select('.parentClass')[2].observe('mouseover', function() {
				$('categorySelect').style.visibility = "hidden";
			});
			$$('#philanthropyItem .levelOneNav .parentClass')[1].select('.parentClass')[2].observe('mouseout', function() {
				$('categorySelect').style.visibility = "visible";
			});
		}
	}
});
