﻿var _t = 0;
var Id;
function ShowFloatingWindow(id, content) {
    //Get the id of the parent element.
    Id = id;
    //Needed this if encrypted the text.
    content = content.replace("~~", "==");
    content = content.replace("~", "="); 
    //Call server method to decrypt.  
    content = PageMethods.Decrypt(content, ShowFloatingWindowData);
    if (_t != 0) {
        clearTimeout(_t);
        _t = 0;
    }
}

function ShowFloatingWindowData(content) { 
    //Add data to Div.
    $("#divWin").html(content);
    //Adjust the window according to height of the text.
    var $c = $("#" + Id);
    var $d = $("#divWin");
    var wh = $(window).height();
    var wo = $(document).scrollTop();
    var dh = $d.height();

    var dleft = $c.offset().left + 10;
       
    if (dh > wh) {       
        $d.css({
            position: 'absolute',
            top: $c.offset().top - 200,
            left: dleft
        });
    }
    else {
        var s = wh - ($c.offset().top - wo);
        if (s > dh) {                  
            $d.css({
                position: 'absolute',
                top: $c.offset().top + 15,
                left: dleft
            });
        }
        else {             
            $d.css({
                position: 'absolute',
                top: wo + wh - dh - 10,
                left: dleft
            });
        }
    }
    $("#divWin").show();
    
}
function HideFloatingWindow() {
    if (_t == 0) {
        _t = setTimeout("HideFloatingWindowDelayed()", 300);
    }       
}

function HideFloatingWindowDelayed() {
    $("#divWin").hide();
    if (_t != 0)
        clearTimeout(_t);
    _t = 0;
}

function HideFloatingWindowCancel() {
    clearTimeout(_t);
    _t = 0;
}





