// @author	DoODABoOM
// @license	Copyright © 2010 - All Rights Reserved
			
var titTipTag = "a,label,input,td";

getElementsByClassName = function (className, tag, elm){
	var testClass = new RegExp("(^|s)" + className + "(s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i ];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

//There's No need to edit anything below this line//
var titTipBox = {
  name : "titTip",
  tip : null
}

titTipBox.init = function () {
	
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "titTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {titTipBox.move (evt)};

	var a, sTitle, elements;
	
	var elementList = titTipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
	
		elements = document.getElementsByClassName( customclass, elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");				
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {titTipBox.show(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {titTipBox.hide()};
				}
			}
		}
	}
}

titTipBox.move = function (evt) {
	
	var x=0, y=0;
	
	if (document.all) {//IE
	
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;		
		
		if ( position == 0 ){ // TOP LEFT
		
			x += ( ( window.event.clientX ) - ( this.tip.offsetWidth ) - 10 );
			y += ( ( window.event.clientY ) - ( this.tip.offsetHeight ) - 5 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth + 40 ) ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			
		} else if ( position == 1 ){ // TOP
		
			x += ( ( window.event.clientX ) - ( ( this.tip.offsetWidth / 2 ) ) + ( 5 ) );
			y += ( ( window.event.clientY ) - ( this.tip.offsetHeight ) - 5 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth / 2 ) + 5 ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			if ( ( x + ( this.tip.offsetWidth/2 ) ) > ( ( document.body.offsetWidth ) - this.margin )   ){
				this.tip.style.left = ( x - ( this.tip.offsetWidth / 2 ) - 5 ) + "px";
			}
			
		} else if ( position == 2 ){ // TOP RIGHT
		
			x += ( ( window.event.clientX ) + 10 );
			y += ( ( window.event.clientY ) - ( this.tip.offsetHeight ) - 5 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 20 ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
						
		} else if ( position == 3 ){ // LEFT
		
			x += ( ( window.event.clientX ) - ( this.tip.offsetWidth ) - 20 );
			y += ( ( window.event.clientY ) - ( this.tip.offsetHeight / 2 ) + 10 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth + 50 ) ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			if ( ( y + ( this.tip.offsetHeight ) ) > ( ( document.body.offsetHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
			
		} else if ( position == 4 ){ // RIGHT
		
			x += ( ( window.event.clientX ) + 20 );
			y += ( ( window.event.clientY ) - ( this.tip.offsetHeight / 2 ) + 10 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 30 ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			if ( ( y + ( this.tip.offsetheight ) ) > ( ( document.body.offsetHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
			
		} else if ( position == 5 ){ // BOTTOM LEFT
		
			x += ( ( window.event.clientX ) - ( this.tip.offsetWidth ) - 5 );
			y += ( ( window.event.clientY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth + 10 ) ) + "px";
			}
			if ( ( y + ( this.tip.offsetHeight ) ) > ( ( document.body.offsetHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
			
		} else if ( position == 6 ){ // BOTTOM
		
			x += ( ( window.event.clientX ) - ( ( this.tip.offsetWidth/2 ) ) + ( 5 ) );
			y += ( ( window.event.clientY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth / 2 ) ) + "px";
			}
			if ( ( x + ( this.tip.offsetWidth/2 ) ) > ( ( document.body.offsetWidth ) - this.margin )   ){
				this.tip.style.left = ( x - ( this.tip.offsetWidth / 2 ) - 20 ) + "px";
			}
			if ( ( y + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}			
			
		} else if ( position == 7 ){ // BOTTOM RIGHT
		
			x += ( ( window.event.clientX ) + 20 );
			y += ( ( window.event.clientY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 20 ) + "px";
			}
			if ( ( y + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
						
		}  else {
			
			x += ( ( window.event.clientX ) + 20 );
			y += ( ( window.event.clientY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 20 ) + "px";
			}
			if ( ( y + ( this.tip.offsetWidth ) ) > ( ( document.body.offsetHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}			

		}

	} else { //Good Browsers
		
		if ( position == 0 ){ // TOP LEFT
		
			x = ( ( evt.pageX ) - ( this.tip.offsetWidth ) - 10 );
			y = ( ( evt.pageY ) - ( this.tip.offsetHeight ) - 5 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth + 40 ) ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			
		} else if ( position == 1 ){ // TOP
		
			x = ( ( evt.pageX ) - ( ( this.tip.offsetWidth / 2 ) ) + ( 5 ) );
			y = ( ( evt.pageY ) - ( this.tip.offsetHeight ) - 5 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth / 2 ) + 5 ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			if ( ( x + ( this.tip.offsetWidth/2 ) ) > ( ( window.innerWidth ) - this.margin )   ){
				this.tip.style.left = ( x - ( this.tip.offsetWidth / 2 ) - 5 ) + "px";
			}
			
		} else if ( position == 2 ){ // TOP RIGHT
		
			x = ( ( evt.pageX ) + 10 );
			y = ( ( evt.pageY ) - ( this.tip.offsetHeight ) - 5 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( window.innerWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 20 ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
						
		} else if ( position == 3 ){ // LEFT
		
			x = ( ( evt.pageX ) - ( this.tip.offsetWidth ) - 20 );
			y = ( ( evt.pageY ) - ( this.tip.offsetHeight / 2 ) + 10 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth + 50 ) ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			if ( ( y + ( this.tip.offsetHeight ) ) > ( ( window.innerHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
			
		} else if ( position == 4 ){ // RIGHT
		
			x = ( ( evt.pageX ) + 20 );
			y = ( ( evt.pageY ) - ( this.tip.offsetHeight / 2 ) + 10 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( window.innerWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 30 ) + "px";
			}
			if ( y < this.margin ){
				this.tip.style.top = ( y + this.tip.offsetHeight + 30 ) + "px";
			}
			if ( ( y + ( this.tip.offsetheight ) ) > ( ( window.innerHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
			
		} else if ( position == 5 ){ // BOTTOM LEFT
		
			x = ( ( evt.pageX ) - ( this.tip.offsetWidth ) - 5 );
			y = ( ( evt.pageY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth + 10 ) ) + "px";
			}
			if ( ( y + ( this.tip.offsetHeight ) ) > ( ( window.innerHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}
			
		} else if ( position == 6 ){ // BOTTOM
		
			x = ( ( evt.pageX ) - ( ( this.tip.offsetWidth/2 ) ) + ( 5 ) );
			y = ( ( evt.pageY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( x < this.margin ){
				this.tip.style.left = ( x + ( this.tip.offsetWidth / 2 ) ) + "px";
			}
			if ( ( x + ( this.tip.offsetWidth/2 ) ) > ( ( window.innerWidth ) - this.margin )   ){
				this.tip.style.left = ( x - ( this.tip.offsetWidth / 2 ) - 20 ) + "px";
			}
			if ( ( y + ( this.tip.offsetWidth ) ) > ( ( window.innerHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}			
			
		} else if ( position == 7 ){ // BOTTOM RIGHT
		
			x = ( ( evt.pageX ) + 20 );
			y = ( ( evt.pageY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( window.innerWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 20 ) + "px";
			}
			if ( ( y + ( this.tip.offsetWidth ) ) > ( ( window.innerHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}			
		} else {
		
			x = ( ( evt.pageX ) + 20 );
			y = ( ( evt.pageY ) + 30 );
			this.tip.style.left = (x) + "px";
			this.tip.style.top = (y) + "px";
			
			if ( ( x + ( this.tip.offsetWidth ) ) > ( ( window.innerWidth ) - this.margin )   ){
				this.tip.style.left = ( x -  this.tip.offsetWidth - 20 ) + "px";
			}
			if ( ( y + ( this.tip.offsetWidth ) ) > ( ( window.innerHeight ) - this.margin )   ){
				this.tip.style.top = ( y - this.tip.offsetHeight - 40 ) + "px";
			}			
		} 

	}
	
}

titTipBox.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

titTipBox.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {

	titTipBox.init ();
	
}


