var cp = document.getElementById( "PopupWindow" )
var mouseX = 0
var mouseY = 0

/*rozmery okna*/
function browserwidth() {
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
    } else {
        if( document.documentElement &&
            ( document.documentElement.clientWidth || 
              document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
        } else {
            if( document.body && 
                ( document.body.clientWidth || document.body.clientHeight ) ) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
      }
    }
  }
  return myWidth;
}

function browserheight() {
    var myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myHeight = window.innerHeight;
    } else {
        if( document.documentElement &&
            ( document.documentElement.clientWidth || 
              document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myHeight = document.documentElement.clientHeight;
        } else {
            if( document.body && 
                ( document.body.clientWidth || document.body.clientHeight ) ) {
                //IE 4 compatible
                myHeight = document.body.clientHeight;
      }
    }
  }
  return myHeight;
}

/*show popup*/
function showPopup( obsah ) {
    cp.innerHTML=obsah;
    cp_sizex = cp.scrollWidth
    cp_sizey = cp.scrollHeight
    x = mouseX + 20;
    if ( x > browserwidth() - cp_sizex) {
        x = mouseX - cp_sizex;
        if ( x < 0 ) {
            x = 0;
        }
    }
    if (document.all) { 
        yoff = document.body.scrollTop;
        y = mouseY + yoff;
    } else { 
        yoff = window.pageYOffset;
        y = mouseY;
    }
    if ( y > browserheight() + yoff - cp_sizey - 20 ) {
        y = browserheight() + yoff - cp_sizey - 20;
        if ( y < yoff ) {
            y = yoff;
        }
    }
    cp.style.left = x + 'px';
    cp.style.top = y + 'px';
    cp.style.visibility = 'visible';
}

/*hide popup*/
function hidePopup() {
    cp.style.visibility='hidden';
}

function RecordMouse(e) {
    if (!e) {
        mouseX = window.event.clientX;
        mouseY = window.event.clientY;
    }
    else {
        mouseX = e.pageX;
        mouseY = e.pageY;
    }
}
document.onmousemove = RecordMouse;
