/* Simple Trail Script */

var offsetfrommouse = [ 0 , 15 ]; // Offsets from cursor position in pixels. Enter 0,0 for no offset.

var defaulttrailwidth = 120;
var defaulttrailheight = 24;

if( document.getElementById || document.all ) {
	document.write( '<div id="trail">' );
	document.write( '</div>' );
}

function gettrailobj() {
	if( document.getElementById ) {
		return document.getElementById( "trail" ).style;
	}
	else if ( document.all ) {
		return document.all.trail.style;
	}
}

function gettrailobjnostyle() {
	if( document.getElementById ) {
		return document.getElementById( "trail" );
	} else if ( document.all ) {
		return document.all.trailimagid;
	}
}

function truebody() {
	return ( !window.opera && document.compatMode && document.compatMode != "BackCompat" )? document.documentElement : document.body;
}

function hidetrail() {
	gettrailobj().innerHTML = "";
	gettrailobj().display = "none";
	document.onmousemove = "";
	gettrailobj().left = "-500px";
}

function showtrail( text ) {	
	document.onmousemove=followmouse;
	// Trail content:
	newHTML  = '<img src="images/ico-trail-arrow.gif" class="arrow" alt="" /><div class="inner">'+ text +'</div>';
	// -----
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display = "inline";
}

function followmouse(e) {
	var xcoord = offsetfrommouse[0];
	var ycoord = offsetfrommouse[1];
	var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset + window.innerWidth - 15;
	var docheight = document.all? Math.min( truebody().scrollHeight, truebody().clientHeight ) : Math.min( window.innerHeight );
	if(typeof e != "undefined") {
		if(docwidth - e.pageX < defaulttrailwidth + 2 * offsetfrommouse[0]) {
			xcoord = e.pageX - xcoord - defaulttrailwidth; // Move to the left side of the cursor.
		} else {
			xcoord += e.pageX;
		}
		if(docheight - e.pageY < defaulttrailheight + 2 * offsetfrommouse[1]) {
			ycoord += e.pageY - Math.max( 0, ( 2 * offsetfrommouse[1] + defaulttrailheight + e.pageY - docheight - truebody().scrollTop ) );
		} else {
			ycoord += e.pageY;
		}
	} else if( typeof window.event != "undefined" ) {
		if(docwidth - event.clientX < defaulttrailwidth + 2 * offsetfrommouse[0] ) {
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaulttrailwidth; // Move to the left side of the cursor.
		} else {
			xcoord += truebody().scrollLeft+event.clientX;
		}
		if( docheight - event.clientY < ( defaulttrailheight + 2 * offsetfrommouse[1] ) ) {
			ycoord += event.clientY + truebody().scrollTop - Math.max( 0, ( 2 * offsetfrommouse[1] + defaulttrailheight + event.clientY - docheight ) );
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left = xcoord + "px";
	gettrailobj().top = ycoord + "px";
}

