var mouseX = 0;
var mouseY = 0;

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	if (mouseX < 0){mouseX = 0;}
	if (mouseY < 0){mouseY = 0;}
	return true;
}

function showImage ( theImageDiv ) {
	var d = document.getElementById(theImageDiv);
	d.style.left = 0;
	d.style.top = 0;
	d.style.visibility = "";
}
function moveImage ( theImageDiv ) {
	var windowW = document.all ? document.body.clientWidth : window.innerWidth;
	var windowH = document.all ? document.body.clientHeight : window.innerHeight;

	var d = document.getElementById(theImageDiv);
	
	if ( mouseX + 20 + d.clientWidth > windowW ) {
		if ( mouseX - 20 - d.clientWidth < 0 ) {
			d.style.left = mouseX - ((20 + d.clientWidth) / 2);
		} else {
			d.style.left = mouseX - 20 - d.clientWidth;
		}
	} else {
		d.style.left = mouseX + 20;
	}

	d.style.top = mouseY - 20 - d.clientHeight;
}
function moveImageImmo ( theImageDiv, pos ) {
	var windowW = document.all ? document.body.clientWidth : window.innerWidth;
	var windowH = document.all ? document.body.clientHeight : window.innerHeight;

	var d = document.getElementById(theImageDiv);
	
	d.style.left = mouseX + 50;
	if ( pos == 1 ) 
		d.style.top = mouseY - 150;
	if ( pos == 2 ) 
		d.style.top = mouseY - (d.clientHeight/2);
	if ( pos == 3 ) 
		d.style.top = mouseY - d.clientHeight + 50;
}
function hideImage ( theImageDiv ) {
	var d = document.getElementById(theImageDiv);
	d.style.visibility = "hidden";
}
function insertImage ( thumbFile, viewFile, viewID, viewW, viewH ) {
	document.write ( "<img style=\"border:1px solid black;\" src=\"/"+thumbFile+"\" onmouseover=\"showImage('"+viewID+"')\" onmousemove=\"moveImage('"+viewID+"')\" onmouseout=\"hideImage('"+viewID+"')\">" );
	document.write ( "<div id=\""+viewID+"\" style=\"position:absolute;width:"+viewW+"px;height:"+viewH+"px;visibility:hidden;background-color:#ffffcc;border:1px solid black;padding:5px;\"><img src=\""+viewFile+"\" width=\""+viewW+"\" height=\""+viewH+"\"></div>" );
}
function insertImageImmo ( thumbFile, viewFile, viewID, pos, objid, imgid ) {
	if ( objid && imgid ) document.write ( "<a target=_blank href=\"?page=immo&objekt="+objid+"&anschauen=bild&bild="+imgid+"\">" );
	document.write ( "<img style=\"border:1px solid black;\" src=\"/"+thumbFile+"\" onmouseover=\"showImage('"+viewID+"')\" onmousemove=\"moveImageImmo('"+viewID+"',"+pos+")\" onmouseout=\"hideImage('"+viewID+"')\">" );
	if ( objid && imgid ) document.write ( "</a>" );
	document.write ( "<div id=\""+viewID+"\" style=\"position:absolute;visibility:hidden;background-color:#ffffcc;border:1px solid black;padding:5px;\"><img src=\"/"+viewFile+"\" ></div>" );
}

