if ( document.getElementById ){
	if (!document.getElementById('home')){
		var num = genRand(4);
		document.write("<style type=\"text/css\" media=\"all\">");
		document.write("#titlebar {background-image: url(../img/s-titlebar-bg"+num+".gif)}");	
		document.write("</style>");		
	}
}

if (location.search == '?g'){
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../inc/glossary.css\" media=\"all\" />")
}

function initialize(){
	if ( document.getElementById ){
		if (!document.getElementById('home')){
			if (document.getElementById('glossary') && location.search == '?g'){
				initGlossaryPage();
			}
			if (document.all) sfTarget();
			initSubnav();
			initGlossary();
			initPDFWindow(); 
			initPopup();
			if (document.getElementById('Photo')) {
				document.getElementById('Photo').onload = initFade;
				loadAPI();
			}
		} else {
			initHPh();
		}
	}
}

function addAnEvent( target, eventName, functionName){
   eval('target.on'+eventName+'=functionName');
}

function initSubnav(){
	var nav = document.getElementById('nav');
	var navas = nav.getElementsByTagName('a');
	for (var a=0; a<navas.length; a++){
		var currenthref=String(navas[a].href);
		var currentloc=String(document.location);
		if (unescape(currenthref)==unescape(currentloc)){
			navas[a].className="current"
		}
	}
}

function initGlossary() {
	var mc = document.getElementById('content');
	var gas = mc.getElementsByTagName('a');
	for ( var z=0; z<gas.length; z++ ){            
  		if ( gas[z].className == "glossary" ){
			gas[z].setAttribute("title", "Define this term");
			addAnEvent(gas.item(z),'click',glossary);
		}
   }
}

function glossary(){
	var u = this.href;
	u = u.split("#");
	u = u[0]+"?g#"+u[1];
 	GlossaryWindow = window.open (u,"glossaryWindow","width=360,height=260,scrollbars=1,resizable=1");
	GlossaryWindow.focus ();
	return false;        
}

function initPDFWindow(){
	var links=document.getElementsByTagName("a");
	var linky;
	for(var i=0;i<links.length;i++){
		linky = links[i];
		if(linky.href.indexOf(".wpd") > 0 || linky.href.indexOf(".pdf") > 0 || linky.href.indexOf(".doc") > 0 || linky.href.indexOf("getdoc.aspx?dl=0") > 0){
			linky.title = "This document will open in a new window.";
			linky.innerHTML += "<img src=\"../img/ic-newwin.gif\" width=\"23\" height=\"13\" alt=\"\" />";
			addAnEvent(linky,'click',PDFWindow);
		}
	}
}

function PDFWindow(){
 		appWindow = window.open (this.href,"appWindow","width=600,height=400,toolbar=0");
		appWindow.focus ();
		return false;        
}

function initPopup(){
	var links=document.getElementsByTagName("a");
	var linkp;
	for(var i=0;i<links.length;i++){
		linkp = links[i];
		if(linkp.className == "popup"){
			linkp.title = "This document will open in a new window.";
			linkp.innerHTML += "<img src=\"../img/ic-newwin.gif\" width=\"23\" height=\"13\" alt=\"\" />";
			addAnEvent(linkp,'click',Popup);
		}
	}
}

function Popup(){
 		appWindow = window.open (this.href,"appWindow","width=600,height=400,toolbar=1,scrollbars=1,resizable=1");
		appWindow.focus ();
		return false;        
}

function sfTarget () {
	var sfEls=document.getElementsByTagName("div");
	var aEls = document.getElementsByTagName("a");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i]; aEls[j].onclick = function() {
					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget"; document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}

function initGlossaryPage(){
	var dl = document.getElementsByTagName("dl");
	var divs = dl[0].getElementsByTagName("div");
	for (var d=0; d<divs.length; d++){
		if (divs[d].className == "rtt"){
			divs[d].innerHTML = "<a href=\"javascript:window.close();\">close window</a>";
			divs[d].className = "close";
		}
	}
}

function initHPh(){
	var nav = document.getElementById('nav')
	var num = genRand(4);
	nav.innerHTML += "<img src=\"img/h-ph"+num+".jpg\" width=\"273\" height=\"180\" alt=\"\" id=\"photo\" />";
}

function genRand(x) {
 var range = x;
 return Math.floor(Math.random() * range) + 1;
}

window.onload=initialize;