/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
****
Modified by Smartways Technology Ltd
*/

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 200;

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var iTrailTimeout = 20000;
var iTrailTimeoutRef = -1;
var iTrailStartTimeout = 500;
var iTrailStartRef = -1;
var sHTML = "";

function showtrail(newHTML, bolDoShow){
	
	/*
	if(bolDoShow != true)
	{
		sHTML = newHTML;
		iTrailStartRef = setTimeout("showtrail('', true)", iTrailStartTimeout);
		return;
	}
	if(iTrailStartRef != -1)
	{
		clearTimeout(iTrailStartRef);
		iTrailStartRef = -1;
	}
	newHTML = sHTML;
	*/
	document.onmousemove=followmouse;
	document.onclick = hidetrail;
	
	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
	if(iTrailTimeoutRef != -1)
	{
		clearTimeout(iTrailTimeoutRef);
		iTrailTimeoutRef = -1;
	}
	iTrailTimeoutRef = setTimeout("hidetrail()", iTrailTimeout);
}


function hidetrail(){
	if(iTrailStartRef != -1)
	{
		clearTimeout(iTrailStartRef);
		iTrailStartRef = -1;
	}
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"
}

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(document.body.offsetHeight, window.innerHeight)
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		xcoord -= 250;
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}
function openWindow(sURL, sWindowName, sFeatures)
{
	window.open(sURL,sWindowName,sFeatures)
	return false;
}
function attachHelpHoverHandlers()
{
	if(!document.getElementById){ return false; }
	if(!document.getElementsByTagName){ return false; }
	var aAnchors = document.getElementsByTagName("A");
	var bSupportsAJAX = supportsAJAX();
	for(var i=0; i<aAnchors.length; i++)
	{
		var oAnchor = aAnchors[i];
		if(oAnchor.className.toLowerCase() == "trail")
		{
			oAnchor.onclick = function()
			{
				var sURL = this.href;
				var sQS = "";
				var sWidth = "320";
				var sHeight = "190";
				if(sURL.indexOf("?") > -1) { sQS = sURL.substring(sURL.indexOf("?")+1); }
				var aArgs = sQS.split("&");
				for(var i=0; i<aArgs.length; i++)
				{
					var aData = aArgs[i].split("=");
					switch(aData[0].toUpperCase())
					{
						case "W":
							sWidth  = aData[1];
							break;
						case "H":
							sHeight = aData[1];
							break;
						default:
							break;
					}
				}
				return openWindow(sURL, "help", "width=" + sWidth + ",height=" + sHeight);
			}
			// If they support AJAX, pull in data on demand.
			if(bSupportsAJAX)
			{
				oAnchor.onmouseover = function()
				{
					var sURL = this.href;
					if(sURL.indexOf("?") > -1)
					{
						sURL = sURL.substring(0, sURL.indexOf("?"));
					}
					getHelpData(sURL);
				}
				oAnchor.onclick = function()
				{
					return false;
				}
				oAnchor.onmouseout = function()
				{
					hidetrail();
				}
				
			}
			// End of attaching event handlers
		}
	}
}

/* AJAX stuff */
document.write('<script type="text/javascript" src="/_script/ajax/common.js"></script>');

attachHelpHoverHandlers();

var oHelp = new Object();
var sHelpURL = "";

function getHelpData(sURL)
{
	if(oHelp[sURL])
	{
		showtrail(oHelp[sURL]);
		return true;
	}
	try
	{
		oXmlHttp = getHTTPObject();
		if(oXmlHttp == null){ return true; }
		sHelpURL = sURL;
		oXmlHttp.open("GET", sURL, true);
		oXmlHttp.onreadystatechange = handleHelpResponse;
		oXmlHttp.send(null);
		return false;
	}
	catch(e)
	{
		return true;
	}
}

function handleHelpResponse()
{
	if(oXmlHttp.readyState != 4){ return false; }
	var sReturn = oXmlHttp.responseText;
	if(sReturn == ""){ return; }
	oHelp[sHelpURL] = sReturn;
	sHelpURL = "";
	showtrail(sReturn);
}