﻿var divTime;
var windowWidth = 0;
var windowHeight = 0;

function WndSize() {
    if (self.innerWidth) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    else {
        windowWidth = 0;
        windowHeight = 0;
    }
}

function clearTimer(timer) {
    window.clearTimeout(timer);
    divTime = null;
}

function Acronym_MouseOver(sender, event, termId) {
    if (divTime != null)
        clearTimer(divTime);
    else {
        clearTimer(divTime);
        divTime = window.setTimeout('ShowTip(' + termId + ',' + Event.pointerX(event) + ',' + Event.pointerY(event) + ');', 500);
    }
}

function ShowTip(termId, x, y) {
    var tableTip = document.getElementById('tableTip_' + termId);
    var divTip = document.getElementById('divTip_' + termId);
    var topCloudTr = document.getElementById('topCloudTr_' + termId);
    var bottomCloudTr = document.getElementById('bottomCloudTr_' + termId);
    tableTip.style.display = 'block';

    var c = tableTip.offsetWidth;

    if (tableTip.offsetWidth > 340)
        tableTip.style.width = '350px';

    if (divTip.offsetHeight > 400)
        divTip.style.height = '300px';
    //определяем размеры окна
    WndSize();

    var topCorner = document.getElementById('top_div_' + termId);
    var bottomCorner = document.getElementById('bottom_div_' + termId);

    if (x > windowWidth / 2) {
        topCorner.className = 'top_right_cloud_corner';
        bottomCorner.className = 'bottom_right_cloud_corner';

        tableTip.style.left = x - tableTip.offsetWidth + 'px';
    }
    else {
        topCorner.className = 'top_left_cloud_corner';
        bottomCorner.className = 'bottom_left_cloud_corner';

        tableTip.style.left = x + 'px';
    }

    if (y - document.viewport.getScrollOffsets().top > windowHeight / 2) {
        topCloudTr.style.display = 'none';
        bottomCloudTr.style.display = '';
        tableTip.style.top = y - tableTip.offsetHeight - 20 + 'px';
    }
    else {
        topCloudTr.style.display = '';
        bottomCloudTr.style.display = 'none';
        tableTip.style.top = y + 20 + 'px';
    }


    clearTimer(divTime);
}

function Acronym_MouseOut(termId) {
    clearTimer(divTime);
    divTime = window.setTimeout('HideTip(' + termId + ');', 50);
}

function DivTip_MouseOver(sender) {
    if (divTime != null)
        clearTimer(divTime);
}

function HideTip(termId) {
    var tableTip = document.getElementById('tableTip_' + termId);
    /*var divTip = document.getElementById('divTip_' + termId);*/
    tableTip.style.display = 'none';
    clearTimer(divTime);
}