/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
//
// Modified by Profilog, 2006
*/

var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['a', 'input', 'span', 'img', 'div'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	tipIn1 : Object,					    // 
	tipIn2 : Object,						// 
	tipIn3 : Object,						// 
	tipIn4 : Object,						// 
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
        
		this.tip = document.createElement('div');
		this.tip.className = 'toolTip';
        this.tip.style.position = 'absolute';
        this.tip.style.visibility = 'hidden';
        this.tip.style.zIndex = 99999;
        
        
		this.tipIn1 = document.createElement('div');
		this.tipIn1.className = 't1'; 
        this.tipIn1.id = 't1id';
        this.tipIn1.style.position = 'absolute';
        this.tipIn1.style.visibility = 'hidden';

		this.tipIn2 = document.createElement('div');
		this.tipIn2.className = 't2'; 
        this.tipIn2.id = 't2id';
        this.tipIn2.style.position = 'absolute';
        this.tipIn2.style.visibility = 'hidden';
        
		this.tipIn3 = document.createElement('div');
		this.tipIn3.className = 't3';
        this.tipIn3.id = 't3id';
        this.tipIn3.style.position = 'absolute';
        this.tipIn3.style.visibility = 'hidden';
        
		this.tipIn4 = document.createElement('div');
		this.tipIn4.className = 't4';
        this.tipIn4.style.visibility = 'hidden';
        
        this.tipIn3.appendChild(this.tipIn4) ;
        this.tip.appendChild(this.tipIn3) ;
        this.tip.appendChild(this.tipIn2) ;
        this.tip.appendChild(this.tipIn1) ;
        
		document.getElementsByTagName('body')[0].appendChild(this.tip);
        
		this.tip.style.top = '0';
		//this.tip.style.visibility = 'visible';
        
        this.attachBehavior() ;

	},
    attachBehavior : function()
    {
		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") && current[j].getAttribute("title") != "")
				{
                    current[j].onmouseover = this.tipOver ;
                    current[j].onmouseout = this.tipOut ;
					//addEvent(current[j],'mouseover',this.tipOver);
					//addEvent(current[j],'mouseout',this.tipOut);
					current[j].setAttribute('tip',current[j].title);
					current[j].removeAttribute('title');
					
					// profilog
					current[j].removeAttribute('alt');
					subEl = current[j].getElementsByTagName("img") ;
					for ( k=0; k<subEl.length; k++ ) 
					{
						var oneImg = subEl[k] ;
						oneImg.removeAttribute('title');
						oneImg.removeAttribute('alt');	
					}
				}
			}
		}
    },
    
	updateXY : function(e) {
		if ( document.captureEvents ) 
        {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
        } 
        else if ( window.event.clientX && document.documentElement.scrollTop) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
        else if(window.event.clientX != null && document.body.scrollTop != null)
        {
			sweetTitles.xCord = window.event.clientX+document.body.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.body.scrollTop;
            
		}     
	},
    
    
    
	tipOver : function(e) {
    
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
        
        if(typeof sweetTitles == "undefined")
        {
            return ;
        }

		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",200);
		sweetTitles.updateXY(e);
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
        
        if(typeof sweetTitles != "undefined")
        {
		    sweetTitles.tipIn1.style.opacity = '1.0';
        }
        tID = window.setTimeout("if(typeof sweetTitles != 'undefined'){sweetTitles.tipFadeOut(100,'sweetTitles.tipIn1', 20);}",100);
        
	},
	tipShow : function() {	

        if(!this.tip)
        {
            return
        }
        this.tip.style.opacity = '1';
		this.tip.style.visibility = 'visible';
        this.tipIn1.style.visibility = 'visible';
		this.tipIn2.style.visibility = 'hidden';
		this.tipIn3.style.visibility = 'hidden';
		this.tipIn4.style.visibility = 'hidden';
		this.tipIn1.style.opacity = '.1';
    
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY-15);
		var lt = parseInt(scrX+5);
		var addy = '';
		var access = '';

        this.tipIn1.style.left = "0px" ;
        this.tipIn2.style.left = "6px" ;
        this.tipIn3.style.left = "15px" ;
           
        this.tipIn1.style.top = "0px" ;    
        this.tipIn2.style.top = "-13px" ;
        this.tipIn3.style.top = "-26px" ;
        
        if(!this.obj.getAttribute)
        {
            return ;
        }
        
        
        if(this.obj.getAttribute('rel') && this.obj.getAttribute('rel').substring(0, 10) == 'sweetTitle')
        {
            var classHere = this.obj.getAttribute('rel') ;
        }
        else
        {
            var classHere = "sweetTitle0" ;
        }
        
        this.tip.className = "x" + classHere ; 

		this.tipIn4.innerHTML = "<nobr>" + this.obj.getAttribute('tip') + "</nobr>" ; 
        

        if(document.documentElement.scrollLeft != null)
        {
		    if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			    this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		    } else {
			    this.tip.style.left = lt+'px';
		    }
        }
        else
        {
		    if ( parseInt(document.documentElement.clientWidth+document.body.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			    this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		    } else {
			    this.tip.style.left = lt+'px';
		    }
        }

        var tempWidth ;
        
        if(document.body.clientWidth != null && document.body.clientWidth != 0 && (document.documentElement.clientWidth == null || document.documentElement.clientWidth == 0) )
        {
            tempWidth = document.body.clientWidth ;
        }
        else
        {
             tempWidth = document.documentElement.clientWidth ;
        }

		if( (parseInt(tempWidth + document.documentElement.scrollLeft)) < parseInt(findPosX(this.tipIn3) + this.tipIn3.offsetWidth)) 
        {
            this.tip.style.left = (parseInt(this.tip.style.left) - 10) + "px" ;
            this.tipIn1.style.left = "-20px" ;
            this.tipIn2.style.left = "-30px" ;
            this.tipIn3.style.left = "-" + (this.tipIn3.offsetWidth + 20) + "px" ;
		}
        

        if(document.documentElement.scrollTop != null)
        {
		    if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			    this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		    } else {
			    this.tip.style.top = tp+'px';
		    }
        }
        else
        {
		    if ( parseInt(document.documentElement.clientHeight+document.body.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			    this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		    } else {
			    this.tip.style.top = tp+'px';
		    }
        }


        
        var tempHeight ;
        if(document.body.scrollTop != null && document.body.scrollTop != 0 && (document.documentElement.scrollTop == null || document.documentElement.scrollTop == 0))
        {
            tempHeight = document.body.scrollTop ;
        }
        else
        {
             tempHeight = document.documentElement.scrollTop ;
        }
        
        
        
		if( (parseInt(tempHeight)) > parseInt(findPosY(this.tipIn3)))
        {
            this.tip.style.top = parseInt(this.tip.style.top) + 25 + "px" ;

            this.tipIn1.style.top = "0px" ;
            this.tipIn2.style.top = "8px" ;
            this.tipIn3.style.top = "18px" ;
		}

		//this.tipFade(100, "this.tipIn1", 15, 100);

        this.tipBing("this.tipIn1");
	},
    
    tipBing: function(divStr)
    {
        var div = eval(divStr) ;
        
        div.style.visibility = 'visible';
        div.style.opacity = '1' ;
		div.style.filter = "alpha(opacity:100)";

        if(div == this.tipIn1)
        {
            opacityID = setTimeout('sweetTitles.tipBing("this.tipIn2");', 125) ;
        }
        else if(div == this.tipIn2)
        {
            opacityID = setTimeout('sweetTitles.tipBing("this.tipIn3");', 200) ;
        }
        else if(div == this.tipIn3)
        {
            this.tipIn4.style.visibility = 'visible';
		    this.tipIn4.style.opacity = '0';
            
           opacityID = setTimeout('sweetTitles.tipFade(0, "this.tipIn4", 60, 100);', 200) ;  
        }
    },

    
	tipFade: function(opac, divStr, speed, opamax) {

        var div = eval(divStr) ;
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < opamax ) { // 80
			div.style.opacity = '.'+newOpac;
			div.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"', '" + divStr + "', " + speed + ", " + opamax + ")", speed);
		}
		else { 
            if(opamax >= 100)
            {
                div.style.opacity = '1.0' ; //.80
            }
            else
            {
                div.style.opacity = '0.' + opamax ; //.80
            }
			
			div.style.filter = "alpha(opacity:" + opamax + ")"; // 80
            
            if(div == this.tipIn1)
            {
                this.tipIn2.style.visibility = 'visible';
		        this.tipIn2.style.opacity = '.1';
                
                opacityID = setTimeout('sweetTitles.tipFade(100, "this.tipIn2", 25, 100);', 500) ;
		        
            }
            else if(div == this.tipIn2)
            {
                this.tipIn3.style.visibility = 'visible';
		        this.tipIn3.style.opacity = '.1';
		        this.tipFade(100, "this.tipIn3", 25, 100);
                
                opacityID = setTimeout('sweetTitles.tipFade(100, "this.tipIn3", 25, 100);', 500) ;
                
            }
            else if(div == this.tipIn3)
            {
                this.tipIn4.style.visibility = 'visible';
		        this.tipIn4.style.opacity = '0';
		        this.tipFade(0, "this.tipIn4", 60, 100);
            }
		}
	},
    
    hidenow : function() {
        this.tipIn1.style.visibility = 'hidden';
        this.tipIn2.style.visibility = 'hidden';
        this.tipIn3.style.visibility = 'hidden';
        this.tipIn4.style.visibility = 'hidden';
    },
    
	tipFadeOut: function(opac, divStr, speed) {
        var div = eval(divStr) ;
        
        if(div && div.style)
        {
		    var passed = parseInt(opac);
		    var newOpac = parseInt(passed-10);
		    if ( newOpac > 0 ) {
			    div.style.opacity = '.'+newOpac;
			    div.style.filter = "alpha(opacity:"+newOpac+")";
			    opacityID = window.setTimeout("sweetTitles.tipFadeOut('"+newOpac+"', '" + divStr + "', " + speed + ")",speed);
		    }
		    else { 
			    div.style.opacity = '0'; //.80
			    div.style.filter = "alpha(opacity:0)"; // 80
                div.style.visibility = 'hidden';
                
                if(div == this.tipIn1)
                {
		            this.tipIn2.style.opacity = '1.0';
                    sweetTitles.tipFadeOut(100,'this.tipIn2', 20) ;
                }
                else if(div == this.tipIn2)
                {
		           this.tipIn4.style.opacity = '1.0';
                   sweetTitles.tipFadeOut(100,'this.tipIn4', 20) ;  
                }
                else if(div == this.tipIn4)
                {
		            this.tipIn3.style.visibility = "hidden" ;   
                }
		    }
        }
	}
    
};
