/* 
 * TOOL TIP CLASS
 * @autor Stanislav Zorjan - stanislav.zorjan@symblaze.com
 */

function ToolTip(tollTipDiv, toolTipText){
    /*reference to this instance*/
    var _this_$ = this;
    document.documentElement._this_$ = _this_$;

    /* TOOL TIP BASIC PARAMETERS */

    /*time after which tool tip is shown. Time in milliseconds*/
    this.showTTAfter = 0;

    /*time after which tool tip is hidden. Time in milliseconds*/
    this.hideTTAfter = 0; // 0 - tool tip is visible until is manually hidden with hide() method

    this.hideDelay = 0;

    /*hides tool tip on mouse moove <Boolean> true or false*/
    this.hideTTOnMouseMoove = false;


    this.onRollOverDontHide = true;

    /*main tool tip div element used for show or hide tool tip*/
    this._toolTip = document.getElementById(tollTipDiv);

    /*element in which is tool tip text shown*/
    this._toolTipText = document.getElementById(toolTipText);

    /*elements where are stored style elements*/
    // this._topMiddle = document.getElementById("TopMiddle");
    //this._bottomMiddle = document.getElementById("BottomMiddle");

    /*this is _this_$ sample of tool tip text*/
    this.value = '<p>EXAMPLE OF TOOL TIP TEXT <br /><_this_$ href="#">Click here</_this_$></p>';

    /*flag for holding value if tool tip is hovered with mouse*/
    this.over = false;


    /***************************************************************************
     * Method for monitoring mouse move for displaying toolt tip on cursor place
     */
    this.handleMouseMove = function (evt) {
    /*
        var _this_$ = document.documentElement._this_$;
        if(_this_$._toolTip.style.visibility == "hidden" ){
            try{
                _this_$._toolTip.style.top = evt.pageY-_this_$._toolTip.offsetHeight-20+"px";
                _this_$._toolTip.style.left = evt.pageX-5+"px";
            }catch(e){
                 _this_$._toolTip.style.top = window.event.clientY - _this_$._toolTip.offsetHeight-20+document.documentElement.scrollTop+"px";
                _this_$._toolTip.style.left = window.event.clientX -5 + "px"; 
            }
        }*/
    }

    /*registering mouse move event*/
    document.onmousemove = _this_$.handleMouseMove;
   

    /***************************************************************************
    * Method invoked with "on mouse over" event
    */
    this._toolTip.onmouseover = function(){
        var _this_$ = this._this_$;
        _this_$.over = true;
        clearTimeout(_this_$.timeout2);
        clearTimeout(_this_$.timeout3);
        clearTimeout(_this_$.timeout4);
    }

   

    /***************************************************************************
     * Method invoked with "on mouse out" event
     */
    this._toolTip.onmouseout = function(){
        var _this_$ = this._this_$;
        _this_$.timeout4 = setTimeout(function(){
            _this_$.hide2();
        }, 10);
            
    }




    /***************************************************************************
     * Method for creating and displaying tool tip
     */
    this.show1 = function(){
        var _this_$ = this;
        this._toolTip.style.visibility = "visible";
    }

    /***************************************************************************
     * Method for building tool tip
     */
    this.build = function(value){
        var _this_$ = this;
        this._toolTipText.innerHTML = document.getElementById(value).innerHTML;

        //this._topMiddle.style.width = this._bottomMiddle.style.width = parseInt(this._toolTipText.offsetWidth)-15+(this._toolTipText.style.marginLeft)+"px";

        /*
         * hides tool tip after specified interval
         * only if this.hideTTAfter is greater than 0 else tool tip should be
         * removed manually with remove method
         */
        if(this.hideTTAfter > 0){
            clearTimeout(this.timeout2);
            this.timeout2 = setTimeout(function(){
                _this_$.hide();
            }, this.hideTTAfter);
        }
    }




    /***************************************************************************
     * Method for displaying tool tip
     * @param value (id of html element that will be shown in tool tip)
     */
    this.show = function(value, left1, top1, name){
        var _this_$ = this;
        this._toolTip._this_$ = _this_$;
        document.documentElement._this_$ = _this_$;
        /*adding value to instance value*/
        this.value = value;
        // if(_this_$.over == false){
        this._toolTip.style.visibility = "hidden";
        // }
        


        
        /*first clears timeout so there is no same timeouts already running*/
        clearTimeout(this.timeout);
        clearTimeout(this.timeout2);
        clearTimeout(this.timeout3);
        clearTimeout(this.timeout4);

        /*building tool tip before it is displayied on screen*/
        this.build(this.value);

        /*creating timeout for displaying tool tip*/
        this.timeout = setTimeout(function(){
            _this_$.show1(_this_$.value);
        }, this.showTTAfter);

        var document_left = document.getElementById('main').offsetLeft;
        var works_left = document.getElementById("uncle_works").offsetLeft;
        var works_top = document.getElementById("uncle_works").parentNode.offsetTop;

        var bg3_top = document.getElementById("background").offsetHeight+document.getElementById("background2").offsetHeight;
        var ucpw_top = document.getElementById("uncles_people_wrapper").offsetTop;
        var ucp_top = document.getElementById("uncle_people").offsetTop;
        var ucp_left = document.getElementById("uncle_people").offsetLeft;
        var top2 = 0;
        var left2 = 0;

        if(name == "tooltip1"){
            left2 = left1 + document_left + works_left;
            top2 = top1 + works_top;
        }else{
            left2 = left1 + document_left + ucp_left;
            top2 = top1 + bg3_top + ucpw_top + ucp_top;
        }
        //object.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetTop;
        //object.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft;
        

        if(_this_$._toolTip.style.visibility == "hidden" ){
            try{
                _this_$._toolTip.style.top = top2 -_this_$._toolTip.offsetHeight+50+"px";
                _this_$._toolTip.style.left = left2+"px";
            }catch(e){
                _this_$._toolTip.style.top = top2+"px";
                _this_$._toolTip.style.left = left2+"px";
            }
        }

    }

    /***************************************************************************
     * Method for removing tool tip
     */
    this.hide = function(){
        var _this_$ = this;
        /*first clears timeout so there is no same timeouts already running*/
        clearTimeout(this.timeout3);
        clearTimeout(this.timeout);
        this.over = false;
        /*creating timeout for displaying tool tip*/
        this.timeout3 = setTimeout(function(){
            _this_$.hide1();
        }, this.hideDelay);
        
    }

    /***************************************************************************
     * Method for hidding tool tip;
     */
    this.hide1 = function(){
        var _this_$ = this;
        if(!this.over){
            this._toolTip.style.visibility = "hidden";
        }
    }
    this.hide2 = function(){
        var _this_$ = this;
        _this_$.timeout2 = setTimeout(function(){
            _this_$.hide();
        }, _this_$.hideTTAfter);
    }
}
