//   This gets rid of the alt / title property of links and replaces it with your own
//   it gets rid of the actual built in broswer tool tip and allows you to define your own 
//   with css =)  *****  the object must have a title or it will not show a tool tip *******or the defualt browser tooltip IE and FF 
//********************************************************************************************
//   this activates on links and on the certain html elements specified such as abbr and acronym like POS - point of sales
// <a href="mysite" alt="Stuff i would like to say on second line of tooltip" or alt="showurltip" which will show the url instead
// <a href="mysite" alt="" you dont need to put an alt value title="Check out mysite"     the title value will display in tooltip





var showurl = new String("showurltip");     	// if you place this string in your links alt value it will display a flashy url
var notip = "notooltip";  						// if you place this string in your links alt value it will not have a tip at all



var scrolloffsetx;
var scrolloffsety;   							//used to track scroll position

var tipconstructed = false;


function getYscroll(){
		if(navigator.appName == "Microsoft Internet Explorer"){
			scrolloffsety = document.body.scrollTop;
		} else {		
			scrolloffsety = document.body.scrollTop;
		}
};

function getXscroll(){
		if(navigator.appName == "Microsoft Internet Explorer"){
			scrolloffsetx = document.body.scrollLeft;
		} else {		
			scrolloffsetx = document.body.scrollLeft;
		}
};


//**********************************************************************************************
//*********************************** Tooltip object *****************************************
var niceTIPS = { 
	xCord : 0,								
	yCord : 0,
	xoldcord : 0,
	yoldcord : 0,
	xnewcord : 0,
	ynewcord : 0,
	tipElements : ['a','abbr','acronym','area','div'],	//html objects to apply tool tip too				
	obj : Object,								
	tip : Object,								

	init : function() {
		if ( !document.getElementById || !document.createElement || !document.getElementsByTagName ) {
				return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		
		//tipwidth = this.tip.style.width;
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		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].getAttribute('title') != null && current[j].getAttribute('title') != ""){
					
					if(current[j].getAttribute('alt') != notip ){
						addEvent(current[j],'mouseover',this.tipOver);
						addEvent(current[j],'mousemove',this.tipSlide);
						addEvent(current[j],'mouseout',this.tipOut);
							
						current[j].setAttribute('tip',current[j].title);
						current[j].setAttribute('alttext',current[j].getAttribute('alt'));   
						current[j].removeAttribute('title');
						current[j].removeAttribute('alt');
					}else {
						current[j].removeAttribute('title');
						current[j].removeAttribute('alt');
					}
				}
			}
		}
	},


	tipOver : function(e) {
			getYscroll();
			getXscroll();
			niceTIPS.obj = this;
	
			tID = window.setTimeout("niceTIPS.tipShow()",500);
			
			
	},
	
	
	tipOut: function() {
			if ( window.tID ) {
				clearTimeout(tID);
			}
			if ( window.opacityID ) {
				clearTimeout(opacityID);
			}
			niceTIPS.tip.style.visibility = 'hidden';
			niceTIPS.tip.innerHTML = " ";
	},
	


	
	checkNode : function() {
			var trueObj = this.obj;
			if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
				return trueObj;
			} else {
				return trueObj.parentNode;
			}
	},





//******************************************************* WHAT Goes in the tooltip very fragile		
//*******************************************************sets 3 styles for text out put edit the styles in the cssfile
//****** the styles are     .tipfont1  .tipfont2 .tipfont3   the css file is called tooltip.css in the same dir as this

	tipShow : function() {		
	
		var anch = this.checkNode();
		var tiptip = new String(anch.getAttribute('tip'));
		var tipalt = new String(anch.getAttribute('alttext'));
		var tiphref = new String(anch.getAttribute('href'));
		var tipid = new String(anch.getAttribute('id'));
		//for abbriviations and firefox doesnt like to check for .child values when it has no child element
		if ((tiphref == null || tiphref == "null" || tiphref =="")&&(tipalt == null || tipalt == "null" || tipalt =="" )){
			var tipchild = new String(anch.firstChild.nodeValue);
			tipchild="<p class=tipfont3>" + tipchild + "</p>";
		} else {
			var tipchild=""
		}
		
		
		if( tipalt == "showurltip" ){
			if ( anch.nodeName.toLowerCase() == 'a' ) {
				tiphref = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
			} 
			tipalt = "";
			//tipchild = "";
		} else {
			tiphref ="";	
		}
	
		if (tiphref == null || tiphref == "null" || tiphref =="" ){
			tiphref="";	
		} else {
			tiphref="<p class=tipfont3>" + tiphref + "</p>";	
		}
		
		
		if (tipalt == null || tipalt == "null" || tipalt =="" ){
			tipalt = "";	
		}	else {
			tipalt="<p class=tipfont2>" + tipalt + "</p>";	
		}
		
		if (tipid =="showurl"){
			tipid =(anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href)
		}else {
		tipid="";
		}
		
		var tipprintL1 = "<p class=tipfont1>"+tiptip + "</p>";
		var tipprintL2 =  tiphref+ tipalt + tipchild; 
		var tipprintL3 =  "<p class=tipfont4>"+tipid + "</p>";
	
		var printstring = tipprintL1 + tipprintL2 + tipprintL3 ;

		this.tip.innerHTML = printstring;

		
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.50';
		this.tipFade(10);
// position  div
	

//end of position div
		},


	tipSlide: function(e){
			var xoffset = 15;         						// Offsets the left value of the tool tip
			var yoffset = 15;	  							// Offsets the top value of the tool tip

			getXscroll();
			getYscroll();

			var browserwidth;
			var browserheight;
			var tipoffsetx;
			var tipoffsety;
			
			if ( document.captureEvents ) {
				//for FF
				browserwidth = window.innerWidth;
				browserheight =window.innerHeight;
				mouseX = e.clientX;
				mouseY = e.clientY;
			} else {
				//for IE
				browserwidth = document.body.offsetWidth;
				browserheight= document.body.offsetHeight;
				mouseX  = window.event.clientX;
				mouseY =  window.event.clientY;
			}
			
			var scrbuffer =50;        //padding between tip and edge of screen pixels
			
			var tipwidth = document.getElementById("toolTip").offsetWidth;
			if (mouseX + tipwidth + scrbuffer >= browserwidth ){
				tipoffsetx = mouseX + tipwidth + scrbuffer - browserwidth;
				mouseX = mouseX - tipoffsetx;
			}else{
			}
			
			var tipheight = document.getElementById("toolTip").offsetHeight;
			if (mouseY + tipheight + scrbuffer >= browserheight ){
				tipoffsety = mouseY + tipheight + scrbuffer - browserheight;
				mouseY = mouseY - tipoffsety;

			}else{
			}
			
			//alert(mouseX + "," + mouseY)							//mouse position test
			//alert(browserwidth + "," + browserheight);            //browsersize
			//alert(tipheight);										//testtipheight
			//alert("offsets x,y :"  + scrolloffsetx +"," +scrolloffsety);    //scroll value test
	
			toolTip.style.left = xoffset + mouseX + scrolloffsetx +'px';
			toolTip.style.top = yoffset + mouseY + scrolloffsety +'px';
	
	},


	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+20);
		if ( newOpac < 100 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("niceTIPS.tipFade('"+newOpac+"')",20);
		}
		else { 
			//this.tip.style.opacity = '100';
			//this.tip.style.filter = "alpha(opacity:100)";
		}
	}
};

//***********************************************************************************************************
function pageLoader() {
	niceTIPS.init();
};
addEvent(window,'load',pageLoader);




