
var win_width, win_height, vert_scroll, hor_scroll, dmxTT_t1, dmxTT_t2, Xpos, Ypos;

function dmxObj(id,x,y,w,h) {
	this.el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): 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;
	var px = (document.layers||window.opera)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	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;
	if (w){ (document.layers)? this.css.clip.width=w+px: this.css.width=w+px;}
	if (h){ (document.layers)? this.css.clip.height=h+px: this.css.height=h+px;}
	this.obj = id + "dmxObj"; 	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_shiftBy(x,y) {
	this.shiftTo(this.x+x,this.y+y);
}

function dw_writeLyr(content) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = content;
  } else if (document.layers) {
			this.doc.write(content);
			this.doc.close();
  }
}

function dw_setBgClr(bg) {
	if (document.layers) this.doc.bgColor=bg;
	else this.css.backgroundColor=bg;
}

dmxObj.prototype.show = dw_show;
dmxObj.prototype.hide = dw_hide;
dmxObj.prototype.shiftTo = dw_shiftTo;
dmxObj.prototype.shiftBy = dw_shiftBy;
dmxObj.prototype.writeLyr = dw_writeLyr;
dmxObj.prototype.setBgClr=dw_setBgClr;


function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}

dmxObj.prototype.centerIn = function(outer) {
	var outWd, outHt, inWd, inHt, x, y;
	if (eval(outer)==window) {
		outWd=getWinWidth();
		outHt=getWinHeight();
	} else {
		outWd=outer.width;
		outHt=outer.height;
	}
	inWd=this.width;
	inHt=this.height;
	x=Math.round((outWd-inWd)/2);
	y=Math.round((outHt-inHt)/2);
	this.shiftTo(x,y);
}

function getWidth(obj,id) {
	var wd=0;
	if (document.getElementById||document.all) {
		var el;
		if (id)	el = (document.getElementById)? document.getElementById(id): document.all[id];
		else el = obj;
		if (el.offsetWidth) wd = el.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 el;
		if (id)	el = (document.getElementById)? document.getElementById(id): document.all[id];
		else el = obj;
		if (el.offsetHeight) ht = el.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;
}

window.onload = dmxTT_init;
window.onresize = dmxTT_onresize;	

var origWidth, origHeight;

if (document.layers) {
  origWidth = window.innerWidth;
  origHeight = window.innerHeight;
}

function dmxTT_onresize() {
	if (document.layers) {
	 if (window.innerWidth != origWidth || window.innerHeight != origHeight)
	    window.location.reload();
	} else {
		win_width = getWinWidth();
		win_height = getWinHeight();
	}
}

function dmxTT_init() {
	dmxTT = new dmxObj('dmxTT_Div');
	if (!dmxTT) return;
	if (!document.layers && typeof dmxTT.doc.innerHTML == "undefined"){
		dmxTT = null;
		return; 
	}
	win_width = getWinWidth();
	win_height = getWinHeight();
}

function dmxTT_exec(dmx_event,content) {
	if (dmxTT_t1) clearTimeout(dmxTT_t1);	
	if (dmxTT_t2) clearTimeout(dmxTT_t2); 
	if (dmxTT_FollowMouse) {
		if (document.addEventListener) {
			document.addEventListener("mousemove",trackMouse,true);
		} else if (document.attachEvent) {
			document.attachEvent("onmousemove",trackMouse);
		} else {
			if (document.layers && document.captureEvents) 
				document.captureEvents(Event.MOUSEMOVE);
				document.onmousemove = trackMouse;
		}
	}
	dmxTT.writeLyr(content);
	vert_scroll = getScrollY();
	hor_scroll = getScrollX();
	dmx_event = (window.event)? window.event: dmx_event;
	if (dmx_event) {
		Xpos = getMouseX(dmx_event);
		Ypos = getMouseY(dmx_event);
	}
	dmxTT.width = getWidth(dmxTT.el);	
	dmxTT.height = getHeight(dmxTT.el);
	if (!document.layers)
		setTimeout("dmxTT.height=getHeight('','dmxTT_Div')",100);
		setTimeout("positiondmxTT_()",120);	
	dmxTT_t1=setTimeout(dmxTT.obj+".show()",200);	
}

function positiondmxTT_() {
	var x, y;
	dmxTT.height = getHeight(dmxTT.el);
	if ((Xpos + dmxTT_OffX + dmxTT.width) > win_width + hor_scroll) 
		x = Xpos - (dmxTT.width + dmxTT_OffX);
	else x = Xpos + dmxTT_OffX;
	
	if ((Ypos + dmxTT_OffY + dmxTT.height) > win_height + vert_scroll) 
		y = (Ypos - (dmxTT.height + dmxTT_OffY) > vert_scroll)?  Ypos - (dmxTT.height + dmxTT_OffY): win_height + vert_scroll - (dmxTT.height + dmxTT_OffY);
	else y = Ypos + dmxTT_OffY;
	dmxTT.shiftTo(x,y);
}

function dmxTT_hide() {
	if (!dmxTT) return;
	dmxTT_t2=setTimeout(dmxTT.obj+".hide()",200);
	if (dmxTT_FollowMouse) {
		if (document.removeEventListener) {
			document.removeEventListener("mousemove",trackMouse,true);
		} else if (document.detachEvent) {
			 document.detachEvent("onmousemove",trackMouse);
		} else {
			if (document.layers && document.releaseEvents)
				document.releaseEvents(Event.MOUSEMOVE);
				document.onmousemove = null;
		}
	}
}

function trackMouse(dmx_event) {
	dmx_event = (window.event)? window.event: dmx_event;
	if (dmx_event) {
		Xpos = getMouseX(dmx_event);
		Ypos = getMouseY(dmx_event);
	}
	positiondmxTT_();	
}

function getMouseX(dmx_event) {
	return (dmx_event.pageX)? dmx_event.pageX: dmx_event.clientX + getScrollX();
}

function getMouseY(dmx_event) {
	return (dmx_event.pageY)? dmx_event.pageY: dmx_event.clientY + getScrollY();
}

