/*
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 = 60;	// maximum image size.

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
}

function showtrail_cert(){
	document.onmousemove=followmouse;
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;width: 350px;" id="trailInnerDiv"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td><p align="left"><img src="http://www.metroinfo.com/images/certified_pending.gif" alt="Certified" width="25" height="27" align="absmiddle" />  Uncertified <p align="left">As a great local business we&rsquo;ve been asked to partner with the MetroInfo portal in your area. However, we&rsquo;re still in the process of being certified as featured MetroInfo vendor. If in fact we pass the MetroInfo entrance process we&rsquo;ll have had many aspects of our business investigated including;<ul><li>Our History</li><li>Background</li><li>Business References</li><li>Contact and Location Information. </li></ul><p align="left">MetroInfo will even continue to check in on us with unplanned spot audits. Within the coming days, we may become a MetroInfo certified partner. We look forward to doing business with you.       <p align="left"><img src="http://www.metroinfo.com/images/certified_pending.gif" alt="Certified" width="25" height="27" align="absmiddle" />Certified <p align="left">As a MetroInfo certified partner we&rsquo;ve passed the stringent testing that all MetroInfo partners must undergo. We&rsquo;ve had our business history, background, references, and administrative information all investigated, and it has passed the test. All that&rsquo;s left for us to do is provide you with a great product or service. As a certified vendor we always adhere to the MetroInfo business ethics;<ol><li>We&rsquo;ll always be honest, courteous, and forthright with our customers. </li><li>We provide a great product or service, guaranteed. </li><li>We comply with all state and federal laws governing businesses in our industry. </li><li>If we need to be licensed to operate our business, you can be sure we are. </li><li>If you ever have a problem, let us know. We&rsquo;ll resolve it to the best of our ability. </li></ol><p align="left">We look forward to doing business with, and be sure to let us know you found us at MetroInfo.</td></tr></table></div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}
function showtrail_desc(description){
	document.onmousemove=followmouse;
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;width: 200px;" id="trailInnerDiv"><table width="100%" height="100%"><tr><td align="center"><b>Description</b><br>&nbsp;<br>'+unescape(description)+'</td></tr></table></div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}
function showtrail(address, business, address_br, phone){
	document.onmousemove=followmouse;

	newHTML = '<div id="map" style="width: 375px; height: 300px"></div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
	var map = null;
    var geocoder = null;

    if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("map"));
      geocoder = new GClientGeocoder();
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              document.getElementById("map").innerHTML="Address not found";
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml('<font face="Verdana" size="3"><b>'+business+'</b><br><font size="2">'+address_br+'<br>'+phone+'</font></font>');
            }
          }
        );
      }
    }
}

function showtrailBatch(imagename,title,filetype){
	document.onmousemove=followmouseBatch;

	cameraHTML = '';

	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;" id="trailInnerDiv">';
	newHTML = newHTML + '<h2>' + title + '</h2>';

	newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;">';
	if(filetype == 8) { // Video
		newHTML = newHTML +	'<object width="380" height="285" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">';
		newHTML = newHTML + '<param name="movie" value="video_loupe.swf">';
		newHTML = newHTML + '<param name="quality" value="best">';
		newHTML = newHTML + '<param name="loop" value="true">';

		newHTML = newHTML + '<param name="FlashVars" value="videoLocation=' + imagename + '">';
		newHTML = newHTML + '<EMBED SRC="video_loupe.swf" LOOP="true" QUALITY="best" FlashVars="videoLocation=' + imagename + '" WIDTH="380" HEIGHT="285">';
		newHTML = newHTML + '</object></div>';
	} else {
		newHTML = newHTML + '<img src="' + imagename + '" border="0"></div>';
	}

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
	gettrailobj().position="absolute";
	currentimageheight = $('trailInnerDiv').offsetHeight;
	
}

function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	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(window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		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 < 380){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 400; // 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;
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

function followmouseBatch(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)

	var trailInnerDiv = $('trailInnerDiv');
	var currentimageheight = trailInnerDiv.offsetHeight;
	var currentimagewidth = trailInnerDiv.offsetWidth;

	scrollPos = Position.realOffset(truebody());
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if ((e.pageY - scrollPos[1]) + currentimageheight > docheight){
			ycoord = -ycoord + (e.pageY - currentimageheight);
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (event.clientX + currentimagewidth > docwidth){
			xcoord = -xcoord + ((event.clientX + scrollPos[0]) - currentimagewidth); // Move to the left side of the cursor
		} else {
			xcoord += (event.clientX + scrollPos[0]);
		}
		if (event.clientY + currentimageheight > docheight){
			ycoord = -ycoord + ((event.clientY + scrollPos[1]) - currentimageheight);
		} else {
			ycoord += (event.clientY + scrollPos[1]);
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }

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

}