/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/
var mousex = 0;
var mousey = 0;
var imagewidth = 0;
var imageheight = 0;

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function followmouse(e)
{
	document.getElementById("trailimageid").style.visibility="visible";
	
	var xcoord=35
	var ycoord=35
	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 myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	}
	
	// siirretään x- ja y-koordinaatista scrollin verran että ollaan oikealla ruudulla
	var scrolldata = getScrollXY();
	myHeight = (myHeight + scrolldata[1]);
	myWidth = (myWidth + scrolldata[0]);
	// if the screen width is not enough
	var dxcoord = 0;
	var dycoord = 0;
	dxcoord = myWidth;
	dycoord = myHeight;
	
	
	
	// max korkeus ja leveys
	dxcoord-=(imagewidth+xcoord+25);
	dycoord-=(imageheight+ycoord+25);
	
	if(dxcoord < 0)
	{
		xcoord = xcoord + dxcoord;
		
		if(dycoord < -15) // jos on liikutettu sekä leveys että korkeus suunnasta niin siirretään kuva kursorin toiselle puolelle
		{
			xcoord = xcoord - (imagewidth + 75) - dxcoord;	
		}
		
	}	
	if(dycoord < 0)
		ycoord = ycoord + dycoord;
	
						
	document.getElementById("trailimageid").style.left=xcoord+"px"
	document.getElementById("trailimageid").style.top=ycoord+"px"
	
}



function hidetrail()
{
	document.getElementById("trailimageid").style.visibility="hidden"
	document.onmousemove="";
}

function trailimage(imgfile, imgwidth, imgheight, targetid)
{
	 
	document.getElementById("trailimageidimg").src = "http://www.mallorcatour.net/data/userimages/" + imgfile;
	document.getElementById("trailimageidimg").height = imgheight;
	document.getElementById("trailimageidimg").width = imgwidth;
	
	var xc = mousex + 25;
	var yc = mousey - 50;
	document.getElementById("trailimageid").style.left = xc + 'px';
	document.getElementById("trailimageid").style.top = yc + 'px';
	
	  
	imagewidth = imgwidth;
	imageheight = imgheight;
	
	document.onmousemove=followmouse
	
	
}

