// ACM Webpage JavaScript
// written by Darren W. Hill

// handleOnLoad()
//
// This function is a generic handler for the OnLoad event.  It will call any
// number of functions we want to implement when the page loads.

function handleOnLoad() {
	navbarIntelligence();
//	if (ajaxFeed)
//		ajaxFeed();
}

// navbarIntelligence()
//
// This function makes the navbar "aware" of our browser location.  Currently,
// the anchor style is changed to make the link underlined if we are on the
// page it points to.

function navbarIntelligence() {
	if (document.getElementById) {	// make sure browser understands HTML DOM
		var navbarlist = document.getElementById("navbar").getElementsByTagName("li");

		if (navbarlist) {	// if we have an object to play with
			var i;
			for (i = 0; i < navbarlist.length; i++) {
				var anchor;
				anchor = navbarlist[i].getElementsByTagName("a");

				if (anchor && anchor[0].href == location.href) {
					navbarlist[i].style.listStyleType = "square";
					break;
				} else {
					navbarlist[i].style.listStyleType = "none";
				}
			}
		}
	}
}

// markExternalLinks() EXPERIMENTAL
//
// This function detects external links and does stuff to them.

function markExternalLinks() {
	if (document.getElementById) {	// make sure browser understands HTML DOM
		var extlink = document.getElementById("content").getElementsByTagName("a");
		var index = 0;
		var homeurl;

		index = location.href.indexOf("//");			// find the protocol:// slashes
		index += 2;										// skip past them
		index = location.href.indexOf("/",index);		// find the next slash
		homeurl = location.href.substring(0,index+1);	// get our home URL to compare links to

		if (extlink && (homeurl.length > 0) ) {
		// We have external links and a sane homeurl to compare to
			for (var i = 0; i < extlink.length; i++) {
				if (extlink[i].href.indexOf("//") != -1 &&		// not a mailto
					extlink[i].href.indexOf(homeurl) == -1) {	// does not match homeurl
					extlink[i].style.paddingLeft = "16px";
					extlink[i].style.backgroundImage = "url(extarrow.png)";
					extlink[i].style.backgroundRepeat = "no-repeat";
					extlink[i].title += " (external link)";
				}
			}
		}
	}
}

// set up onLoad event handler
window.onload = handleOnLoad;
