// touchles javascript™ -- no event handlers in html

window.onload = kickOff;
window.onresize = pageCalc;

var curLeft = 0;
var logoObj;
var aAll;


var theImages = new Array()

//Random-loading images
theImages[0] = 'images/imagebox1.jpg' // replace with names of images
theImages[1] = 'images/imagebox2.jpg' // replace with names of images
theImages[2] = 'images/imagebox3.jpg' // replace with names of images
theImages[3] = 'images/imagebox4.jpg' // replace with names of images
theImages[4] = 'images/imagebox5.jpg' // replace with names of images
theImages[5] = 'images/imagebox6.jpg' // replace with names of images
theImages[6] = 'images/imagebox7.jpg' // replace with names of images
theImages[7] = 'images/imagebox8.jpg' // replace with names of images
theImages[8] = 'images/imagebox9.jpg' // replace with names of images
theImages[9] = 'images/imagebox10.jpg' // replace with names of images
theImages[10] = 'images/imagebox11.jpg' // replace with names of images

var j = 0
var p = theImages.length;
var preBuffer = new Array()

for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
    var whichImage = Math.floor(Math.random()*p);

function showImage(){
    //if(whichImage==0){
document.write('<div style="width:100%; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// }
// else if(whichImage==1){
// document.write('<div style="width:100%; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// }
// else if(whichImage==2){
// document.write('<div style="width:100%; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// }
// else if(whichImage==3){
// document.write('<div style="width:100%; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// }
// else if(whichImage==4){
// document.write('<div style="width:100%; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// }
// else if(whichImage==5){
// document.write('<div style="width:100%; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+theImages[whichImage]+') repeat-x 50% 0;">');
// }

}

var upImages = new Array()

//Random-loading images
upImages[0] = '../images/imagebox1.jpg' // replace with names of images
upImages[1] = '../images/imagebox2.jpg' // replace with names of images
upImages[2] = '../images/imagebox3.jpg' // replace with names of images
upImages[3] = '../images/imagebox4.jpg' // replace with names of images

var j = 0
var q = upImages.length;
var upBuffer = new Array()

for (i = 0; i < q; i++){
upBuffer[i] = new Image()
upBuffer[i].src = upImages[i]
}
var whchImage = Math.round(Math.random()*(q-1));

function subImage(){
    //if(whchImage==0){
document.write('<div style="width:100%; background:#333333 url(../'+theImages[whichImage]+') repeat-x 50% 0;">');
document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url(../'+theImages[whichImage]+') repeat-x 50% 0;">');
//}
// else if(whchImage==1){
// document.write('<div style="width:100%; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// }
// else if(whchImage==2){
// document.write('<div style="width:100%; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// }
// else if(whchImage==3){
// document.write('<div style="width:100%; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// }
// else if(whchImage==4){
// document.write('<div style="width:100%; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// document.write('<div style="width:98%; max-width:900px; height:105px; margin:auto; padding:0; background:#333333 url('+upImages[whchImage]+') repeat-x 50% 0;">');
// }

}

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";
           	}
        }
		// fix ie's lack of support for css :focus so tabbers see skip links on focus
		if (navigator.appName == "Microsoft Internet Explorer" && aAll[i].className == "skip") {
			var restoreColor = aAll[i].style.color;
			var restoreBorder = aAll[i].style.borderBottom;
			aAll[i].onfocus = function() {this.style.color = "#999999"; this.style.borderBottom = "1px solid #999999";}
			aAll[i].onblur = function() {this.style.color = restoreColor; this.style.borderBottom = restoreBorder;}
		}
     }
	// fixes in-page link bug for Internet Explorer
	if (navigator.appName == "Microsoft Internet Explorer") {
		getElementsByClass("target");
	}
    // calculate certain elements for placement:
	pageCalc();
}

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() {
	// make the column depths match so they have full-height attributes (bg colors, etc):
	var colArray = new Array(["nav",0],["main",0],["sidebar",0]);
	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();
}

function getElementsByClass(searchClass,node,tag) {
	// fixes in-page link bug for Internet Explorer; first find all destinations (elements with classname "target"):
    var classElements = new Array();
	if ( node == null ) {
			node = document;
	}
	if ( tag == null ) {
			tag = '*';
	}
	var elAll = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (var i = 0, j = 0; i < elAll.length; i++) {
		if (pattern.test(elAll[i].className)) {
			classElements[j] = elAll[i];
			j++;
		}
	}
	// then insert what is an invalid attribute for most elements, with an invalid value to boot:
	for (var i=0; i<classElements.length; i++) {
		classElements[i].setAttribute("tabIndex",-1)
	}
}
