//********* Hover functions *********
/*
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,-25]; //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 = 60;	// maximum image size.


if (document.getElementById || document.all ){
	//alert('inside trailimageid insertion');
	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 getprogressbarobj(){
if (document.getElementById)
	return document.getElementById("progressbar").style
else if (document.all)
	return document.all.progressbar.style
}

function gettrailobj_content(){
if (document.getElementById)
	return document.getElementById("trailobj_content").style
else if (document.all)
	return document.all.trailobj_content.style
}

function gettrailobj_ifrm(){
if (document.getElementById)
	return document.getElementById("frm_block").style
else if (document.all)
	return document.all.frm_block.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
}

function switch_div(){
  getprogressbarobj().display       = "none";
  gettrailobj_content().display     = "block";
  return true;
}

function checkIt(string)
{
var detect = navigator.userAgent.toLowerCase();
    place = detect.indexOf(string) + 1;
    thestring = string;
    return place;
}

function showtrail(imagename, showthumb, imageNumber, brandText, img_width, img_height){    
    
      
    var isOp=window.opera?1:0;
    var display_it='none'; 
    var triger_progress=1;

    //Not an increment.  Just set to 0 if this function has been run  >0 times.
		counterAdjustment = 0;

		//alert('followmouse: ' + followmouse);
		document.onmousemove=followmouse;

    img_width = img_width + 4; 

		newHTML = '<div class="select-free" style="width: ' + img_width + 'px; padding: 0px; background-color: #FFF; border: 0px solid #888;">';

		//img_width   += 10;
		//img_height  += 10;
		
	
		if (showthumb > 0){
    		  
		  if (isOp) 
      { 
        display_it      = 'block';
        triger_progress = 0;
      }
      
      if (checkIt('safari')){
        display_it      = 'block';
        triger_progress = 0;        
      } 
      
      if(triger_progress){
        newHTML = newHTML + '<div id="progressbar" style="padding: 110px;display: block"><img src="images/progress_bar.gif" border="0" align="absmiddle"></div>';
      }
      	
			newHTML = newHTML + '<div align="center" style="padding: 0px 0px 0px 0px;display: ' + display_it + '" id="trailobj_content"><img src="' + imagename + '" onload="switch_div();" border="0"></div>';

      if (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0)
      {
      //Check for IE, if found add iframe to hide select dropdown menu //zdr
          newHTML += '<div id="frm_block" style="visibility: hidden;" ><iframe></iframe><div>';		
  		}
		
    }
	
		newHTML = newHTML + '</div>';
		//alert('newHTML: ' + newHTML);

		gettrailobjnostyle().innerHTML  = newHTML;   
		gettrailobj().visibility        = "visible";

      if (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0)
      {
      //Check for IE, if found add iframe to hide select dropdown menu //zdr
         gettrailobj_ifrm().visibility   = "visible";
  		}
		
	
}


function hidetrail(){
		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 < 480){
			xcoord = e.pageX - xcoord - 460; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 470)){
			ycoord += e.pageY - Math.max(0,(470 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 480){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 460; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 470)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(470 + 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)

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

//********* END Hover functions *********


