<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

/*
Functions for displaying modal popup boxes.

To create a new popup box you need the following:

1) A hidden <DIV> tag printed somewhere on the page that contains the popup box content.
   There may be a PHP class that helps you create this content.

<div id="myPopupBox" class="popupBox" style="width: 200px;">
	[..help button..][..close button..]
	[..popup box content..]
</div>

2) If the popup is modal then you need to define a javascript function that
   resets the popup box content. This function should take the popup box <DIV>
   element object as its first argument and a click event as its second
   arguement. This script should be in the <HEAD>.

<script type="text/javascript">
	function myPopupBoxReset(popupElement, clickEvent){
		# optional reset statements
	}
</script>

3) A button of some sort on the page that you'll use to show the popup box.
   This button will need to call the showPopupBox() javascript function and
   pass it a click event. The simplest way to achieve this is by redefining
   the button's onclick event. In fact, you might even want provide some fallback
   method for non-DOM-compliant browsers, or if the user has javascript turned off.

<script type="text/javascript">
// DOM-compliant
if (document.getElementById || document.all){
	document.write('<img id="myPopupBoxButton12345" src="myPopupBoxButton.gif"/ alt="My Popup" title="My Popup">');
	document.getElementById('myPopupBoxButton12345').onclick = function (e){
		showPopupBox(document.getElementById('myPopupBox), e, myPopupBoxReset, true);
	}
}
// non-DOM-compliant
else {
	document.write('<a href="javascript:void(0);" onclick="javascript:window.open(\'myPopupWindow.php?id=12345\',\'Popup\',\'scrollbars=yes,width=400,height=550\')">');
	document.write('<img src="myPopupBoxButton.gif" alt="My Popup" title="My Popup">');
	document.write('</a>');
}
</script>
<noscript>
	<a href="myPopupWindow.php?id=1234" target="_blank"><img src="myPopupBoxButton.gif"/ alt="My Popup" title="My Popup"></a>
</noscript

*/

var popupBoxOffsetFromMouse=[-50,-5]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset



// For modal popups, a click outside of the popup box <DIV> will cause the popup to close.
// We do this be putting a big transparent <DIV> that masks the entire page behind the popup <DIV>.
// FIXME: this <DIV> should continue to cover the entire page even if the window scrolls
if (document.getElementById || document.all){

	document.write('<div id="popupBoxModalBackground" style="position: absolute; visibility: hidden; left: 0px; top: 0px; width: ' + getDocWidth() + 'px; height: ' + getDocHeight() + 'px; z-index: 500"></div>');

}


////////////////////////////////////////////////////////////////////////////////
/// @name showPopupBox
/// @desc show a given popup box
///
/// @param popupElement element object - the popup box <DIV>
/// @param e event object - a click event that we will use to position the popup box near the cursor
/// @param popupResetCallback function - should reset the popup box to its initial state
/// @param isModal boolean - if true, then clicking anywhere outside of the popupbox will cause it to close and reset
////////////////////////////////////////////////////////////////////////////////
function showPopupBox(popupElement, e, popupResetCallback, isModal){

	if ( typeof popupElement == 'string' ){
		popupElement = document.getElementById(popupElement);
	}
	
	movePopupBox(popupElement, e);
	popupElement.style.visibility="visible";

	if ( isModal && popupResetCallback ){
		document.getElementById('popupBoxModalBackground').onclick = function (modalE){
			popupResetCallback(popupElement, modalE);
			popupElement.style.visibility = 'hidden';
			document.getElementById('popupBoxModalBackground').style.visibility = 'hidden';
		};
		document.getElementById('popupBoxModalBackground').style.visibility = 'visible';
	}

}

////////////////////////////////////////////////////////////////////////////////
/// @name hidePopupBox
/// @desc hide a given popup box
///
/// @param popupElement - element object - the popup box <DIV>
////////////////////////////////////////////////////////////////////////////////
function hidePopupBox(popupElement){
	if ( typeof popupElement == 'string' ){
		popupElement = document.getElementById(popupElement);
	}
	popupElement.style.visibility="hidden";
	document.getElementById('popupBoxModalBackground').style.visibility = 'hidden';
}

////////////////////////////////////////////////////////////////////////////////
/// @name movePopupBox
/// @desc move a given popup box to the location defined by a click event
///
/// @TODO keep the popup box from extending beyond the right or bottom of the window
///
/// @param popupElement - element object - the popup box <DIV>
/// @param e event object - a click event that we will use to position the popup box near the cursor
////////////////////////////////////////////////////////////////////////////////
function movePopupBox(popupElement, e){

	//debugOnClickEventHandler(e);

	var xcoord = popupBoxOffsetFromMouse[0];
	var ycoord = popupBoxOffsetFromMouse[1];

	var docwidth = getDocWidth();
	var docheight = getDocHeight();

	if (typeof e != "undefined"){

//alert(e.pageY + ':' + popupElement.offsetHeight + ':' + docheight + ':' + getTrueBody().scrollTop);
//alert(ycoord);
/*
doc     ----------------------------
page    ------------------------
scroll  -------
pop            --------------
*/
		// ie doesn't like pageX
		var x = 0;
		var y = 0;	
		
		if(e.pageX || e.pageY) {
			x = e.pageX;
			y = e.pageY;
		} else if (e.clientX || e.clientY) {
			x = e.clientX;
			y = e.clientY;
			//x = e.clientX + document.body.scrollLeft;
			//y = e.clientY + document.body.scrollTop;
		}
		
				
		if (docwidth - x < popupElement.offsetWidth + xcoord){
			xcoord = x - xcoord - popupElement.offsetWidth; // Move to the left side of the cursor
		} else {
			xcoord += x;
		} 
					
		if (docheight + getTrueBody().scrollTop - y < popupElement.offsetHeight + ycoord){
			ycoord = y - ycoord - popupElement.offsetHeight;
		} else {
			ycoord += y;
		}

	} else if (typeof window.event != "undefined"){
		//if (docwidth + getTrueBody().scrollLeft - e.pageX < popupElement.offsetWidth + xcoord){
		if (docwidth - event.clientX < popupElement.offsetWidth + xcoord){
			xcoord = event.clientX - xcoord - popupElement.offsetWidth + getTrueBody().scrollLeft; // Move to the left side of the cursor
		} else {
			xcoord += event.clientX + getTrueBody().scrollLeft;
		}
		if (docheight - event.clientY < popupElement.offsetHeight + ycoord){
			ycoord = event.clientY - ycoord - popupElement.offsetHeight + getTrueBody().scrollTop;
		} else {
			ycoord += event.clientY + getTrueBody().scrollTop;
		}

	}	else {

		return;

	}

	//var docwidth=document.all? getTrueBody().scrollLeft+getTrueBody().clientWidth : pageXOffset+window.innerWidth-15;
	//var docheight=document.all? Math.max(getTrueBody().scrollHeight, getTrueBody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	
	popupElement.style.left = xcoord+"px"
	popupElement.style.top = ycoord+"px"

}


////////////////////////////////////////////////////////////////////////////////
/// @name whichQuadrant
/// @expirmental
/// @desc given a width and a height, figure our which quadrant a point falls in
///
/// @param pageX int - the width of the theoretical space
/// @param pageY int - the height of the theoretical space
/// @param pointX int - the horizontal distance of the point from the upper left corner
/// @param pointY int - the vertical distance of the point from the upper left corner
/// @return int - one of the QUADRANT_* constants
////////////////////////////////////////////////////////////////////////////////
var SIDE_TOP = 1;
var SIDE_BOTTOM = 2;
var SIDE_LEFT = 4;
var SIDE_RIGHT = 8;
var QUADRANT_TOP_LEFT = SIDE_TOP | SIDE_LEFT;
var QUADRANT_TOP_RIGHT = SIDE_TOP | SIDE_RIGHT;
var QUADRANT_BOTTOM_LEFT = SIDE_BOTTOM | SIDE_LEFT;
var QUADRANT_BOTTOM_RIGHT = SIDE_BOTTOM | SIDE_RIGHT;
function whichQuadrant(pageX, pageY, pointX, pointY){

	var quadrant = 0;
	var halfX = pageX/2;
	var halfY = pageY/2;

	if ( pointX < halfX ){
		quadrant |= SIDE_LEFT;
	} else {
		quadrant |= SIDE_RIGHT;
	}

	if ( pointY < halfY ){
		quadrant |= SIDE_TOP;
	} else {
		quadrant |= SIDE_BOTTOM;
	}

	return quadrant;

}

function getDocWidth(){
	return (document.all? getTrueBody().scrollLeft+getTrueBody().clientWidth : pageXOffset+window.innerWidth-15);
}

function getDocHeight(){
	return (document.all? Math.min(getTrueBody().scrollHeight, getTrueBody().clientHeight) : Math.min(window.innerHeight));
}

function getTrueBody(){
	return ( (!window.opera && document.compatMode && document.compatMode!="BackCompat") || window.opera)? document.documentElement : document.body
}

function debugOnClickEventHandler(e){

/*
type - this property indicates the type of event. 
target - this property indicates the object to which the event was originally sent.
*layerX - the cursor location when the click event occurs.
*layerY - the cursor location when the click event occurs.
*pageX - the cursor location when the click event occurs.
*pageY - the cursor location when the click event occurs.
*screenX - the cursor location when the click event occurs.
*screenY - the cursor location when the click event occurs.
which - 1 represents a left mouse click and 3 a right click.
modifiers - lists the modifier keys (shift, alt, ctrl, etc.) held down when the click event occurs.
*/
	s = typeof e + ":\n";
	s += 'type = ' + e.type + "\n";
	s += 'target = ' + e.target + "\n";
	s += 'layerX = ' + e.layerX + "\n";
	s += 'layerY = ' + e.layerY + "\n";
	s += 'pageX = ' + e.pageX + "\n";
	s += 'pageY = ' + e.pageY + "\n";
	s += 'screenX = ' + e.screenX + "\n";
	s += 'screenY = ' + e.screenY + "\n";
	s += 'which = ' + e.which + "\n";
	s += 'modifiers = ' + e.modifiers + "\n";

	alert(s);
}




//file serarchhover
var offsetfrommouse=[5,5]; //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 = 500;	// 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(imagename,title,description,ratingaverage,ratingnumber,showthumb,height,filetype,para){

	if (height > 0){
		currentimageheight = height;
	}

	document.onmousemove=followmouse;

	cameraHTML = '';

	if ( !ratingnumber ){
		ratingnumber = 0;
		ratingaverage = 0;
	}

	for(x = 1; x <= 5; x++){

		if (ratingaverage >= 1){
			cameraHTML = cameraHTML + '<img src="/images/camera_1.gif">';
		} else if (ratingaverage >= 0.5){
			cameraHTML = cameraHTML + '<img src="/images/camera_05.gif">';
		} else {
			cameraHTML = cameraHTML + '<img src="/images/camera_0.gif">';
		}
	
		ratingaverage = ratingaverage - 1;
	}

	//cameraHTML = cameraHTML;// + ' (' + ratingnumber + ' Review';
	//if ( ratingnumber > 1 ) cameraHTML += 's';
	//cameraHTML = cameraHTML + ')';

	newHTML = '<div style="padding: 5px; background-color: #e6f7ff; border: 1px solid #0080c0; ">';
	newHTML = newHTML + title + '<br/>';
	//newHTML = newHTML + 'Rating: ' + cameraHTML + '<br/>';
	//newHTML = newHTML + description + '<br/>';

	if (showthumb > 0){
		newHTML = newHTML + '<div align="center" style="padding: 2px 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="high">';
			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" '+ para +'></div>';
		}
	}

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}


function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove="100px"
	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,(60 + 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,(60 + 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; }
		//ycoord=ycoord-100;
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}



