var updateIMG = function (node) {
	var images = node.getElementsByTagName('IMG');
	for (var i = 0; i < images.length; i ++) {
		if (images[i].src.search(/\.png$/i) > 0) {
			images[i].style.width = images[i].width + "px";
			images[i].style.height = images[i].height + "px";
			images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+images[i].src+"', sizingMethod='scale')";
			images[i].src = "/images/spacer.gif";
		}
	}
};

var doHide = function (nodeId) {
	var obj = document.getElementById(nodeId);
	if (obj) {
		if (obj.className.search(/ over/i) >= 0) {
			obj.className = obj.className.replace(" over","");
		}
	}
};

var updateLI = function (node) {
	var listItems = node.getElementsByTagName('LI');
	for (var i in listItems) {
		if (!listItems[i].id) {
			listItems[i].id = ("nav-li-" + i);
		}
		listItems[i].onmouseover = function () {
			if (this.className.search(/over/i) < 0) {
				this.className += " over";
			}
			if (this.waiting) {
				clearTimeout(this.waiting);
			}
		}
		listItems[i].onmouseout = function () {
			this.waiting = setTimeout("doHide('" + this.id + "')", 50);
		}
	}
};

var modifyDocument = function () {

	// fixes IE6-only CSS background image flicker when altering dynamically with js
	try { document.execCommand("BackgroundImageCache", false, true); } catch (err) { };
	
	// modify images in content area and nav LI hovers
	if (document.getElementsByTagName && document.getElementById) {
		var docContent = document.getElementById("content");
		if (docContent != null) {
			updateIMG(docContent);
		}
		var docNav = document.getElementById("nav");
		if (!docNav) {
			docNav = document.getElementById("navigation");
		}
		if (docNav != null) {
			updateLI(docNav);
		}
	}
	
};

if (document.all && navigator.userAgent.search(/msie [65]{1}\./i) >= 0) {
	if (window.onload) {
		var beforeModifyIEFunction = window.onload;
		window.onload = function () {
			beforeModifyIEFunction();
			modifyDocument();
		};
	} else {
		window.onload = modifyDocument;
	}
}

