var linkArray = new Array("home", "about", "dj", "perf", "anim", "prog", "web");
var numLinks = linkArray.length;
var cutVert;
var cutHoriz;

window.onload=function(){
	cutVert = document.body.clientHeight / 2;
	cutHoriz = document.body.clientWidth / 2.5;
	initLinks();
	initScrollLayer(vertical);
	if(selected == 'home') {
		homeImageLoad();
		animator();
	}
	polling();
}

function getIndex(myArray, match) {
	var i=0;
	for (i=0;i<myArray.length;i++) {
		if(myArray[i] == match && (i+1) < myArray.length)
			return myArray[i + 1];
	}
	return null;
}
function getElement(id) {
	if(document.layers)
    	return document[id];
  	else if(document.all)
    	return document.all[id];
  	else if(document.getElementById)
    	return document.getElementById(id);
}
function rollover (id, on) {
	var cell = getElement(id);
	var cell_class = cell.className;
	if (cell_class != 'HL') {
		var color = on ? "#333" : "#000";
		cell.style.background = color;
		if (on){
			cell.style.borderLeft = ".15em dashed #fff";
			cell.style.borderRight = ".15em dashed #fff";
		} else{
			cell.style.borderLeft = "0px dashed #fff";
			cell.style.borderRight = "0px dashed #fff";
		}
	}
	return true;
}

function clicker(id) {

	procLink(id);
    return true;
}

function procLink(action) {
    document.linkform.changeContent.value = action;
    document.linkform.submit();
}

function initLinks() {
	//var temp = getElement('home');
	//temp.innerHTML = "the link is: " + selected;
	if(selected != "home") {
		var cellOn = getElement(selected);
		cellOn.style.background = "#000";
		cellOn.style.border = "0px";
		if(selected != linkArray[numLinks - 1])
			cellOn.style.borderTop = ".15em dashed #fff";
		var index = getIndex(linkArray, selected);
		//temp.innerHTML = "the index is: " + index;
		if(index != null) {
			var cellBelow = getElement(index);
			cellBelow.style.borderTop = ".15em dashed #fff";
		} else {
			var cellBelow = getElement(linkArray[numLinks-1]);
			cellBelow.style.borderBottom = ".15em dashed #fff";
			cellBelow.style.borderTop = ".15em dashed #fff";
		}
		var cell = getElement(selected);
			cell.style.border = ".2em solid #fff";
		cell.style.background = "#666";
		cell.className = "HL";
	
		index = getIndex(linkArray, selected);
		if(index != null) {
			var cellBelow = getElement(index);
			cellBelow.style.borderTop = "0px dashed #fff";
		}
	}
}

function updatePlayer(id) {
    document.mp3Player.playerID.value = id;
    document.mp3Player.submit();
}

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

/************   scrolling layers   ************/

function initScrollLayer(vertical) {
  var wndo = new dw_scrollObj('wn', 'middlebox');
  //dw_scrollObj.GeckoTableBugFix('wn');
  //wndo.shiftTo(document.getElementById('middlebox'), 0, vertical);
  //document.getElementById('middlebox').style.top = wndo.y = vertical;
  //wndo.glideTo(0, -200, 1);
}

/************   popup windows   ************/
function popUp(URL, width, height) {
	var winWidth = document.body.clientWidth;
	var winHeight = document.body.clientHeight;
	var x = (winWidth/2) - (width/2);
	var y = (winHeight/2) - (height/2);
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + 
		"', 'toolbar=0,scrollbars=0,location=0,statusbar=0,status=0,directories=0,menubar=0,resizable=0,width=" +
		width + ",height=" + height + ",left=" + x + ",top=" + y + "');");
}
function PopupPic(sPicURL, width, height) { 
	var winWidth = document.body.clientWidth;
	var winHeight = document.body.clientHeight;
	var x = (winWidth/2) - (width/2);
	var y = (winHeight/2) - (height/2);
	window.open("popup.htm?" +
	sPicURL, "", "toolbar=0,scrollbars=0,location=0,statusbar=0,status=0,directories=0,menubar=0,resizable=0,HEIGHT=" +
	height + ",WIDTH=" + width + ",left=" + x + ",top=" + y);
}



/************   scaling elements   ************/
function scaleWidth() {
	var windowWidth = document.body.clientWidth - 320;
        var windowHeight = document.body.clientHeight - 75;
        var contentBox = getElement('box');
        var left = (windowWidth - (windowWidth * .8)) / 2;
        contentBox.style.left = left + "px";
        contentBox.style.top = (windowHeight - (windowHeight * .8)) / 2 + "px";
        contentBox.style.right = (windowWidth - (windowWidth * .8)) / 2 + "px";
        contentBox.style.bottom = (windowHeight - (windowHeight * .8)) / 2 + "px";

	return true;
}

