var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

var thumbFollowMouse= true;
var thumbWidth= 100;
var offX= 12;	// mouse offset
var offY= 12;   // mouse offset
var thumbBgColor= "#000000"; 
var thumbPadding= 0;
var messages = new Array();

messages[0] = new Array('http://www.kristisnowcat.com/registry/thumbs/00019.jpg');
messages[1] = new Array('http://www.kristisnowcat.com/registry/thumbs/00024.jpg');
messages[2] = new Array('http://www.kristisnowcat.com/registry/thumbs/00031.jpg');
messages[3] = new Array('http://www.kristisnowcat.com/registry/thumbs/00032.jpg');
messages[4] = new Array('http://www.kristisnowcat.com/registry/thumbs/00033.jpg');
messages[5] = new Array('http://www.kristisnowcat.com/registry/thumbs/00037.jpg');


// resize fix for ns4
var origWidth, origHeight;
if (ns4) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }


// preload images 
if (document.images) {
	var theImgs = new Array();
	for (var i=0; i<messages.length; i++) {
  	theImgs[i] = new Image();
		theImgs[i].src = messages[i][0];
  }
}


//  initthumb	- initialization for imagethumb, global variables for imagethumb, set styles for all but ns4, set up mousemove capture if thumbFollowMouse set true.
var imagethumb, thumbcss;
function initthumb() {
	if (nodyn) return;
	imagethumb = (ns4)? document.thumbDiv.document: (ie4)? document.all['thumbDiv']: (ie5||ns5)? document.getElementById('thumbDiv'): null;
	thumbcss = (ns4)? document.thumbDiv: imagethumb.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		thumbcss.width = thumbWidth+"px";
		thumbcss.backgroundColor = thumbBgColor;
		thumbcss.padding = thumbPadding+"px";
	}
	if (imagethumb&&thumbFollowMouse) {
		if (ns4) document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = trackMouse;
	}
}

window.onload = initthumb;

//  doimagethumb function, Assembles content for imagethumb and writes it to thumbDiv
var t1,t2;	// for setTimeouts
var thumbOn = false;	// check if over imagethumb link
function doimagethumb(evt,num) {
	if (!imagethumb) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	thumbOn = true;
	// set colors if included in messages array
	if (ns4) {
		var thumb = '<table width="' + thumbWidth + '" cellspacing="0" cellpadding="0" border="0"><tr><td><table bgcolor="' + thumbBgColor + '" width="100%" cellspacing="0" cellpadding="' + thumbPadding + '" border="0"><tr><td>'+ '<table width="' + thumbWidth + '"><tr><td align="center" width="100%"><img src="' + messages[num][0] + '" border="0"></td></tr></table>' + '</td></tr></table></td></tr></table>';
		imagethumb.write(thumb);
		imagethumb.close();
	} else if (ie4||ie5||ns5) {
		var thumb = '<table width="' + thumbWidth + '"><tr><td align="center" width="100%"><img src="' + messages[num][0] + '" border="0"></td></tr></table>';
		thumbcss.backgroundColor = thumbBgColor;
	 	imagethumb.innerHTML = thumb;
	}
	if (!thumbFollowMouse) positionthumb(evt);
	else t1=setTimeout("thumbcss.visibility='visible'",100);
}

var mouseX, mouseY;
function trackMouse(evt) {
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (thumbOn) positionthumb(evt);
}

//  positionthumb function; Calculations use mouseover event position, offset amounts and imagethumb width to position imagethumb within window.
function positionthumb(evt) {
	if (!thumbFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	}
	// imagethumb width and height
	var tpWd = (ns4)? imagethumb.width: (ie4||ie5)? imagethumb.clientWidth: imagethumb.offsetWidth;
	var tpHt = (ns4)? imagethumb.height: (ie4||ie5)? imagethumb.clientHeight: imagethumb.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against thumb and window dimensions
	// and position the imagethumb 
	if ((mouseX+offX+tpWd)>winWd) 
		thumbcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
	else thumbcss.left = (ns4)? mouseX+offX: mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		thumbcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
	else thumbcss.top = (ns4)? mouseY+offY: mouseY+offY+"px";
	if (!thumbFollowMouse) t1=setTimeout("thumbcss.visibility='visible'",100);
}

function hidethumb() {
	if (!imagethumb) return;
	t2=setTimeout("thumbcss.visibility='hidden'",100);
	thumbOn = false;
}
