var origWidth, origHeight;
if (document.layers) {
  origWidth = window.innerWidth;
  origHeight = window.innerHeight;
}
// onresize
function to_do_onresize() {
	if (document.layers) {
	 if (window.innerWidth != origWidth || window.innerHeight != origHeight)
	    window.location.reload();
	} else {
		win_width = getWinWidth();
		win_height = getWinHeight();
	}
}
window.onresize = to_do_onresize;	

// avoid error of passing event object in older browsers
if (!document.getElementById && !document.all && !document.layers) 
	event = "";

var win_width, win_height;	

/////////////////////////////////////////////////////////////////////
// Customize tooltip here

// put images to preload in this array
var preload_list = new Array("images/dot-com-btn.gif");

// preload (change path to images if necessary)
if (document.images) {
	var image_list = new Array();
	for (var preload_counter=0; preload_counter<preload_list.length; preload_counter++) {
  	image_list[preload_counter] = new Image(); 
		image_list[preload_counter].src ="images/" + preload_list[preload_counter];	
  }
}

// settings for tooltip 
var tipWidth 			 	= 221;
var tipOffX				 	= 20;	// how far from mouse to show tip
var tipOffY				 	= -50; 
var tipFontFamily 	= "Verdana, arial, helvetica, sans-serif";
var tipFontSize			= "10px";
var tipFontColor		= "#FF8A00";
var tipBgColor 			= "#FFFFFF";
var tipBorderColor 	= "#CE7B00";
var tipBorderWidth 	= 1;
var tipBorderStyle 	= "solid";
var tipPadding		 	= 2;
var tipAniLen				= 300; // time allotted for slideOut/In (milliseconds)

// messages for links
var msg1 = "Your message for link 1, whatever length you need. The layer will grow to accommodate your content.";

var msgImg = '<img src="images/dot-com-btn.gif" width="176" height="30" alt="" border="0"><div class="tp1">Images and text can go together in a tooltip.</div>';

// end of tooltip customization area
/////////////////////////////////////////////////////////////////////

var tooltip, tipMult, startTime;
function initTip() {
	tooltip = new dynObj('tipDiv');
	if (!tooltip) return;
	if (!document.layers && (typeof tooltip.doc.innerHTML == "undefined" || window.opera) ){
		tooltip = null;
		return; // opera 7 not ok
	}
	tooltip.slideOut = slideOut;
	tooltip.slideIn = slideIn;
	
	win_width = getWinWidth();
	win_height = getWinHeight();
	if (tooltip.el.style) {	// ns4 would lose all this on rewrites
		tooltip.css.width = tipWidth+"px";
		tooltip.css.fontFamily = tipFontFamily;
		tooltip.css.fontSize = tipFontSize;
		tooltip.css.color = tipFontColor;
		tooltip.css.backgroundColor = tipBgColor;
		tooltip.css.borderColor = tipBorderColor;
		tooltip.css.borderWidth = tipBorderWidth+"px";
		tooltip.css.padding = tipPadding+"px";
		tooltip.css.borderStyle = tipBorderStyle;
	}
	// adjust for border and padding in standards-compliant browsers
	// be sure to skip ie4 which will give window width
	if (document.getElementById && tooltip.el.offsetWidth) 
		tipWidth = tooltip.el.offsetWidth;
	tooltip.clipTo(0,0,0,0);	
	tipMult = tipWidth/tipAniLen/tipAniLen;	// used for slideIn/Out
}
window.onload=initTip;

function doTip(txt,evt) {
	if (!tooltip) return;
	if (t1) clearTimeout(t1); if (t2) clearTimeout(t2);
	var cntnt;
	if (document.layers) // styles need to be reapplied each time for ns4
		cntnt = '<table bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + tipBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td><span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + tipFontColor + ';">' + txt  + '</span></td></tr></table></td></tr></table>';
	else cntnt = txt;
	tooltip.writeLyr(cntnt);
	
	evt = (window.event)? window.event: evt;
	if (evt) {
		var mouseX = (evt.pageX)? evt.pageX: evt.clientX + getScrollX();
		var mouseY = (evt.pageY)? evt.pageY: evt.clientY + getScrollY();
	}
	tooltip.width = getWidth(tooltip.el);	
	tooltip.height = getHeight(tooltip.el);
	tooltip.clipTo(0,tooltip.width,tooltip.height,0);
	positionTip(mouseX,mouseY)
	
	startTime = (new Date()).getTime();
	tooltip.slideOut();
}

// check coordinates and position tooltip
function positionTip(mouseX,mouseY) {
	var x, y;
	
	if ((mouseX + tipOffX + tooltip.width) > win_width + getScrollX()) 
		x = mouseX - (tooltip.width + tipOffX);
	else x = mouseX + tipOffX;
	
	if ((mouseY + tipOffY + tooltip.height) > win_height + getScrollY()) 
		y = (mouseY - (tooltip.height + tipOffY) > getScrollY())?  mouseY - (tooltip.height + tipOffY): win_height + getScrollY() - (tooltip.height + tipOffY);
	else y = mouseY + tipOffY;
	tooltip.shiftTo(x,y);
}

var t1, t2;	// for setTimeout's
function slideOut() {
	var elapsed = (new Date()).getTime()-startTime;
	if (elapsed<tipAniLen) {
		var cv = this.width - Math.round(Math.pow(tipAniLen-elapsed,2)*tipMult);
		this.clipTo(0,cv,this.height,0);
		t1 = setTimeout(this.obj+".slideOut()",35);
	} else this.clipTo(0,this.width,this.height,0);
}

function slideIn() {
	var elapsed = (new Date()).getTime()-startTime;
	if (elapsed<tipAniLen) {
		var cv = Math.round(Math.pow(tipAniLen-elapsed,2)*tipMult);
		this.clipTo(0,cv,this.height,0);
		t2 = setTimeout(this.obj+".slideIn()",35);
	} else this.clipTo(0,0,this.height,0);
}

function shrink() {
	if (!tooltip) return;
	if (t1) clearTimeout(t1);
	if (t2) clearTimeout(t2);
	startTime = (new Date()).getTime();
	tooltip.slideIn();
}
