var divElm;
var bodyElm;
var imgElm;
var timer;
var show = 0;

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function gettrailobj() {
	bodyElm = document.body;
	divElm = document.createElement('div');
	divElm.setAttribute('id', 'imgDiv');
	bodyElm.appendChild(divElm);
	divElm.innerHTML = 'Wird geladen!';
	show = 1;
}

function hidetrail()
{
    clearTimeout(timer);
    if(show == 1) {
	    bodyElm.removeChild(divElm);
	    show = 0;
    }

}


function showtrail(bildName) {
    timer = setTimeout("showIMG('"+bildName+"');", 500);
}

function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1){

		var xcoord=20
		var ycoord=20

		var w = imgElm.width;
		var h = imgElm.height;

		if (typeof e != "undefined"){
			xcoord+=e.pageX
			ycoord+=e.pageY
		}else if (typeof window.event !="undefined"){
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-40;

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		divElm.style.left=xcoord+"px"
		divElm.style.top=ycoord+"px"


	}

}

function showIMG(bildName) {
    if(bildName != 'noPic.jpg'
       && bildName != 'noPicSmall.jpg'
       && bildName != '') {
           if(navigator.userAgent.toLowerCase().indexOf('opera') == -1 && navigator.userAgent.toLowerCase().indexOf('safari') == -1) {
               gettrailobj();
               divElm.innerHTML = '';
        	   imgElm = document.createElement('img');

        	   if(bildName.indexOf('http://') == -1){
        	       imgElm.src = 'image/prod/g_'+bildName;
        	   } else {
                   imgElm.src = bildName;
        	   }
        	   divElm.appendChild(imgElm);
        	   document.onmousemove=followmouse;
           }
    } else {
        show = 0;
    }
    //alert(bildName);
}

