function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

// emulate hover on li elements in ie6
sfHover = function() {
	var sfEls = document.getElementById('nav').getElementsByTagName('LI');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=' sfhover';
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(' sfhover\\b'), '');
		}
	}
}
if (window.attachEvent && navigator.userAgent.indexOf('MSIE 7') == -1) window.attachEvent('onload', sfHover);

// force ie6 to cache background images
function bgrCache() {
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}
if (window.attachEvent) window.attachEvent('onload', bgrCache);

// set menu items widths 
function setWidth() {
	var maxW;
	uls = document.getElementById('nav').getElementsByTagName('ul');
	for (i=0; i<uls.length; i++) {
		lis=uls[i].getElementsByTagName('li')
		for (var j=0; j<lis.length; j++) {
			lis[j].style.width = '1000px';
			lis[j].firstChild.style.display = 'inline';
			lis[j].firstChild.style.width = 'auto';
		}
		maxW = 0;
		for (var j=0; j<lis.length; j++) {
			if((maxW < lis[j].firstChild.offsetWidth) && (lis[j].parentNode == uls[i])) maxW = lis[j].firstChild.offsetWidth;
		}
		newWidth = maxW + 'px';
		newMargin = maxW + 11 + 'px';
		uls[i].style.width = newWidth;
		for (var j=0; j<lis.length; j++) {
			lis[j].style.width = '100%';
			lis[j].firstChild.style.display = 'block';
			lis[j].firstChild.style.width = '100%';
		}
		subUls=uls[i].getElementsByTagName('ul');
		for (var j=0; j<subUls.length; j++) {
			subUls[j].style.marginLeft = newMargin;
		}
	}
}

// try to run the script before the whole page is loaded
function $(v) { return(document.getElementById(v)); }
function mkLoad() {
	var v=new Date().getTime();
    if(!$('mainContentBlock')) { 
		if(v-loadTime<=7000) {
			setTimeout("mkLoad()",50);
		} else {
			addLoadEvent(setWidth);
		}
	} else {
		setWidth();
	}
}
var loadTime=new Date().getTime();
setTimeout("mkLoad()",10);

