var fullsizeImage = new Array();

function thumbSetup()	{
	var thumbs, thumbDivAttr

	// get all LIs in imagelist, loop over them 
	thumbs = document.getElementById('thumbnails').getElementsByTagName('div');
	for(i=0;i<thumbs.length;i++) {

		// Get the attributes for any referanced elementNode
		thumbDivAttr = thumbs[i].attributes;
		thumbLinkAttr = thumbs[i].getElementsByTagName('a')[0].attributes;
		thumbImgAttr = thumbs[i].getElementsByTagName('img')[0].attributes;

		// Assign an event listener to the preview div
		YAHOO.util.Event.addListener(thumbDivAttr.getNamedItem("id").value, "mouseover", fnCallback);

		// Assign the source of the contained IMG tag as the background image for the div.
		// This may seem an odd thing to do, but later we will remove the image from the div.
		document.getElementById(thumbDivAttr.getNamedItem("id").value).style.backgroundImage = "url(" + thumbImgAttr.getNamedItem("src").value + ")";

		// load the first image into the fullsize div		
		if(i==0) {
			document.getElementById("fullsize").style.backgroundImage = "url(" + thumbLinkAttr.getNamedItem("href").value + ")";
			document.getElementById("fullsize").style.display = "block";
			// thumbs[i].style.opacity = "0.5";
		} else {
			// alert("Preloading : " + thumbLinkAttr.getNamedItem("href").value);
			// Run a script to preload the additional full size images
			fullsizeImage[i] = new Image(68,45);
			fullsizeImage[i].src = thumbLinkAttr.getNamedItem("href").value;			
			
		}

		// Remove the anchor tag so the preview loads within the page if the broswer supports Javascript.
		// Doing so removes the image itself, which prevents the images from printing so I've comented out
		// the deletion for now. This means clicking on an image will open it in the browsser window.
		// thumbs[i].removeChild(thumbs[i].getElementsByTagName('a')[0]);		

	}
}

function resetAlpha() {
	var thumbs = document.getElementById('thumbnails').getElementsByTagName('div');

	for(i=0;i<thumbs.length;i++) {
		thumbs[i].style.opacity = "1.0";
	}
}

function fnCallback(e) { 
	// alert(this.id.substring(8));
	var fullImage = resourcePath + practiceArea + projectName + "/fullsize_" + String(this.id.substring(8)) + ".jpg";

	resetAlpha();

	this.style.opacity = "0.5";
	document.getElementById("fullsize").style.backgroundImage = "url("+fullImage+")";
}
