<!--
	/*
		Sweet Titles Constructor
		@param {String/HTMLElement/Array} oEls : Accepts a string for an id, a DOM HTMLElement reference, or an HTML Array Collection
		@param {Object} attr : Attributes to customize your sweet titles. Possible properties are as follows:
		@type {Int} (optional) : time | The length of the fade in effect. Default is 0.5
		@type {String} (optional) : tipClass | An optional className to reference your tooltip. Default is 'tip'
		@type {String} (optional) : imgClass | An optional className to reference your image. Default is 'imgGallery'
		@type {String} (optional) : imgClassOver | An optional className to reference your image. Default is 'imgGalleryOver'
		@type {Int} (optional) : opacity | The final opacity after "fade in". Default is 1
		@type {Int} (optional) : timeout | the amount of time the tooltip will fire. Default is 500 (0.5 seconds)
		@type {Int} (optional) : isFix | set if the tooltip has a fixed position
		@type {Int} (optional) : offsetX | set if the tooltip offset X  position default is 15
		@type {Int} (optional) : offsetY | sset if the tooltip offset Y  position default is 15
		@type {bolean} (optional) : rollaisOn | set  the rollover on the element default is false
	*/
	YAHOO.widget.toolTitles = function(oEls, attr) {
		this.oEls = oEls;
		this.timeout = attr.timeout || 200;
		this.tipClass = attr.tipClass || 'tip';
		this.imgClass = attr.imgClass || 'imgGallery';
		this.imgClassOver = attr.imgClassOver || 'imgGalleryOver';
		this.isFix = attr.isFix || 0;
		this.offsetX = attr.offsetX || 15;
		this.offsetY = attr.offsetY|| 15;
		this.rollaisOn=attr.rollaisOn|| false
		this.tip = document.createElement('div');
		this.tip.className = this.tipClass;
		this.showHeader=attr.showHeader || false
		this.showFooter=attr.showFooter || false
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.sweetLinks = [];
        this.opacity=attr.opacity || 100;
       
        
		this.xy = [];
		this.attributes = {};
 
		this.tip.style.position = 'absolute';
		this.tip.style.top = '0';
		this.tip.style.left = '0';
		this.tip.style.visibility = 'hidden';
	};
	/*
		Shared methods of the prototype to speed things up.
		No need for this.methodName
	*/
	YAHOO.widget.toolTitles.prototype = function() {
		var $D = YAHOO.util.Dom;
		var $E = YAHOO.util.Event;
		var $A = YAHOO.util.Anim;
		var $ = $D.get;
		return {
			init : function() {
				this.attributes = {
					opacity : {
						to : this.opacity,
						from : 0
					}
				};
              
				$D.batch($(this.oEls), this.nuke, this, true);
				$E.on(this.sweetLinks, 'mouseover', this.over, this, true);
				$E.on(this.sweetLinks, 'mousemove', this.move, this, true);
				$E.on(this.sweetLinks, 'mouseout', this.out, this, true);
			  },
			
			  nuke : function(oEl) {
				if ( !oEl.getAttribute('title') || 
					oEl.getAttribute('title') == null ||
					oEl.getAttribute('title') == '' ) {
					return;
			  }
			  oEl.setAttribute('tip', oEl.getAttribute('title'));
			  oEl.removeAttribute('title'); 
			  // prevent the deafualt tooltip
			  this.sweetLinks.push(oEl);
			},
			over : function(e) {
				this.curTip = $E.getTarget(e, true);
				this.rolla()
				this.xy = $E.getXY(e);
				var that = this;
				var fn = function() {that.animate(); };
				tipTimer = setTimeout(fn, this.timeout);
			},
			move : function(e) {
				this.curTip = $E.getTarget(e, true);
				this.xy = $E.getXY(e);
				var that = this;
				if(this.isOver==1)that.animate();
			},
			out : function() {
			    this.rolla()
				this.tip.style.visibility = 'hidden';
				window.clearTimeout(tipTimer);
				this.isOver=0
				
			},
			animate : function() {
			    this.isOver=1
				this.tip.style.visibility = 'visible';
				this.createBox();
				this.calculatePos()  
			},
			rolla:function(){
			   if(this.rollaisOn==true){
			 	if(this.curTip.className==this.imgClass)this.curTip.className=this.imgClassOver;
	  		 	else this.curTip.className=this.imgClass
			   }
			},
			
			calculatePos:function(){
			  this.curTipXY = $D.getXY(this.curTip); 
			  this.curTipW = this.curTip.width;
			  this.curTipH = this.curTip.height; 
			  this.tipW = this.tip.offsetWidth;
			  this.tipH = this.tip.offsetHeight;
			  this.tip.className=this.tipClass
			 
			  if(this.isFix==1){ 
			      var curX=this.curTipXY[0]+this.curTip.width+2
			      var curY=this.curTipXY[1]+this.offsetY
				    if(this.curTipXY[0]+this.curTipW+this.tipW > $D.getViewportWidth()){
			         curX=this.curTipXY[0]-this.tipW+3
			        }
			        if(this.curTipXY[1]+this.curTipH> $D.getViewportHeight()){
					   //curY=this.curTipXY[1]-this.tipH+this.offsetY
					 
				   }  
				   $D.setXY(this.tip,[curX,curY]);
		      } 
			  else if ( this.xy[0]+this.tipW > $D.getViewportWidth() ) {
					this.boxHeader.className="tipHeaderL"
					$D.setX(this.tip, this.xy[0]-this.tipW-(2*this.offsetX));
					$D.setY(this.tip, this.xy[1]+this.offsetY);
				}
			   else {
					$D.setXY(this.tip, [this.xy[0]+this.offsetX, this.xy[1]+this.offsetY]);
				}
		       
			   
			},
			
			createBox:function(){
			   this.tip.innerHTML='';
			   if(this.showHeader){
				   this.boxHeader = document.createElement('div');
		           this.boxHeader.className = "tipHeader";
				   this.tip.appendChild(this.boxHeader);
				}
			    if(this.curTip.getAttribute('tip')){
                   
				  	this.boxBody = document.createElement('div');
				    this.boxBody.className = "tipBody";
				    this.tip.appendChild(this.boxBody);
				    this.boxBody.innerHTML=this.curTip.getAttribute('tip');
				}
				 if(this.showFooter){
				   this.boxHeader = document.createElement('div');
		           this.boxHeader.className = "tipFooter";
				   this.tip.appendChild(this.boxHeader);
				}
			}
			
			
		};
	}();
	

