
var wait_for_object_ref = 0;
var wait_time = 700;

function wait_for_info(div_id, object_ref, image_exists, e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
        posx = e.pageX - document.body.scrollLeft - document.documentElement.scrollLeft;
        posy = e.pageY - document.body.scrollTop - document.documentElement.scrollTop;
    }
    else if (e.clientX || e.clientY)
    {
        posx = e.clientX;
        posy = e.clientY;
    }
	if (wait_for_object_ref != object_ref) {
		wait_for_object_ref = object_ref;
		var func_call = "show_pop_info('" + div_id + "', '" + object_ref + "', '" + image_exists + "', '" + posx + "', '" + posy + "')";
		setTimeout(func_call, wait_time);
	}
}	 

function show_pop_info(div_id, object_ref, image_exists, posx, posy) {
	if (wait_for_object_ref == object_ref) {
        var winW = getWidth();
        var winH = getHeight();
//	   alert(posx + ',' + posy + "   " + winW + ',' + winH);
	   var from_bottom = winH - posy;
	   var move_up = 0;
	   if (from_bottom < 200) {
	       move_up = 200 - from_bottom;
	   }
//	   alert('Height: ' + winH + '. Y: ' + posy + '. From bottom: ' + from_bottom + '. Moving up: ' + move_up);
        var position = 20 - move_up;
		$(div_id).style.visibility="visible";
		$(div_id).style.zIndex=10;
        $(div_id).style.marginTop = position + "px";
        if (move_up) {
            if (posx > 140) {
                $(div_id).style.marginLeft = posx - 40 + "px";
            }
        }
		$("image_" + div_id).src = image_exists;
		wait_time=100;
	}
}

function hide_info(div_id, object_ref) {
	if (wait_for_object_ref == object_ref) {
		wait_for_object_ref = 0;
		$(div_id).style.visibility="hidden";
		setTimeout("reset_wait_time()",5000);
	}
}

function reset_wait_time () {
	if(wait_for_object_ref==0) {
		wait_time=700;
	}
}

function getWidth() {
  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 getHeight() {
  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;
}

