// touchles javascript™ -- no event handlers in html

window.onload = kickOff;
window.onresize = pageCalc;

var curLeft = 0;
var logoObj;
var startWidth;
var aAll;
var aContent;
var contentCols;

function kickOff() {
	aAll = document.getElementsByTagName("a");
	// disable and change color of active page's link
    for (var i=0; i<aAll.length; i++) {
        if (window.location.href.split("#")[0] == aAll[i].href) {
            aAll[i].onclick = function() {if (this.blur) {this.blur();} return false;}
            aAll[i].style.cursor = "text";
			aAll[i].style.borderBottom = "none";
			aAll[i].style.color = "#9999aa";
            if (aAll[i].className == "site") {
				aAll[i].style.color = "#ffffff";
           	}
			/*if (aAll[i].className == "promo") {
				aAll[i].style.color = "#333333";
           	}*/
        }
        // set Back link for js enabled browsers
        if (aAll[i].id == "back") {
        	aAll[i].firstChild.nodeValue = "Back";
			aAll[i].onclick = function() {history.back(); return false;}
		}
     }
    contentCols = document.getElementById("contentbox");
    aContent = contentCols.getElementsByTagName("a");
	for (var i=0; i<aContent.length; i++) {
		if (aContent[i].firstChild && aContent[i].firstChild.nodeName == "IMG") {
			continue;
		}
		if (aContent[i].href.indexOf(".pdf") != -1) {
			linkImg(i,"url(/cob/images/pdflink.gif)","100% 2px","no-repeat","13px","5px");
		}		
		else if (aContent[i].href.indexOf("cob.") == -1) {
			linkImg(i, "url(/cob/images/extlink.gif)","100% 2px","no-repeat","13px","5px");
		}
	
	}
    // calculate certain elements for placement:
	pageCalc();
}

function linkImg (i,url,pos,rep,pad,mar) {
	aContent[i].style.backgroundImage = url;
	aContent[i].style.backgroundPosition = pos;
	aContent[i].style.backgroundRepeat = rep;
	aContent[i].style.paddingRight = pad;
	aContent[i].style.marginRight = mar;
}

function findPos() {
	// position logo-aligned bg image relative to window width accounting for browsers' differing def of offsetParent:
	logoObj = document.getElementById("footerbox").firstChild.firstChild;
	if (logoObj.offsetParent) {
		curLeft = logoObj.offsetLeft;
		while (logoObj.offsetParent!=null) {
			logoObj = logoObj.offsetParent;
			curLeft += logoObj.offsetLeft;
		}
	}
	document.getElementsByTagName("body")[0].style.backgroundPosition = curLeft - 649 + "px";
}

function equalCol() {
	var colArray = new Array(["nav",0],["main",0],["sidebar",0]);
	// make the column depths match so they have full-height attributes (bg colors, etc):
	for (var i=0; i<colArray.length; i++) {
		// everyone expresses their natural column heights:
		document.getElementById(colArray[i][0]).style.height = "100%";
		// detect natural column heights in px and store in the array:
		colArray[i][1] = document.getElementById(colArray[i][0]).offsetHeight;
	}
	// determine tallest column in the array:
	var tallCol = Math.max(colArray[0][1],colArray[1][1],colArray[2][1]);
	// make all columns the height of the tallest column:
	for (var i=0; i<colArray.length; i++) {
		if (document.getElementById(colArray[i][0]).offsetHeight == tallCol) {
			var fullCol = document.getElementById(colArray[i][0]);
		}
		document.getElementById(colArray[i][0]).style.height = tallCol + "px";
	}
	fullCol.style.height = "100%"
}

function pageCalc() {
	// position logo-aligned bg image relative to window width:
	findPos();
	// make the column depths match so they have full-height attributes:
	equalCol();
}




