var imageViewerWindow;
var imageToView;

// if this browser supports image preloading, then preload the images
if (document.images) {
	// active images
	contactOn     = new Image();
	drawingOn     = new Image();
	galleriesOn   = new Image();
	informationOn = new Image();
	sculptureOn   = new Image();
	contactOn.src     = "images/prototype_06_hover.gif";
	drawingOn.src     = "images/prototype_05_hover.gif";
	galleriesOn.src   = "images/prototype_07_hover.gif";
	informationOn.src = "images/prototype_02_hover.gif";
	sculptureOn.src   = "images/prototype_04_hover.gif";

	// inactive images
	contactOff     = new Image();
	drawingOff     = new Image();
	galleriesOff   = new Image();
	informationOff = new Image();
	sculptureOff   = new Image();
	contactOff.src = "images/prototype_06.gif";
	drawingOff.src = "images/prototype_05.gif";
	galleriesOff.src   = "images/prototype_07.gif";
	informationOff.src = "images/prototype_02.gif";
	sculptureOff.src   = "images/prototype_04.gif";
}

function imgOn(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "On.src");
	}
}

function imgOff(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "Off.src");
	}
}

function popupImage(imageUrl) {
	var windowName = "ImageViewer";
	imageToView = new Image();
	imageToView.src = "images/" + imageUrl + ".jpg";
	imageViewerWindow = window.open(imageToView.src,windowName,"height=100,width=100,status=no,toolbar=no,menubar=no,location=no");
	resizeToFitImage();
	
}

function resizeToFitImage() {
	if ( imageToView.width != 0 && imageToView.height != 0 ) {
		imageViewerWindow.resizeTo(imageToView.width + 20,imageToView.height + 60);
		centerWindow(imageViewerWindow);
	} else {
		setTimeout("resizeToFitImage()",100);
	}
}

function includeImage(imageUrl) {
	document.write("<a href='javascript:popupImage(\"" + imageUrl + "\")' class='thumbnail'>");
	document.write("<img src='images/" + imageUrl + "_thumb.jpg' class='thumbnail'>");
	document.write("</a>");
}

function centerWindow(popupWindow) {
	var width = (screen.width - popupWindow.innerWidth) / 2;
	var height = (screen.height - popupWindow.innerHeight) / 2; 
	
	popupWindow.moveTo(width,height);
}
