startList = function() {
//alert("page loaded: onload event") ;
/* FIX IE HOVER */
if (document.all&&document.getElementById) {
navRoot = document.getElementById("mainmenu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }

	/* we are looking for items of class menuThumb with tag img with element with id photomenu */
	photomenuThumbs = getElementsByClass('menuThumb',document.getElementById('photomenu'),'img') ; 
	
	var item; 
	var parent ;
	var url; 
	
	var preloadImages = new Array() ;
	// no need to cache first item in photomenu as it is displayed by default, so start at x = 1
	
	for (x= 1 ; x < photomenuThumbs.length; x++) 
	{
		item = photomenuThumbs[x]; 
		parent = item.parentNode;
		url = parent.href;
		//alert("The url to load is " + url) ;
		var oneImage = new Image;
		oneImage.src = url; 
	}
	
	

	// alert("preload complete") ;
}

window.onload=startList;

/* UTILITY SCRIPT */

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	//alert ("the number of elements in the class is " + classElements.length) ; 
	return classElements;
}










/* following scripts povide gallery effects and are
developed from sample script in DOM scripting book */

/* swaps in image and resets caption
	function requires 
	- an image with id "placeholder" in html 
	- a text element with id "caption" in html
	
	passed
		link passed in should have title attribute set to the text for the caption 
	
*/ 


function unselectCurrentlySelectedPhotomenuItem() {
	var selectedItem = document.getElementById("photomenuSelected") ;
	selectedItem.setAttribute("id", null); 
}

function selectPhotomenuItem(item) {
	item.setAttribute("id", "photomenuSelected"); 
}


function crossFadeUsingTweenClass(currentImage, newImageURL, durationOfFade) {
	//alert("cross fading between two images with Tween class") ;


	/* pre-load the new image -> this approach doesn't work well on first load
	pic1= new Image; 
	pic1.src=newImageURL; 

	*/
	
	var seq = new Sequence() ;	
	//alert("cross fading Tween 2") ;
	// var fadeFrames = new Array(currentImage, newImage) ;
	//alert("cross fading Tween 3") ;
	
	//alert("current image is "+ currentImage) ;   // currentImage is an object current image is [object HTMLImageElement]
	//alert("new image URL is "+ newImageURL) ;			 // newImage is a url reference:	new image is ../../images/projectImages/letterbox/AlcoaBusiness/5.jpg
	
	//newImage = new Image;
	//newImage.src = newImageURL;


/* 	var newImage=document.createElement('img');
    newImage.src=newImageURL;
    newImage.alt="alt text";
    newImage.className='fader';
    newImage.style.left= 20 + 'px';
    newImage.style.top= 20 + 'px';
*/
	var placeholderSwapImage = document.getElementById("placeholderSwap");
	//alert("cross fading Tween 4") ;
	var placeholderImage = document.getElementById("placeholder");
	placeholderSwapImage.src = newImageURL; 
	// fadeFrames.length
	/* for (i= 0 ; i < 1; i++) { */
		//alert("i is "+i); 
		//alert("cross fading Tween 5") ;
			
		// var item = fadeFrames[ i ] ;
		var step = new Parallel() ;
		//alert("cross fading Tween 6") ;
		var currentImageOut = new OpacityTween(currentImage,Tween.regularEaseOut,100,0,2)   ;  // fade out current image
		//alert("cross fading Tween 7") ;
		var newImageIn = new OpacityTween(placeholderSwapImage,Tween.regularEaseOut,0,100,2)   ;  // fade out current image
		
		step.addChild(currentImageOut ) ;
		step.addChild(newImageIn ) ;
		
		seq.addChild(step) ;
		//seq.addChild(pause) ;
		//alert("cross fading Tween 8") ;
		
	/* } */
	// alert("start seq");
	// currentImageOut.start();
	 seq.onMotionFinished = function(){ placeholderImage.src = newImageURL } ;				  // {alert( 'onMotionFinished' )}; placeholderImage.src = newImageURL;
		//alert("cross fading Tween 9") ;
		seq.start() ;
		//currentImageOut.start();

		//alert("cross fading Tween 10") ;
	
	
	// when it's all done swap the new URL into the placeholder 
	
	//alert("end") ;
}


function showImageWithCrossfade(aLink) {
	//alert("called showImageWithCrossfade") ;

	// get the image source
	var imageSource = aLink.getAttribute("href") ;
	

	var placeholder= document.getElementById("placeholder") ;
	
	// use the crossfade script
	// arguments: currentImage, newImage, fade duration, new alt text
	
	
	/* TEMPORARILY REPLACE WITH CROSSFADE TWEEN */
		/*	crossfade(placeholder, imageSource, '1', 'alt') ; */
		
	crossFadeUsingTweenClass(placeholder, imageSource, 1) ;
	// placeholder.setAttribute("src", imageSource); 
	
	//alert("crossFadeUsingTweenClass returned to showImageWithCrossfade") ;
	
	//alert("swap caption") ;		
	// swap the caption
	var newCaption = aLink.getAttribute("title") ;
	var caption = document.getElementById("caption") ;
	caption.firstChild.nodeValue = newCaption; 
	
	
	// update the image menu
		
		// get element whose current id is selected, and make it un-selected
		 unselectCurrentlySelectedPhotomenuItem() ; 
		

		// set the parentNode of the a element (the li element) to selected
		selectPhotomenuItem(aLink.parentNode); 
		
		// test
		// aLink.setAttribute("class", "red") ;
		
		/* 
		var selItem = document.getElementById("selected") ;
		var child = selItem.childNodes[0] ; 
		alert ( child.getAttribute("href") ) ;
		*/
	//alert("reached ebd") ;		
	return false;
}


function showImageWithCrossfadeNoCaption(aLink) {

	// get the image source
	var imageSource = aLink.getAttribute("href") ;
	

	var placeholder= document.getElementById("placeholder") ;
			
	crossFadeUsingTweenClass(placeholder, imageSource, 1) ;
	
	return false;
}

function swapThisAtributeToElementWithID(thisObj, attributeName, id) {
	var title = thisObj.getAttribute(attributeName) ;
	var elementWithID = document.getElementById(id) ;
	elementWithID.firstChild.nodeValue = title; 
}

function setProjectNameHoverToTitleOfThis(obj) {
	swapThisAtributeToElementWithID(obj, "title", "projectNameHover") ;
} 

function toggleStyleOfElementWithIDUsingSuffix(id, suffix) {
	// alert("called toggleStyleOfElementWithIDUsingSuffix") ;
	var item = document.getElementById(id) ; 
	if ( item != null ) {
		// alert("found projectInformationHidden") ;
		item.id = 	id+suffix;
	} else {
		item = document.getElementById(id+suffix) ; 
		if ( item != null ) {
			item.id = id;
		}
	}

}

function showAwardsUsingAIA(aLink) {
	
	toggleStyleOfElementWithIDUsingSuffix('awards', 'Hidden'); 
	<!-- use the function above to show the awards image, which must be set as the href in the html--> 
	showImageWithCrossfade(aLink) ;	
}

