var b_IE = navigator.userAgent.indexOf('MSIE') > -1;
var move = false;
var hintX;
var hintY;
var hintOffsetX = 15;
var hintOffsetY = 10;
var hintID;
var divtextfirst = "Ждите... Идет загрузка первого сообщения темы.";
var divtextlast = "Ждите... Идет загрузка последнего сообщения темы.";
var start = false;
var onspan = false;
var ttt;
if (window.innerHeight != null) {
        getWinSz = function (b_hight) { return b_hight ? innerHeight : innerWidth; }
        getWinSc = function (b_hight) { return b_hight ? pageYOffset : pageXOffset; }
} else {
        getWinSz = function (b_hight) { return document.body[b_hight ? 'clientHeight' : 'clientWidth']; };
        getWinSc = function (b_hight) { return document.body[b_hight ? 'scrollTop' : 'scrollLeft']; };
}
 function InitHitSpan(){
            var elts = document.getElementsByTagName("SPAN");
            for (var i=0; i<elts.length; i++) {
                 var span = elts[i];
                 if (span.className.indexOf("spanhint")!=-1) {
                     id = span.getAttribute('id');
                     ids = id.split("::");
                     document.write ('<div id="hint'+id+'::1" align="left" class="hintclass" style="visibility:hidden;position:absolute;top:0px;left:0px;width:450px;">'+divtextfirst+'</div>');
                     document.write ('<div id="hint'+id+'::2" align="left" class="hintclass" style="visibility:hidden;position:absolute;top:0px;left:0px;width:450px;">'+divtextlast+'</div>');
                     attachspan(span,ids);
                     span.className = "NewHint";
                 }
            }
            start = true;

 }
 function attachspan(el,vars){

          var first = document.createElement('span');
          var end = document.createElement('span');
          InnerSpanText = '&nbsp;[<span class="spaninfo" onclick="return false" onMouseOver="ShowHint('+vars[0]+','+vars[1]+',1);" onMouseOut="HideHint()">F</span>/';
          InnerSpanText += '<span class="spaninfo" onclick="return false" onMouseOver="ShowHint('+vars[0]+','+vars[1]+',2);" onMouseOut="HideHint()">L</span>]';
          first.innerHTML = InnerSpanText;
          el.parentNode.insertBefore(first, el);
          el.parentNode.insertBefore(el, first);
 }
getSize = function (b_hight) {
        return b_hight ? document.getElementById(hintID).offsetHeight : document.getElementById(hintID).offsetWidth;
};
document.onmousemove = b_IE || window.opera
? function () {
        hintX = event.clientX + document.body.scrollLeft;
        hintY = event.clientY + document.body.scrollTop;
        if (move!=false) moveHint();
        return true;
}
: function (e) {
        hintX = e.pageX;
        hintY = e.pageY;
        if (move!=false) moveHint();
        return true;
};
function ShowHint (inforum,intopic,type) {

         if (start === true){
             hintID = "hint"+inforum+"::"+intopic+"::"+type;
             onspan = true;
             ttt = window.setTimeout("ShowRealHint("+inforum+","+intopic+","+type+")",1500);
             return ttt;
         }

}
function ShowRealHint (inforum,intopic,types) {
         if (onspan==true){
             if (document.layers) return;
             HideHint();
             if (document.getElementById(hintID).innerHTML == divtextfirst || document.getElementById(hintID).innerHTML == divtextlast){
                 window.frames['hidden_frame'].location.href = 'hints.php?inforum='+inforum+'&intopic='+intopic+'&t='+types;
             }
             document.getElementById(hintID).style.visibility = "visible";
             moveHint ();
             move=true;
         }
}

function HideHint () {
         if (start === true){
             onspan = false;
             window.clearTimeout(ttt);
             if (document.getElementById(hintID).style.visibility == "visible" ) {
                 document.getElementById(hintID).style.visibility = "hidden";
                 move = false;
             }
         }
}

function moveHint () {
        var n_x = hintX + hintOffsetX;
        var n_y = hintY + hintOffsetY;
        var n_w = getSize(false), n_h = getSize(true);

        var n_win_w = getWinSz(false), n_win_h = getWinSz(true);
        var n_win_l = getWinSc(false), n_win_t = getWinSc(true);
        if (n_x> (n_win_w + n_win_l)/2) n_x = n_win_w + n_win_l - n_w-25-(n_win_w + n_win_l-n_x);
        if (n_x < n_win_l) n_x = n_win_l;
        if (n_y + n_h > n_win_h + n_win_t) n_y = n_win_h + n_win_t - n_h-25;
        if (n_y < n_win_t) n_y = n_win_t;
        document.getElementById(hintID).style.left = n_x;
        document.getElementById(hintID).style.top = n_y;
}
