﻿/**  ToolTips
-------------------------------------------------------------*/

var tooltip = function() {this.init.apply(this, arguments)};
tooltip.prototype = {

    //Properties-----------------------------------------------
    
    anchor: null,
    to_on:  null,
    to_off: null,
    
    //Config---------------------------------------------------
    
    config: {
       on_delay: 200,
       off_delay: 300
    },
    
    //Constructor----------------------------------------------
    
    //Init
    init: function(el) {
        this.anchor = el;
        var object = this;
        
        //OnClick Handler
        this.anchor.onclick = function() {
            clearTimeout(object.to_off);
            object.activate();
        }
        
        //OnMouseOver Handler
        this.anchor.onmouseover = function() {
            clearTimeout(object.to_off);
            object.to_on = setTimeout(function () {
                object.activate();
            },object.config.on_delay);
        };
        
        //OnMouseOut Handler
        this.anchor.onmouseout = function() {
            clearTimeout(object.to_on);
            object.to_off = setTimeout(function () {
                object.reset();
            },object.config.off_delay);
        }; 
        
    },
    
    //Methods--------------------------------------------------
    
    activate: function() {
        this.anchor.className = 'tooltip tt_active';
    },
    
    reset: function() {
        this.anchor.className = 'tooltip';
    }
};


/** Init Behaviour
-------------------------------------------------------------*/
var rules = {
    'a.tooltip' : function(el) {
        var tip = new tooltip(el);
        var maincontent = document.getElementById("maincontent");
        var contextual = document.getElementById("contextual");
        
        if(maincontent != null)
			maincontent.style.overflow = "visible";
		if(contextual != null)
			contextual.style.overflow = "visible";
    }
}

Behaviour.register(rules);


