running=0;
current=-1;
isNav=false;
isW3C=false;
isExp=false;
isOpera=false;
isNOT=false;
isMac=false;
isNN4=document.layers?1:0;
isIE=document.all?1:0;

// Detect browser and define pre/suf-fixes
browser=navigator.appName;
version=navigator.appVersion;
useragent=navigator.userAgent;
Vmajor=parseInt(navigator.appVersion);
Vminor=parseFloat(navigator.appVersion);

if (useragent.indexOf('Opera') != -1) {
	isOpera=true;
	pre='all';
	suff='.style';
}
else if (browser=="Netscape") {
	if (Vmajor==4)
	{
		isNav=true; pre='layers.'; suf='';
	}
	else if (Vmajor>=5)	isW3C=true;
	else isNOT=true;
}
else if (browser=="Microsoft Internet Explorer") {
	if ( version.indexOf('MSIE 5.0; Macintosh;') != -1 )  {
		isExp=true;
		pre='all.';
		suf='.style';
	}
	// IE 4 to 5.5 return 4 as the version
	else if ( (Vmajor==4) ) {
		isExp=true;
		pre='all.';
		suf='.style';
	}
	else isNOT=true;
} else {
	isW3C=true;
}

if (version.indexOf('Mac') != -1) isMac=true;


function mouseHandler(evt) {
	if (isNN4) {
		mouseX=evt.pageX;
		mouseY=evt.pageY;
	} 
	else if (isIE) {
		mouseX=window.event.clientX;
		mouseY=window.event.clientY;
	}	
	else if (isOpera) {
		mouseX=window.event.clientX;
		mouseY=window.event.clientY;
	}
	else if (isW3C) {
		mouseX=evt.clientX;	
		mouseY=evt.clientY;
	}
	if ((running==1) && (current!=-1)) {
		if (smallThumbs) {
			moveLayer('info'+current,mouseX+20-((current > 6)*200),mouseY);
		} else {
			moveLayer('info'+current,mouseX+20-(((current>2 && current < 7) || (current > 9))*200),mouseY);
		}
	}
	return true;
}

function showlayer(which) {
	if (isNav || isExp) {
		eval ('document.'+pre+which+suf+'.visibility="visible"');
		eval ('document.'+pre+which+suf+'.display="block"');
		return;
	}
	else if (isW3C || isOpera) {
		obj=document.getElementById(which);
		obj.style.visibility="visible";
		obj.style.display="block";
	}
}

function hidelayer(which) {
	if (isNav || isExp) {
		eval ('document.'+pre+which+suf+'.visibility="hidden"');
		eval ('document.'+pre+which+suf+'.display="none"');
		return;
	}
	else if (isW3C || isOpera) {
		obj=document.getElementById(which);
		obj.style.visibility="hidden";
		obj.style.display="none";
	}
}

function moveLayer(which,x,y) {
	if (isIE)	{
		document.all[which].style.pixelLeft=x;
		document.all[which].style.pixelTop=y;
	}
	else if (isNN4) {
		document.layers[which].moveTo(x,y);
	}
	else if (isOpera) {
		obj=document.getElementById(which);
		obj.style.left=x;
		obj.style.top=y;	
	}
	else if (isW3C) {
		obj=document.getElementById(which);
		obj.style.left=x+'px';
		obj.style.top=y+'px';	
	}
}
	
function getWinWidth() {
	if (isIE) {
		return document.body.clientWidth;
	}
	else if (isNN4 || isW3C || isOpera) {
		return window.innerWidth;
	}
}

function infoOn(which) {
	if (running==0) return;
	showlayer('info'+which);

	if (! isNN4) {
		whichImg = "thumb" + which;
		currentImg = "thumb" + current;
		document.images[whichImg].style.borderColor='#EEE5B3';
		//document.images[currentImg].style.borderColor='#000000';
	}

	current=which;
}
	
function infoOut(which) {
	if (running==0) return;
	hidelayer('info'+which);

	if (! isNN4 && (!smallThumbs || !(which == currentID))) {
		whichImg = "thumb" + which;
		document.images[whichImg].style.borderColor='#000000';
	}
}
	
if (isNN4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mouseHandler;

function nnOnresize() {
	if (isNN4) {
		window.location.reload();
	}
}


function init() {
	running=1;
	offset=(getWinWidth()-730)/2;
}


function numberOver(num) {
	if (currentSel != num) {
		swapImage('num' + num, numOver[num]);
	}
}

function numberOut(num) {
	if (currentSel != num) {
		swapImage('num' + num, numOff[num]);
	}
}

function selectImg(sel) {
	if (!isExp && !isW3C && !isOpera) {
		return true;
	}

	if (document.images && document.images["mainImg"]) {
			document.images["mainImg"].src = "artifacts/360x310/" + imgPaths[sel] + ".jpg";
			if (sel != currentSel) {
				swapImage('num' + sel, numSel[sel])
				swapImage('num' + currentSel, numOff[currentSel])
				
				if (objHasMultipleDesciptions) {
					hidelayer("desc" + currentSel);
					showlayer("desc" + sel);
				}
				
				// show zoom button?
				swapImage('btnLaunch', zoomImgArr[flags[sel]]);
				if (flags[sel] == 1) { 
					document.images["btnLaunch"].alt = "Click to zoom";
				} else if (flags[sel] == 2) {
					document.images["btnLaunch"].alt = "Click to view";
				} else {
					document.images["btnLaunch"].alt = "";
				}
				
				
				currentSel = sel;
			}
		}
	return false;
}

function launchZoom() {
	var id = currentID;
	var sel = currentSel;
	if (flags[sel] == 1) {
//		url = 'zoom.php?id=' + id + "&sel=" + sel;
		url = 'zoom_' + id + '_' + sel + '.php';
		zoom = window.open(url,'zoom','width=760,height=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
		zoom.focus();
	} else if (flags[sel] == 2) {
//		url ='clip.php?id=a' + id;
		url ='clip_a' + id + '.html';
		clip =  window.open(url,'artclip','width=240,height=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
		clip.focus();
	}
}
