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



//window.onload = prep_mainNavRO;


/* custom stuff */

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

/* function to handle thumbnails replacing main image in portfolio/project.php */
function prep_thumbLinks(){
	if(!document.getElementsByTagName || !document.getElementById){
		return false;
	}
	if(document.getElementById("portfoliomainimage")){
		var bullseye = document.getElementById("portfoliomainimage");
		if(document.getElementById("prjthumbs")){
			var box = document.getElementById("prjthumbs");
			var links = box.getElementsByTagName("a");
			for (var i=0; i<links.length; i++){
				links[i].onclick = function(){
					//alert("click");
					
					bullseye.src = "../i/portfolio/fullsize/" + this.firstChild.src.substring(this.firstChild.src.lastIndexOf("/"));
					
				}
			}
		}
	}
}
addLoadEvent(prep_thumbLinks);





/* function to handle the L2 navigation on the /art/ page */
function prep_artLinks(){
	if(!document.getElementsByTagName || !document.getElementById){
		return false;
	}
	if(document.getElementById("artsubnav")){
		var artsubnav = document.getElementById("artsubnav");
		var links = artsubnav.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(".")) + "_f3.gif";
			}
			links[i].onmouseout = function() {
				this.firstChild.src = this.firstChild.src.substring(0, this.firstChild.src.lastIndexOf("_")) + ".gif";
			}
		}
	}
}
addLoadEvent(prep_artLinks);


/* function to resize container on the /portfolio/index.php page 
function resizeContainer(){
	var frame = document.getElementById("portfolioThumbs");
	var maxHeight = frame.height;
	
	//var maxHeight = document.body.parentNode.scrollHeight;
	var frame2 = document.getElementById("container");
	frame2.style.height = maxHeight + "px";
}
addLoadEvent(resizeContainer);
*/


/* 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);
}


/* 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] = img1;
	images[1] = img2;
	images[2] = img3;
	images[3] = img4;
	
	// start preloading
	for(i = 0; i<=3; i++) {
		imageObj.src=images[i];
	}
}


