/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
Modified: Michael John Trettewick
*/
var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['a'],	// @Array: Allowable elements that can have the toolTip
	elemObj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			 !document.createElement ||
			 !document.getElementsByTagName ) {
			 return;
		}
		var i,j;
		this.tip = document.getElementById('doc_tooltip');
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		this.tip.style.display = 'block';
		var tipLen = this.tipElements.length;
		// addEvent(document,'mousemove',sweetTitles.tipUpdateXY);
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				if (current[j].className.indexOf('tip') >= 0) {
					// if img tag...
					if (current[j].firstChild.nodeName.toLowerCase() == 'img'){
						current[j].setAttribute('tiptitle', current[j].firstChild.alt);
						current[j].setAttribute('tipdescription',current[j].title);
						current[j].firstChild.alt = '';
					} else { // if a tag...
						current[j].setAttribute('tipdescription',current[j].title);
						current[j].setAttribute('tiptitle',current[j].innerHTML);
					}					
					addEvent(current[j],'mouseover',this.tipOver);
					addEvent(current[j],'mouseout',this.tipOut);
					current[j].title = '';
				}
			}
		}
	},
	tipUpdateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
		sweetTitles.tipPosition();
	},
	tipOut: function() {
		
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		document.getElementById('pointer_left').style.visibility = 'hidden';
		document.getElementById('pointer_left').style.display = 'none';
		document.getElementById('pointer_right').style.visibility = 'hidden';
		document.getElementById('pointer_right').style.display = 'none';
		document.getElementById('pointer_top').style.visibility = 'hidden';
		document.getElementById('pointer_top').style.display = 'none';
		sweetTitles.tip.style.visibility = 'hidden';
	},
	tipCheckNode : function() {
		var trueObj = this.elemObj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.elemObj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",10);
		sweetTitles.tipUpdateXY(e);
		
		addEvent(sweetTitles.elemObj,'mousemove',sweetTitles.tipUpdateXY);
	},
	tipPosition : function(){
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY-this.tip.offsetHeight-15);
		var lt = parseInt(scrX-25);
		if(this.elemObj.className.indexOf('tip_up') >= 0) {
			this.tip.style.top = parseInt(tp+(this.tip.offsetHeight+45))+'px';
			this.tip.style.left = lt+'px';
			if(document.getElementById('pointer_left')) {
				document.getElementById('pointer_left').style.visibility = 'hidden';
				document.getElementById('pointer_left').style.display = 'none';
			}
			if(document.getElementById('pointer_right')){
				document.getElementById('pointer_right').style.visibility = 'hidden';
				document.getElementById('pointer_right').style.display = 'none';
			}
			if (document.getElementById('pointer_top')) {
				document.getElementById('pointer_top').style.visibility = 'visible';
				document.getElementById('pointer_top').style.display = 'block';
			}
		} else {
			if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
				this.tip.style.left = parseInt(lt-(this.tip.offsetWidth-45))+'px';
				
				if (document.getElementById('pointer_top')) {
					document.getElementById('pointer_top').style.visibility = 'hidden';
					document.getElementById('pointer_top').style.display = 'none';
				}
				if(document.getElementById('pointer_left')) {
					document.getElementById('pointer_left').style.visibility = 'hidden';
					document.getElementById('pointer_left').style.display = 'none';
				}
				if(document.getElementById('pointer_right')){
					document.getElementById('pointer_right').style.visibility = 'visible';
					document.getElementById('pointer_right').style.display = 'block';
				}
			} else {
				this.tip.style.left = lt+'px';
				
				if (document.getElementById('pointer_top')) {
					document.getElementById('pointer_top').style.visibility = 'hidden';
					document.getElementById('pointer_top').style.display = 'none';
				}
				if(document.getElementById('pointer_left')) {
					document.getElementById('pointer_left').style.visibility = 'visible';
					document.getElementById('pointer_left').style.display = 'block';
				}
				if(document.getElementById('pointer_right')){
					document.getElementById('pointer_right').style.visibility = 'hidden';
					document.getElementById('pointer_right').style.display = 'none';
				}
			}
			if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
				this.tip.style.top = parseInt(tp-(this.tip.offsetHeight-40))+'px';
			} else {
				this.tip.style.top = tp+'px';
			}
		}
			this.tip.style.visibility = 'visible';
			this.tip.style.opacity = '1.0';
	},
	tipShow : function() {
		var anch = this.tipCheckNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
			var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		} else {
			addy = anch.firstChild.nodeValue;
		}
		document.getElementById('doc_tooltip_name').innerHTML = anch.getAttribute('tiptitle');
		document.getElementById('doc_tooltip_description').innerHTML = anch.getAttribute('tipdescription');
		sweetTitles.tipPosition();
		//this.tipFade(10);
		
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 100 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '1.0';
			this.tip.style.filter = "alpha(opacity:100)";
		}
	}
};
/*
function tipPageLoader() {
	sweetTitles.init();
}
addEvent(window,'load',tipPageLoader);
*/

if (ToolTip == undefined) {
var ToolTip = {

	tooltip:undefined,
	targetDiv: undefined,
	
	show:function(target, e){
		if(document.toolObj != null){
			return;
		}
		var xpos = e ? e.clientX : event.clientX;
		var ypos = e ? e.clientY : event.clientY;
		xpos = xpos + Stage.getScrollLeft();
		ypos = ypos + Stage.getScrollTop();

		var message;
		if(target.getAttribute('tooltip')){
			message = target.getAttribute('tooltip');
		}	

		this.targetDiv = target;

		if(this.tooltip == undefined){
			if($('tooltip')){
				this.tooltip = $('tooltip');
				this.tooltip.innerHTML = '<div style="overflow:hidden; width:150px; color:#576F79; font-family:Arial,Verdana; font-size:12px; font-weight:bold; background-color:#FFFFFF; padding:5px">'+message+'</div><div style="font-size:1px; padding-left:20px; width:' + (gteIE5 ? '150' : '140') + 'px"><img src="http://heavy.com/images/ttiparrow.gif" width="15" height="8"></div>';
			}else{
				this.tooltip  = document.createElement('span');
				this.tooltip.style.cssText ="overflow:hidden; position:absolute; display:none; font-size:1px; z-index:" + ZManager.prototype.zTopMost;
				this.tooltip.innerHTML = '<div style="width:150px; color:#576F79; font-family:Arial,Verdana; font-size:12px; font-weight:bold; background-color:#FFFFFF; padding:5px">'+message+'</div><div style="font-size:1px; padding-left:20px; width:' + (gteIE5 ? '150' : '140') + 'px"><img src="http://heavy.com/images/ttiparrow.gif" width="15" height="8"></div>';
				this.tooltip.id  = 'tooltip';
				document.body.appendChild(this.tooltip);
			}
		}else{
			this.tooltip.innerHTML = '<div style="width:150px; color:#576F79; font-family:Arial,Verdana; font-size:12px; font-weight:bold; background-color:#FFFFFF; padding:5px">'+message+'</div><div style="font-size:1px; padding-left:20px; width:' + (gteIE5 ? '150' : '140') + 'px"><img src="http://heavy.com/images/ttiparrow.gif" width="15" height="8"></div>';
		}
		if(this.tooltip.offsetHeight){
			this.move(xpos-27, ypos-5-this.tooltip.offsetHeight);			
			Element.show(this.tooltip);	
		}
		document.toolObj = this;
		document.onmousemove = this.toolTracking;
	},

	hide:function(target){
		this.targetDiv = null;
		delete this.targetDiv;
		this.posCache = null;
		delete this.posCache;
		this.sizeCache = null;
		delete this.sizeCache;
		document.toolObj  = null;
		document.onmousemove = null;
		if(this.tooltip && this.tooltip.style.display != 'none'){
			Element.hide(this.tooltip);	
		}
	},

	withinTarget:function(x, y){
		if(!this.posCache){
			this.posCache = Position.cumulativeOffset(this.targetDiv);
		}

		if(!this.sizeCache){
			this.sizeCache = [this.targetDiv.offsetWidth, this.targetDiv.offsetHeight];
		}

		return (y >= this.posCache[1] &&
		y <  this.posCache[1] + this.sizeCache[1] &&
		x >= this.posCache[0] && 
		x <  this.posCache[0] + this.sizeCache[0]);
	},

	toolTracking:function(e){
		var xpos = e ? e.clientX : event.clientX;
		var ypos = e ? e.clientY : event.clientY;
		xpos = xpos + Stage.getScrollLeft();
		ypos = ypos + Stage.getScrollTop();
		if(this.toolObj.withinTarget(xpos, ypos)){
			if(this.toolObj.tooltip.style.display == 'none'){
				Element.show(this.toolObj.tooltip);	
			}		
			this.toolObj.move(xpos-27, ypos-5 - this.toolObj.tooltip.offsetHeight);	
		}else{
			this.toolObj.hide();
		}
	
	},

	move:function(x, y){
		this.tooltip.style.left = String(x) + 'px';
		this.tooltip.style.top = String(y) + 'px';
	}

};
}
