if(Df){
}else{
	var Df = {}
}
Df.Tip = function(el){
	//BEGIN constructor
	var ele = this.ele = $(el)
	
	var pars = this.pars = {
		dataString:'some sample text for the tool tip',
		dataString: false,
		className:'holder',
		parent: document.body,
		pause:200,
		xOffset: 0,
		yOffset: 0,
		fitInPage: true,
		animate: false,
		direction:'rc' //lt, ltl, ltt, ct, ctc, rt, rtt, rtr, lc, lcc, rc, rcc, rb, rbr, rbb, cb, cbc, lb, lbl, lbb, cc
	}
	
	var pointer, tip, holder, animation, tipHeight, tipWidth, eleHeight, eleWidth, holderHeight, holderWidth, pointerHeight, pointerWidth, elePosTop, elePosLeft, maxHeight, maxWidth, offSetTop, offsetLeft, xcord, ycord, pcord
	var status = false;
	var displayStatus = false;
	var pcord = false;
	//END constructor
	
	this.version = function(){
		return 1.1;
	}
	
	this.requires = function(){
		return [
			'../js/Df.js',
			'../js/prototype1_6.js',
			'../js/prototype1_6_extend.js',
			'../js/Df.Animate.js'
			];
	}
	
	this.set = function(para){
		if(para){
			pars = Object.extend(pars,para)
		}
		
		holder = $E('div',pars.parent,{className:pars.className});
		
		tip = $E('div',holder,{className:'tip'});
		
		xcord = pars.direction.substring(0,1);
		ycord = pars.direction.substring(1,2);
		
		if(pars.direction.substring(2,3)){
			pcord = pars.direction.substring(2,3);
			var cln = 'pointer';
			if(pars.direction == "ltt" | pars.direction == "ctc" | pars.direction == "rtt") {
				cln += 'T';
			}else if(pars.direction == "ltl" | pars.direction == "lcc" | pars.direction == "lbl"){
				cln += 'L';
			}
			else if(pars.direction == "rtr" | pars.direction == "rcc" | pars.direction == "rbr"){
				cln += 'R';
			}
			else if(pars.direction == "lbb" | pars.direction == "cbc" | pars.direction == "rbb"){
				cln += 'B';
			}
			pointer = $E('div',holder,{className:cln});
		}
		
		if(pars.dataNode){
			tip.appendChild($(pars.dataNode));
		}else if(pars.dataString){
			tip.innerHTML = pars.dataString;
		}
		
		setDems();
		setPos();
		
		holder.style.display = 'none';
		
		if(pars.animate){
			animation = new Df.Animate(holder);
			animation.pars = Object.extend(animation.pars,pars.animate);
		}
		
		Event.observe(holder,'mouseover',function(){
			status = true;
		},false);
		
		Event.observe(holder,'mouseout',hide,false);
		
		Event.observe(ele,'mouseover',display,false);
		Event.observe(ele,'mouseout',hide,false);
	}
	
	this.getAnimationObject = function(){
		return animation;
	}
	
	var display = this.display = function(event){
		status = true;
		setTimeout(waitToDisplay,pars.pause);
	}
	
	var hide = this.hide = function(event){
		status = false;
		setTimeout(waitToHide,pars.pause);
	}
	
	var setDems = function(){
		tipHeight = parseInt(tip.getDimensions().height)
		tipWidth = parseInt(tip.getDimensions().width)
		
		eleHeight = parseInt(ele.getDimensions().height)
		eleWidth = parseInt(ele.clientWidth)
		
		holderHeight = parseInt(holder.getDimensions().height)
		holderWidth = parseInt(holder.getDimensions().width)
		
		if(pcord){
			pointerHeight = parseInt(pointer.getDimensions().height)
			pointerWidth = parseInt(pointer.getDimensions().width)
		}
		
	}
	
	var setPos = function(){
		elePosLeft =  parseInt(Position.cumulativeOffset(ele)[0])
		elePosTop =  parseInt(Position.cumulativeOffset(ele)[1])
		maxHeight = parseInt(Element.getDimensions(document.body).height)
		maxWidth = parseInt(Element.getDimensions(document.body).width)
		offSetTop = parseInt(Position.realOffset(holder)[1])
		offsetLeft = parseInt(Position.realOffset(holder)[0])
	}
	
	var waitToDisplay = function(){
		if(status && !displayStatus){
			displayStatus = true
			
			holder.style.display = 'block';
			
			setPos();
			
			holder.style.height = tipHeight + 'px';
			holder.style.width = tipWidth + 'px';
			
			//align to the right
			if(xcord == "r"){
				holder.style.left = elePosLeft + eleWidth + pars.xOffset + 'px';
			}
			//align to the left
			else if(xcord == "l"){
				holder.style.left = elePosLeft - holderWidth - pars.xOffset + 'px';
			}
			//align centered on x axis		
			else if(xcord == "c"){
				holder.style.left = elePosLeft - (holderWidth/2) + ((eleWidth)/2) + pars.xOffset + 'px';
			}
			
			//align on top
			if(ycord == "t"){
				holder.style.top = elePosTop - tipHeight - pars.yOffset + 'px';
			}
			//align to the bottom
			else if(ycord == "b"){
				holder.style.top = elePosTop + eleHeight + pars.yOffset + 'px';
			}
			//align middle on y axis
			else if(ycord == "c"){
				holder.style.top = elePosTop + ((eleHeight/2)-(tipHeight/2)) + pars.yOffset + 'px';
			}
			
			//position for pointer
			if(pcord){
				positionPointer();
			}
			
			//readjust to fit inside window
			if(pars.fitInPage){
				adjustToPage();
			}
			
			if(animation){
				if(animation.getHistoryCount() == 0){
					animation.run();	
				}else{
					animation.last();
				}
			}
		}
	}
	
	var positionPointer = function(){
		pointer.style.display = 'block';
		pointer.style.top = '0px';
		pointer.style.left = '0px';
			
		if(xcord == "l" && ycord == "t"){
			if(pcord == "l"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) + pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 1 + 'px';
				pointer.style.top = tipHeight - pointerHeight + 'px';
				pointer.style.left = holderWidth  - 1 + 'px';
			}
			else if(pcord == "t"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 1 + 'px';
				holder.style.left = parseInt(holder.style.left) + pointerWidth + 'px';
				pointer.style.top = tipHeight - 1 + 'px';
				pointer.style.left = holderWidth - pointerWidth + 'px';
				
			}
		}
		else if(xcord == "c" && ycord == "t"){
			holder.style.height = tipHeight + pointerHeight + 'px';
			holder.style.top = parseInt(holder.style.top) - pointerHeight + 1 + 'px';
			pointer.style.top = tipHeight - 1 + 'px';
			//if(pcord == "c"){
				pointer.style.left = (parseInt(holder.style.width)/2) - (pointerWidth/2) + 'px';
			//}
		}
		else if(xcord == "r" && ycord == "t"){
			if(pcord == "r"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) + pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) + 'px';
				tip.style.left = pointerWidth - 1 + "px";
				pointer.style.top = tipHeight - pointerHeight + 'px';
			}
			else if(pcord == "t"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 1 + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 'px';
				pointer.style.top = tipHeight - 1 + 'px';
				pointer.style.left = 0 + 'px';
				
			}
		}
		else if(xcord == "l" && ycord == "c"){
			holder.style.width = holderWidth + pointerWidth + 'px';
			holder.style.left = parseInt(holder.style.left) - pointerWidth + 1 + 'px';
			pointer.style.left = holderWidth  - 1 + 'px';
			//if(pcord == "c"){
				pointer.style.top = (tipHeight/2)-(pointerHeight/2) + 'px';
				
			//}
			
		}
		else if(xcord == "r" && ycord == "c"){
			holder.style.width = holderWidth + pointerWidth + 'px';
			tip.style.left = pointerWidth - 1 + "px";
			//if(pcord == "c"){
				pointer.style.top = (tipHeight/2)-(pointerHeight/2) + 'px';
				
			//}
			
		}
		else if(xcord == "r" && ycord == "b"){
			if(pcord == "r"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 'px';
				tip.style.left = pointerWidth - 1 + "px";
			}
			else if(pcord == "b"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 'px';
				tip.style.top = pointerHeight - 1 + 'px';
			}
		}
		else if(xcord == "c" && ycord == "b"){
			holder.style.height = tipHeight + pointerHeight + 'px';
			tip.style.top = pointerHeight - 1 + 'px';
			if(pcord == "c"){
				pointer.style.left = (parseInt(holder.style.width)/2) - (pointerWidth/2) + 'px';
			}
		}
		else if(xcord == "l" && ycord == "b"){
			if(pcord == "l"){
				holder.style.width = holderWidth + pointerWidth + 'px';
				holder.style.top = parseInt(holder.style.top) - pointerHeight + 'px';
				holder.style.left = parseInt(holder.style.left) - pointerWidth + 1 + 'px';
				pointer.style.left = holderWidth  - 1 + 'px';
			}
			else if(pcord == "b"){
				holder.style.height = tipHeight + pointerHeight + 'px';
				pointer.style.left = tipWidth - pointerWidth + 'px';
				holder.style.left = parseInt(holder.style.left) + pointerWidth + 'px';
				tip.style.top = pointerHeight - 1 + 'px';
			}
		}
		
		
	}
	
	var resizeHolderWithoutPointer = function(){
		holder.style.height = tipHeight + 'px';
		holder.style.width = tipWidth + 'px';
		tip.style.top = '0px';
		tip.style.left = '0px';
		pointer.style.display = 'none';
	}
	
	var adjustToPage = function(){
		var deltaT = -1*(parseInt(holder.style.top) - offSetTop);
		var deltaB = (parseInt(holder.style.height) + parseInt(holder.style.top) - offSetTop) - maxHeight;
		var deltaL = -1*(parseInt(holder.style.left) - offsetLeft);
		var deltaR = (parseInt(holder.style.width) + parseInt(holder.style.left) - offsetLeft) - maxWidth;
		
		if(pcord){
			if(((deltaT>0 | deltaB>0) && (deltaL>0 | deltaR>0)) |
			   (deltaT>0 && (xcord == "c" | pcord == "t")) |
			   (deltaB>0 && (xcord == "c" | pcord == "b")) |
			   (deltaL>0 && (ycord == "c" | pcord == "l")) |
			   (deltaR>0 && (ycord == "c" | pcord == "r"))
			   ){
				resizeHolderWithoutPointer();
			}
			
		}
		
		if(deltaT>0){
			holder.style.top = parseInt(holder.style.top) + deltaT + 'px'
			if(pcord){
				pointer.style.top = parseInt(pointer.getStyle('top')) - deltaT  + 'px'
			}
		}
		else if(deltaB>0){
			holder.style.top = parseInt(holder.style.top) - deltaB + 'px'
			if(pcord){
				pointer.style.top = parseInt(pointer.getStyle('top')) + deltaB  + 'px'
			}
		}
		
		if(deltaL>0){
			holder.style.left = parseInt(holder.style.left) + deltaL + 'px'
			if(pcord){
				pointer.style.left = parseInt(pointer.getStyle('left')) - deltaL  + 'px'
			}
		}
		else if(deltaR>0){
			holder.style.left = parseInt(holder.style.left) - deltaR + 'px'
			if(pcord){
				pointer.style.left = parseInt(pointer.getStyle('left')) + deltaR  + 'px'
			}
		}
	}
	
	var waitToHide = function(){
		if(!status){
			displayStatus = false;
			
			if(animation){
				if(animation.getHistoryCount() > 0){
					animation.first({onComplete: function(){
							holder.style.display = "none";
						}
					});
				}
			}else{
				holder.style.display = "none";
			}
		}
	}
	
	//END private methods
}