/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

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 = 100;	// maximum image size.
var currentImageHeight = 0;
var currentImageWidth = 0;
var srcImageRight = 0;

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 (document.getElementById || document.all)
{
	document.write('<div style="position:absolute;visibility:visible;left:0px;top:0px;width:1px;height:1px" id="trailimageid">');
	document.write('</div>');
}

function gettrailobj()
{
	if (document.getElementById)
	{
		currentimageheight = 100;
		var trailImg = document.getElementById("trailimageid");
		return document.getElementById("trailimageid").style;
	}
	else if (document.all)
	{
		return document.all.trailimageid.style;
	}
}


function gettrailobjnostyle()
{
	if (document.getElementById)
	{
		return document.getElementById("trailimageid")
	}
	else if (document.all)
	{
		return document.all.trailimageid;
	}
}


function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

 window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
 var menuActive = 0
 var menuOn = 0
 var onLayer
 var timeOn = null // LAYER SWITCHING CODE

function getImagePageLeft(img) {
  var x, obj;
  if (NS4) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
      return img.x;
  }
  if (IE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}


function getImagePageTop(img) {
  var y, obj;
  if (NS4) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (IE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}


function showtrail(imagename, srcImage)
{
	docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
	docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	newHTML = '';
	newHTML = newHTML + '<table border="1" cellpadding="2" cellspacing="0" class="product-image-border"><tr><td>';
	newHTML = newHTML + '<div align="center" style="padding: 1px 1px 1px 1px;"><img src="' + imagename + '" border="0"></div>';
	newHTML = newHTML + '</td></tr></table>';

	var img = new Image();
	img.src = imagename;
	
	currentImageWidth = img.width;
	currentImageHeight = img.height;
	//Grab the rightmost edge of the image that triggered this event (srcImage).
	srcImageRight = getImagePageLeft(srcImage) + srcImage.width;
	
	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
	
	document.onmousemove=followmouse;
}

function showAjaxtrail(imagename, srcImage)
{
	docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
	docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	newHTML = '';
	newHTML = newHTML + '<table border="1" cellpadding="2" cellspacing="0" class="product-image-border"><tr><td>';
	newHTML = newHTML + '<div align="center" style="padding: 1px 1px 1px 1px; background-color:#ffffff; height: 225px; width: 225px; vertical-align: middle;">Loading Image ... Please Wait!<br><br><br><img src="/images/navigation/loading.gif" border="0"></div>';
	newHTML = newHTML + '</td></tr></table>'; 
	
	//Grab the rightmost edge of the image that triggered this event (srcImage).
	srcImageRight = getImagePageLeft(srcImage) + srcImage.width;
			
	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
			
	document.onmousemove=followmouse;
			
	var xmlhttp = new XMLHttpRequest();	
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
			docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

			newHTML = '';
			newHTML = newHTML + '<table border="1" cellpadding="2" cellspacing="0" class="product-image-border"><tr><td>';
			newHTML = newHTML + '<div align="center" style="padding: 1px 1px 1px 1px;"><img src="' + imagename + '" border="0"></div>';
			newHTML = newHTML + '</td></tr></table>';

			var img = new Image();
			img.src = imagename;			
			currentImageWidth = img.width;
			currentImageHeight = img.height;
			
			//Grab the rightmost edge of the image that triggered this event (srcImage).
			srcImageRight = getImagePageLeft(srcImage) + srcImage.width;
			
			gettrailobjnostyle().innerHTML = newHTML;

			gettrailobj().visibility="visible";
		}
	}
	
	xmlhttp.open('Get', imagename, true);
	xmlhttp.send(null);
}

function hidetrail()
{
	gettrailobj().visibility = "hidden";
	document.onmousemove = "";
	gettrailobj().left = "-1500px";
}


function followmouse(e)
{
	var xcoord = offsetfrommouse[0]
	var ycoord = offsetfrommouse[1]

	docwidth=document.all? truebody().scrollLeft+truebody().clientWidth - 15 : pageXOffset+window.innerWidth - 15
	docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight - 15) : Math.min(window.innerHeight)

	if (typeof e != "undefined")
	{
		if ((docwidth - e.pageX) <= srcImageRight) // within 300 pixels of the right edge.
		{
			xcoord = e.pageX - (2 * xcoord) - currentImageWidth; // Move to the left side of the cursor
		}
		else 
		{
			xcoord += e.pageX;
		}
		
		if (docheight - e.pageY <= (currentImageHeight + 40))
		{
			ycoord += e.pageY - Math.max(0,(40 + currentImageHeight + e.pageY - docheight - truebody().scrollTop));
		}
		else
		{
			ycoord += e.pageY;
		}
	}
	else if (typeof window.event != "undefined")
	{
		if ((docwidth - event.clientX) < srcImageRight)
		{
			// Move to the left side of the cursor
			xcoord = event.clientX + truebody().scrollLeft - (2 * xcoord) - currentImageWidth; 
		}
		else
		{
			xcoord += truebody().scrollLeft + event.clientX;
		}

		if (docheight - event.clientY < (currentImageHeight + 20))
		{
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(20 + currentImageHeight + event.clientY - docheight));
		}
		else
		{
			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 (ycoord < 0)
	{
		ycoord = ycoord * -1;
	}
	
	gettrailobj().left = xcoord + "px"
	gettrailobj().top = ycoord + "px"
}
