// JavaScript Document
function startScripts() {
	navbar();
	loadXMLDoc(sils_url);
}

var sils_url="/silhouettes.xml";
var req;

function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			changeSil();
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
}

function changeSil() {
	var sls = req.responseXML.getElementsByTagName("sil");
	var j = Math.round((sls.length - 1)*Math.random());
	document.getElementById('home_sil').src = sls[j].getElementsByTagName('source')[0].firstChild.nodeValue;
	document.getElementById('home_sil').alt = sls[j].getElementsByTagName('alt')[0].firstChild.nodeValue;
	
}

function navbar() {
	if (document.all&&document.getElementById) {
		var collUL = document.getElementsByTagName("UL");
		for (j=0; j<collUL.length; j++) {
			if (collUL[j].className.indexOf('nav')!=-1) {
				navRoot = collUL[j];
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() { this.className+="over" }
						node.onmouseout=function() { this.className=this.className.replace("over", "") }
					}
				}
			}
		}
	}
}

window.onload=startScripts;


