﻿var TooltipAnchor = new function() {
    this.Left = 0;
    this.Right = 1;
    this.Top = 2;
    this.Bottom = 3;
}
function Kensoft() {
    this.initTooltip();
}

Kensoft.prototype = {
    initTooltip: function() {
        this.tooltipDiv = document.createElement("div");
        this.tooltipDiv.id = "kensofttooltip";
        this.tooltipDiv.className = "kensofttooltip";
        this.tooltipBox = document.createElement("div");
        this.tooltipBox.className = "box";
        this.tooltipArr = document.createElement("div");
        this.tooltipArr.className = "arrow";

        this.tooltipDiv.appendChild(this.tooltipArr);
        this.tooltipDiv.appendChild(this.tooltipBox);
        var _this = this;
        $(document).ready(function() { //requires jquery
            document.body.appendChild(_this.tooltipDiv);
        });
    },
    tooltipMe: function(pObject, pAnchor) {
        if (document.getElementById("kensofttooltip") == null) {
            this.initTooltip();
        }
        var _this = this;
        this.tooltipBox.innerHTML = pObject.getAttribute("tip");
        this.tooltipDiv.style.display = "block";
        $(this.tooltipDiv).parent().remove(this.tooltipDiv);
        $(pObject).mouseout(function() {
            _this.hideTooltip();
        });
        $(pObject).parent().append($(this.tooltipDiv));
        switch (pAnchor) {
            case TooltipAnchor.Left:

                this.tooltipBox.style.top = "";
                this.tooltipBox.style.left = "";
                this.tooltipArr.style.left = "";
                this.tooltipArr.style.top = "";

                this.tooltipDiv.style.top = -(($(this.tooltipDiv).outerHeight() + $(pObject).outerHeight()) / 2) + "px";
                this.tooltipDiv.style.right = $(this.tooltipDiv).outerWidth() + "px"; //parseInt($(pObject).position().left);
                this.tooltipBox.style.bottom = "0px";
                this.tooltipBox.style.right = "23px";
                this.tooltipArr.style.right = "4px";
                this.tooltipArr.style.bottom = "5px";
                this.tooltipArr.style.backgroundImage = "url(images/ttlft.png)";
                break;
            case TooltipAnchor.Right:

                this.tooltipBox.style.top = "";
                this.tooltipBox.style.right = "";
                this.tooltipArr.style.right = "";
                this.tooltipArr.style.top = "";

                this.tooltipDiv.style.top = -(($(this.tooltipDiv).outerHeight() + $(pObject).outerHeight()) / 2) + "px";
                this.tooltipDiv.style.right = -$(this.tooltipDiv).outerWidth() + "px"; // + (2 * $(pObject).outerWidth())); // + $(pObject).outerWidth());
                this.tooltipBox.style.bottom = "0px";
                this.tooltipBox.style.left = "23px";
                this.tooltipArr.style.left = "4px";
                this.tooltipArr.style.bottom = "5px";
                this.tooltipArr.style.backgroundImage = "url(images/ttrgt.png)";
                break;
        }
    },
    hideTooltip: function() {
        this.tooltipDiv.style.display = "none";
    }
}

var KensoftTools = new Kensoft();
