/******************************
*
* Javascript for www.alanbumpus.com
*
* @date: 2007-05
*
* some code may be borrowed or heavily inspired by Jeremy Keith's DOM Scripting (2005) from Friends of Ed.
*
*********************************/


/* custom stuff */

/* this function drives the main navigation */
function prep_mainNavRO(){
	if(!document.getElementsByTagName || !document.getElementById){
		return false;
	}
	if(document.getElementById("L1nav")){
		var myHeader = document.getElementById("L1nav");
		var links = myHeader.getElementsByTagName("a");
		for(var i=0; i<links.length; i++){
			links[i].onmouseover = function(){
				this.firstChild.src = this.firstChild.src.substring(0, this.firstChild.src.lastIndexOf(".")) + "_f2.gif";
			}
			links[i].onmouseout = function() {
				this.firstChild.src = this.firstChild.src.substring(0, this.firstChild.src.lastIndexOf("_")) + ".gif";
			}
		}
	}
}
addLoadEvent(prep_mainNavRO);

/* function to drive the ability to move through multiple images in a project */
function prep_imageLinks(){
	if(!document.getElementsByTagName || !document.getElementById){
		return false;
	}
	if(document.getElementById("l3nav")){
		var myHeader = document.getElementById("l3nav");
		var myTarget = document.getElementById("thework");
		var links = myHeader.getElementsByTagName("a");
		
		for(var i=0; i<links.length; i++){
			 links[i].onclick = function(){
				 var newImage;
				 newImage = myTarget.style.backgroundImage.substring(0, myTarget.style.backgroundImage.lastIndexOf("_")) + "_" + this.name + ".jpg')";
				 newImage = newImage.replace('(', '(\'');
				 //newImage = "#333";
				 myTarget.style.background = newImage;
			}
		}
	}
}
addLoadEvent(prep_imageLinks);



/* javascript to preload the full-size images on the portfolio/project.php pages * takes 4 image arguments to correspond to the 4 possible images in the portfolio */
function portfolioPreloader(img1, img2, img3, img4) {
	var i = 0;
	
	imageObj = new Image();
	
	//set image list
	images = new Array();
	images[0] = "i/work/" + img1;
	images[1] = "i/work/" + img2;
	images[2] = "i/work/" + img3;
	images[3] = "i/work/" + img4;
	
	// start preloading
	for(i = 0; i<=3; i++) {
		imageObj.src=images[i];
	}
}



/* global resources */

/* function to simply multiple functions in window.onload
* DOM Scripting (103) :: Simon Willison (http://simon.incution.com) */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}
	else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}


/* generic popup window function to act as an interface to window.open() 
* DOM Scripting (88) */
function popUp(winURL, title, w, h){
	d = "width=" + w + ",height=" + h;
	window.open(winURL, title, d);
}


