var kursor = {x:0, y:0};

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    var offset_top=getScrollY();
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + 
            (document.documentElement.scrollLeft || 
            document.body.scrollLeft) - 
            document.documentElement.clientLeft;
        cursor.y = e.clientY + 
            (document.documentElement.scrollTop || 
            document.body.scrollTop) - 
            document.documentElement.clientTop;
    }
    cursor.y=cursor.y - offset_top;
    return cursor;
}

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

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

function getScrollY() 
{
var scrOfY = 0;
if( typeof( window.pageYOffset ) == 'number' )
  {
  //Netscape compliant
  scrOfY = window.pageYOffset;
  } 
  else if( document.body && document.body.scrollTop) 
  	{
    //DOM compliant
    scrOfY = document.body.scrollTop;
    } 
    else if(document.documentElement && document.documentElement.scrollTop)
      {
      //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
      }
return (scrOfY);
}

function show_photo(path, w, h)
{
var window_width=getWindowWidth();
var window_height=getWindowHeight();
var offset_top=getScrollY();
l = kursor.x-w/2;
if (l < 0) 
  {
  l=20;
  }
else if (l > window_width-w-20)
  {
  l= window_width - w - 20;
  }
t = kursor.y-h/2;
if (t < 0) 
  {
  t=0;
  }
else if (t > window_height-h)
  {
  t= window_height - h;
  }
t=t+offset_top;
document.getElementById("divfotka").style.left=l+'px';
document.getElementById("divfotka").style.top=t+'px';
document.getElementById("divfotka").style.width=w+'px';
document.getElementById("divfotka").style.height=h+'px';
document.getElementById("divfotka").style.visibility='visible';
}

function hide_photo()
{
document.getElementById("divfotka").style.visibility='hidden';
document.getElementById("imgfotka").src="";
}

function uaktualnij_wsp(e)
{
kursor=getPosition(e);
}

function init()
{
  document.onmousemove = uaktualnij_wsp;
}
