var win_width, win_height, vert_scroll, hor_scroll, tip_t1, tip_t2,	mouseX, mouseY, origWidth, origHeight;
var tipOffX	= 8;	var tipOffY	= 12; 
var tipFontFamily = "Trebuchet MS, Times, serif;";
var tipFontSize	= "14px"; var tipFontWeight = "bold"; var tipTextAlign = "center"; var tipFontColor = "#ffffff"; var tipBgColor = "#90795B";	
window.onload = initTip; window.onresize = to_do_onresize;	
if (document.layers) { origWidth = window.innerWidth;  origHeight = window.innerHeight;}
function to_do_onresize() {
	if (document.layers) {
	 if (window.innerWidth != origWidth || window.innerHeight != origHeight)
	    window.location.reload();
	} else {win_width = getWinWidth();	win_height = getWinHeight(); }
}
function initTip() {
	tooltip = new dynObj('tipDiv');	if (!tooltip) return;
	if (!document.layers && typeof tooltip.doc.innerHTML == "undefined"){
		tooltip = null;	return; 
	}
	if (tooltip.el.style) {	
		tooltip.css.width = tipWidth+"px";
		tooltip.css.fontFamily = tipFontFamily;
		tooltip.css.fontSize = tipFontSize;
		tooltip.css.lineHeight = 1.2;
		tooltip.css.color = tipFontColor;
		tooltip.css.fontWeight = tipFontWeight;
		tooltip.css.textAlign = tipTextAlign;
		tooltip.css.backgroundColor = tipBgColor;
        tooltip.css.border = "5px solid #4D292D";
	}
	win_width = getWinWidth();	win_height = getWinHeight();
}
function wrapTip(num) {
	var cntnt = "";
  messages[num][4]? curTipWidth = messages[num][4]: curTipWidth = tipWidth;
	if (document.layers) {
		cntnt += '<table bgcolor="#000000" width="' + curTipWidth + '" cellspacing="0" cellpadding="1" border="0"><tr><td>';
		cntnt += '<table bgcolor="' + tipBgColor + '" width="100%" cellspacing="0" cellpadding="4" border="0"><tr><td>';
		cntnt += '<table width="100%"><tr><td align="left" width="100%"><img src="' + messages[num][0] + '" width="' + messages[num][2] + '" height="' + messages[num][3] + '" border="0"></td></tr>';
		cntnt += '<tr><td valign="top"><span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + tipFontColor + '">' + messages[num][1] + '</span></td></tr></table>' + '</td></tr></table></td></tr></table>';
	} else {
    tooltip.css.width = curTipWidth+"px";
		cntnt += '<div style="text-align:left; padding:4px"><img src="' + messages[num][0] + '" width="' + messages[num][2] + '" height="' + messages[num][3] + '" border="0"></div>';
		cntnt += '<div style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + tipFontColor + '; padding:4px">' + messages[num][1] + '</div>';
	}
	return cntnt;
}

function goTooltip(evt,cntnt) {
	if (tip_t1) clearTimeout(tip_t1);	if (tip_t2) clearTimeout(tip_t2); 
	tooltip.writeLyr(cntnt);
	vert_scroll = getScrollY();	hor_scroll = getScrollX();
	evt = (window.event)? window.event: evt;
	if (evt) {
		mouseX = getMouseX(evt);	mouseY = getMouseY(evt);
	}
	tooltip.width = getWidth(tooltip.el);	
  tooltip.height = getHeight(tooltip.el);
	if (!document.layers)
		setTimeout("tooltip.height=getHeight('','tipDiv')",100);
	setTimeout("positionTip()",120);	
	tip_t1=setTimeout(tooltip.obj+".show()",200);	
}
function positionTip() {
	var x, y;
	tooltip.height = getHeight(tooltip.el); 
	if ((mouseX + tipOffX + tooltip.width) > win_width + hor_scroll) 
		x = mouseX - (tooltip.width + tipOffX);
	else x = mouseX + tipOffX;
	if ((mouseY + tipOffY + tooltip.height) > win_height + vert_scroll) 
		y = (mouseY - (tooltip.height + tipOffY) > vert_scroll)?  mouseY - (tooltip.height + tipOffY): win_height + vert_scroll - (tooltip.height + tipOffY);
	else y = mouseY + tipOffY;
	tooltip.shiftTo(x,y);
}
function hideTip() {
	if (!tooltip) return;
	tip_t2=setTimeout(tooltip.obj+".hide()",200);
	}

function getMouseX(evt) {
	return (evt.pageX)? evt.pageX: evt.clientX + getScrollX();
}
function getMouseY(evt) {
	return (evt.pageY)? evt.pageY: evt.clientY + getScrollY();
}
function dynObj(id,x,y,w,h) {
	this.el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (!this.el) return null;
	this.doc = (document.layers)? this.el.document: this.el;
	this.css = (this.el.style)? this.el.style: this.el;
	this.x = x || 0;	this.y = y || 0;	
	this.width = w? w: (this.el.offsetWidth)? this.el.offsetWidth: (this.css.clip.width)? this.css.clip.width: 0;
	this.height = h? h: (this.el.offsetHeight)? this.el.offsetHeight: (this.css.clip.height)? this.css.clip.height: 0;
	this.obj = id + "dynObj"; 	eval(this.obj + "=this");
}
function dw_show() { this.css.visibility = "visible"; }
function dw_hide() { this.css.visibility = "hidden"; }
function dw_shiftTo(x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}
function dw_writeLyr(cntnt) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = cntnt;
  } else if (document.layers) {
			this.doc.write(cntnt);
			this.doc.close();
  }
}
dynObj.prototype.show = dw_show;
dynObj.prototype.hide = dw_hide;
dynObj.prototype.shiftTo = dw_shiftTo;
dynObj.prototype.writeLyr = dw_writeLyr;
function getWidth(obj,id) {
	var wd=0;
	if (document.getElementById||document.all) {
		var elem;
		if (id)	elem = (document.getElementById)? document.getElementById(id): document.all[id];
		else elem = obj;
		if (elem.offsetWidth) wd = elem.offsetWidth;
  } else if (obj.document) wd = obj.document.width;	// ns4
	return wd;
}
function getHeight(obj,id) {
	var ht=0;
	if (document.getElementById||document.all) {
    var elem;
		if (id)	elem = (document.getElementById)? document.getElementById(id): document.all[id];
		else elem = obj;
		if (elem.offsetHeight) ht = elem.offsetHeight;
  } else if (obj.document) ht = obj.document.height;	// ns4
	return ht;
}
function getWinWidth() {
	var winWd = 0;
	if (document.documentElement && document.documentElement.clientWidth) 
		winWd = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		winWd = document.body.clientWidth;
	else if (document.body && document.body.offsetWidth) 
		winWd = document.body.offsetWidth; // ns6
	else if (window.innerWidth) winWd = window.innerWidth-18;
	return winWd;
}
function getWinHeight() {
	var winHt = 0;
	if (window.innerHeight) winHt = window.innerHeight-18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		winHt = document.body.clientHeight;
	return winHt;
}	
function getScrollY() {
	var scroll_y = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		scroll_y = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scroll_y = document.body.scrollTop; 
	else if (window.pageYOffset)
		scroll_y = window.pageYOffset;
	else if (window.scrollY)
		scroll_y = window.scrollY;
	return scroll_y;
}
function getScrollX() {
	var scroll_x = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		scroll_x = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scroll_x = document.body.scrollLeft; 
	else if (window.pageXOffset)
		scroll_x = window.pageXOffset;
	else if (window.scrollX)
		scroll_x = window.scrollX;
	return scroll_x;
}