
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var trailimage = ["test.gif",300,300]
var offsetfrommouse=[15,0] //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 compwidth = 300
var compheight = 300
var isbigcomp = 0


// initialize global variables
var detectableWithVB = false;
var pluginFound = false;

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}

function loadQT()
{
   if (document.getElementById || document.all) {
	document.write('<div id="trailimageid"><img src="/images/spacer.gif">');
	document.write('</div>');
	gettrailobj().width=0;
	gettrailobj().height=0;
    	gettrailobj().left="+1000px"
    	gettrailobj().top="0px"
	gettrailobj().visibility="hidden"
    	gettrailobj().display=""
   }

}

loadQT()


function loadQTV()
{
   if (document.getElementById || document.all) {
	document.write('<div id="trailimageid"><img src="/images/spacer.gif">');
	document.write('</div>');
	pluginFound = detectPlugin('QuickTime');
    	// if not found, try to detect with VisualBasic
    	if(!pluginFound && detectableWithVB) {
		pluginFound = detectQuickTimeActiveXControl();
    	}	
	if (pluginFound) {
  		document.getElementById("trailimageid").innerHTML = '<div style="width:0px;height:0px;padding:4px;background-color:#fff;border:1px solid #888;"><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" width="0" height="0" align="middle"> <param name="src" value="/images/spacer.mov"> <param name="autoplay" value="true"> <param name="bgcolor" value="#ffffff"> <embed width="0" height="0" src="/images/spacer.mov" bgcolor="#ffffff" pluginspage="http://www.apple.com/quicktime/download/"></embed></object></div>'
	} 
	gettrailobj().width=0;
	gettrailobj().height=0;
    	gettrailobj().left="-1000px"
    	gettrailobj().top="0px"
	gettrailobj().visibility="visible"
    	gettrailobj().display=""
   }

}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(comppath,iwidth,iheight){

//if (document.form_nav.quickview.checked) {

var maxsize = 0
var f = 0.0
var max_comp = 300
var max_bigcomp = 500
if (comppath.indexOf("bigcomps") == -1) {
   maxsize = max_comp
   compwidth = 300
   compheight = 300
} else {
   //big comp
   maxsize = max_bigcomp
   compwidth = 500
   compheight = 500
   isbigcomp = 1
}

if (iwidth == null || iheight == null || iwidth == 0 || iheight == 0) {
  if (isbigcomp = 0) {
     iwidth = 120
     iheight = 120
  } else {
     iwidth = 300
     iheight = 500
  }
}
if (iwidth > iheight) {
  f = maxsize/iwidth
  compheight = iheight * f
} else {
  f = maxsize/iheight
  compwidth = iwidth * f
}
document.onmousemove=followmouse;

if (comppath.indexOf("mov") == -1)
   //image preview
   document.getElementById("trailimageid").innerHTML = '<div style="width:'+compwidth+'px;height:'+compheight+'px;padding:4px;background-color:#fff;border:1px solid #888;"><img src="'+comppath+'" border="0"></div>'
else {
  //video preview
  compheight = 200
  compwidth = 240
  document.getElementById("trailimageid").innerHTML = '<div style="width:'+compwidth+'px;height:'+compheight+'px;padding:4px;background-color:#fff;border:1px solid #888;"><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" width="'+compwidth+'" height="'+compheight+'" align="middle"> <param name="src" value="'+comppath+'"> <param name="autoplay" value="true"> <param name="controller" value="true"> <param name="bgcolor" value="#ffffff"> <embed width="'+compwidth+'" height="'+compheight+'" src="'+comppath+'" bgcolor="#ffffff" pluginspage="http://www.apple.com/quicktime/download/" controller="true"></embed></object></div>'
}

if (iwidth != 0 && iheight != 0){
//gettrailobj().width=iwidth;
//gettrailobj().height=iheight;}
gettrailobj().width=compwidth;
gettrailobj().height=compheight;}
gettrailobj().visibility="visible";

//}

}

function hidetrail(){
gettrailobj().visibility="hidden"
gettrailobj().left="-1000px"
document.onmousemove=""
}

function followmouse(e){
  var xcoord=offsetfrommouse[0]
  var ycoord=offsetfrommouse[1]
  if (isbigcomp == 1) {
     trailimage[1] = 500;
     trailimage[0] = 500;
  }
  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 (docwidth < xcoord+trailimage[1] || docheight < truebody.scrollTop+trailimage[1]) {
    //gettrailobj().visible="none"
  //}
  //} else {
  
    if (typeof e != "undefined") {
      // Mozilla
      xcoord+=e.pageX
      ycoord+=e.pageY
      if (xcoord+trailimage[1] >docwidth)
        xcoord = e.pageX - compwidth - offsetfrommouse[0]
      if (ycoord+trailimage[1]+15> docheight + truebody().scrollTop)
        ycoord = (truebody().scrollTop+docheight) - compheight - 40

	//always show big-comp even if it doesn't quite fit
	if (ycoord <= 0 && isbigcomp == 1)
	   ycoord = truebody().scrollTop
	if (xcoord <= 0 && isbigcomp == 1)
	   xcoord = e.pageX+trailimage[1]
    }
    else if (typeof window.event !="undefined") {
      // IE browser
      xcoord+=truebody().scrollLeft+event.clientX
      ycoord+=truebody().scrollTop+event.clientY

      if (xcoord+trailimage[1] > docwidth) 
        xcoord = (truebody().scrollLeft+event.clientX) - compwidth - offsetfrommouse[0]
      if (ycoord+trailimage[1] > docheight + truebody().scrollTop) 
        ycoord = (truebody().scrollTop+docheight) - compheight - 15

	//always show big-comp even if it doesn't quite fit
	if (ycoord <= 0 && isbigcomp == 1)
	   ycoord = (truebody().scrollTop)
	if (xcoord <= 0 && isbigcomp == 1)
	   xcoord = (truebody().scrollLeft+event.clientX)+offsetfrommouse[0]


      // this is to move the .top up if it is too far down from the mouse pointer
      if (ycoord > (truebody().scrollTop+event.clientY) + 10)
         ycoord  = ycoord  - (ycoord - (truebody().scrollTop+event.clientY))
    }


  //}

  if (xcoord < 0 || ycoord < 0) {
    gettrailobj().visible="none"
    gettrailobj().display=""
  } else {
    gettrailobj().display=""
    gettrailobj().left=xcoord+"px"
    gettrailobj().top=ycoord+"px"
  }  
}

function quickview_onClick()
{
   var dt = new Date();
   //default to 1 year
   dt.setTime(dt.getTime()+(365*24*3600*1000))
   if (document.form_nav.quickview.checked) {
	setCookie("quickview","yes",dt,"/","","");
   } else {
	setCookie("quickview","no",dt,"/","","");
   }
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

