addLoadEvent(init);


// protect the onload event
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
		window.onload = function() {
		  oldonload();
		  func();
		}
	}
}

function init(){

	// Add class name to last item of lists
	oLists = document.getElementsByTagName('UL');
	for(i=0;i<oLists.length;i++){
		oChildren = oLists[i].childNodes;
		vLastItem = oChildren.length;
		if(vLastItem > 0) {
			do{
				vLastItem = vLastItem-1;
				addClassName(oChildren[vLastItem],'last');
			}while ((oChildren[vLastItem].nodeType!=1)&&(vLastItem>0));
		}
	}

	// Set up SiteNavigation JS rollover stickyness
	if (document.getElementById('site-nav')){
		/** Attempts to address  Internet Explorer bug (Q177378) where 
			FORM elements 'burn through' dHTML menus.
						http://support.microsoft.com/kb/q177378/
			Technique 'undercovers' menus with iframes. Not guaranteed for
			non-IE browsers - use at own risk.
			
		    Ugly browser-sniffing based on User Agent String here.
		    Dangerous because of unknown behaviour in Internet Explorer 7+
		**/
		var ua = navigator.userAgent.toLowerCase();
		var ie = (document.all) ? true : false;
		if ((ua.indexOf('msie') != -1) && (ie) && (ua.indexOf('win') != -1)) {
			var ieULs = document.getElementById('site-nav').getElementsByTagName('ul');
			for (j=0; j<ieULs.length; j++) {
				ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + ieULs[j].innerHTML);
				/*ieULs[j].innerHTML = ('<iframe id="iePad' + j + '" src="" scrolling="no" frameborder="0" style=""></iframe>' + ieULs[j].innerHTML);
				var ieMat = document.getElementById('iePad' + j + '');*/
				//	var ieMat = ieULs[j].childNodes[0];  alert(ieMat.nodeName); // also works...
				var ieMat = ieULs[j].firstChild;
				ieMat.style.width=ieULs[j].offsetWidth+"px";   // Doesn't work on IE5.x/Mac
				ieMat.style.height=ieULs[j].offsetHeight+"px";
				ieULs[j].style.zIndex="99";
			}
		}
		// End Internet Explorer bug fix.
		
		var oSubms = document.getElementById('site-nav').getElementsByTagName('LI');
		for (var i=0; i<oSubms.length; i++) {		
			oSubms[i].onmouseover=function() {
				if(this.className.indexOf('jshover')<0){
					addClassName(this,'jshover');
				}
			}
			oSubms[i].onmouseout=function() {
				removeClassName(this,'jshover');
			}
		}
	}

	// Home LS nav sub menu
	if (document.getElementById('home') || document.getElementById('home-sub')){
		oLSNav=document.getElementById('secondary-navigation')
		oSUbs=oLSNav.getElementsByTagName('LI');
		for (var i=0;i<oSUbs.length;i++) {
			if (oSUbs[i].className.indexOf('hasSub')>=0){
				oSUbs[i].onmouseover=function() {
					if(this.className.indexOf('makeVisible')<0){
						addClassName(this,'makeVisible');
					}
				}
				oSUbs[i].onmouseout=function() {
					removeClassName(this,'makeVisible');
				}
			}
		}		
	}
	
	// Close Toggle group
	if (document.getElementById('getmore-group')){
		oTG=document.getElementsByTagName('DIV');
		for (var i=0;i<oTG.length;i++){
			if (oTG[i].className=='more') {
				oTG[i].className='less';
			}
		}
	}
	
} // int close


// show hide dynamic divs
function toggle(obj){
	var oTarget = obj.parentNode.nextSibling.nodeType==1?obj.parentNode.nextSibling:obj.parentNode.nextSibling.nextSibling;
	if(oTarget.className=='less'){
		oTarget.className='more';
	}else{
		oTarget.className='less';
	}
}

/* Some functions to add and remove classNames cleanly - if
	an element has a className we don't want to overwrite it */
	
function addClassName(obj,newClassName){
	if(obj.className==''){
		CLname=newClassName;
	}else{
		CLname=obj.className+' '+newClassName;
	}
	obj.className=CLname
}

function removeClassName(obj,ClassName){
	var vRegX=new RegExp('\s*' +ClassName+ '*\\b');
	obj.className=obj.className.replace(vRegX, '');
}


// print popup placeholder
function popPrint(pURL){
	vMsg='TEST - Popup URL:\n'+pURL;
	alert(vMsg);
}
