var pages = new Array(
			"index.html",
			"projects.html",
			"jasperServerRedesign.html",
			"JIF.html",
			"workAtApple.html",
			"DMX.html",
			"phoenix.html",
			"Schwab_VisionGraphic.html",			
			"techIllustrations.html",
			"capabilitiesPresentation.html",
			"carnaval.html",
			"walterHaasPark.html",
			"process.html",
			"Process_ObservationsAndSynthesis.html",
			"Process_Personas.html",
			"Process_ScenariosAndStoryboards.html",
			"Process_Prototyping.html",
			"Process_Specification.html"
			);


var imageWindow;


var loadPage = function(which) {
	var theIndex = Number(which);
	window.location = pages[theIndex];
}


var getCurrentPage = function() {
	var currentPath = String(window.location);
	var currentPage = currentPath.substr(currentPath.lastIndexOf("/") + 1);
	if (!currentPage) { //then window is pointing to server root, as in www.timsheiner.com
		currentPage = "index.html";
	}
	return currentPage;
}

var setCurrent = function() {
	var currentPage = getCurrentPage();
	
	for (var i = 0; i < pages.length; i++) {
		if (pages[i] == currentPage) {
			document.getElementById(i).className += " current";
			return;
		}
	}
}

var addImageWindowToImages = function() {
	var theImages = document.getElementsByTagName("img");
	var imageWindow;
	var emptyString;
	
	for (var i = 0; i <  theImages.length; i++) {
		if (theImages[i].className.search("noFullSize") == -1) {
		
			theImages[i].className += "clickableImage";
			
			theImages[i].onclick = function() {
				theSource = "images/fullSize/" + this.src.substr(this.src.lastIndexOf("/") + 1);
				theURL = "imgWin.html?" + theSource;
				window.open(theURL ,"imgWin" ,"resizable=1,height=300,width=300");
			}
		}
	}
}
	

var addNavigationToTOC = function() {
	var theTOC = document.getElementById("toc");
	var theItems = theTOC.getElementsByTagName("LI");
	
	for (var i = 0; i <  theItems.length; i++) {
		
		theItems[i].className += " up";
		
		theItems[i].onmouseover = function() {
			this.className = this.className.replace("up","over");
			return false; 
			}

		theItems[i].onmousedown = function() {
			if(this.className.search("over") != -1) {
				this.className = this.className.replace("over","down");
			}
			if(this.className.search("up") != -1) {
				this.className = this.className.replace("up","down");
			}
			return false; 
			}
			
		theItems[i].onmouseup = function() {
			this.className = this.className.replace("down","up");					
			loadPage(this.id);
			return false; 
			}

		theItems[i].onmouseout = function() {
			if(this.className.search("over") != -1) {
				this.className = this.className.replace("over","up");
			}
			if(this.className.search("down") != -1) {
				this.className = this.className.replace("down","up");
			}
			
			
			return false; 
			}
	}	
}

/*

function handleKeys(e) {
//credit: http://santrajan.blogspot.com/2007/03/cross-browser-keyboard-handler.html
    var character;
    var evt = (e) ? e : window.event;       //IE reports window.event not arg
    if (evt.type == "keydown") {
        character = evt.keyCode;
        if (character < 16 ||                    // non printables
            (character > 16 && character < 32) ||     // avoid shift
            (character > 32 && character < 41) ||     // navigation keys
            character == 46) {                   // Delete Key (Add to these if you need)
            //handleNonChar(character);            // function to handle non Characters
            nonChar = true;
        } else
            nonChar = false;
    } else {                                // This is keypress
        if (nonChar) return;                // Already Handled on keydown
        character = (evt.charCode) ?
                   evt.charCode : evt.keyCode;
        if (character > 31 && character < 256)        // safari and opera
            handleChar(character);               //
    }
}
*/


function handleKeys(e) {
    var evt = (e) ? e : window.event;       //IE reports window.event not arg
    var character = (evt.charCode) ? evt.charCode : evt.keyCode;
        if (character > 31 && character < 256) { 
            handleChar(character);
    }
}



var handleChar = function(character) {
	if (character == 37) {
	//if (character == 104) {
		loadPreviousPage();
	} else if (character == 39) {
	//} else if (character == 106) {
		loadNextPage();
	}
}



var loadNextPage = function() {
	var currentPage = getCurrentPage();
	
	for (var i = 0; i < pages.length; i++) {
		if (pages[i] == currentPage) {
			if ((i + 1) < pages.length) {
				document.location.href = pages[i + 1];
			} else {
				document.location.href = pages[0];
			}
			return;
		}
	}
}

var loadPreviousPage = function() {
	var currentPage = getCurrentPage();
	
	for (var i = 0; i < pages.length; i++) {
		if (pages[i] == currentPage) {
			if ((i - 1) < 0) {
				document.location.href = pages[pages.length - 1];
			} else {
				document.location.href = pages[i - 1];
			}
			return;
		}
	}
}
	
