/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
Modified by Darren Benfer 3/5/2007 for use on this website
*/

// detect browser, we'll have to hide all select elements
// on IE 6 or lower because our div doesn't float over them
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

// not really used any more but kept in just in case we roll back
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentheight = 0;	
var currentwidth = 0;

if (document.getElementById || document.all){
	document.write('<div id="hoverframe">');
	document.write('</div>');
}

function writetostatus(input){
    window.status=input
    return true
}

function get_b_obj(){
if (document.getElementById)
return document.getElementById("hoverblock").style
else if (document.all)
return document.all.hoverblock.style
}

function get_b_obj_nostyle(){
if (document.getElementById)
return document.getElementById("hoverblock")
else if (document.all)
return document.all.hoverblock
}

function gethoverobj(){
if (document.getElementById)
return document.getElementById("hoverframe").style
else if (document.all)
return document.all.hoverimagid.style
}

function gethoverobjnostyle(){
if (document.getElementById)
return document.getElementById("hoverframe")
else if (document.all)
return document.all.hoverimagid
}

function resize(h,w){
	gethoverobj().height = h+"px";
	gethoverobj().width = w+"px";
	gethoverobj().display="inline";
	return true;
}

function hideElements() {
	// looping through form ppForm and hiding the dropdowns
	var elements = document.forms["ppForm"].elements;
	for (e = 0; e < elements.length; e++) {
		if (elements[e].type == "select-one") {
			elements[e].style.display = 'none';
		}
	}
	var elements = document.forms["cartForm"].elements;
	for (e = 0; e < elements.length; e++) {
		if (elements[e].type == "select-one") {
			elements[e].style.display = 'none';
		}
	}
}

function showElements() {
	// looping through form cartForm and hiding the dropdowns
	var elements = document.forms["ppForm"].elements;
	for (e = 0; e < elements.length; e++) {
		if (elements[e].type == "select-one") {
			elements[e].style.display = 'block';
		}
	}
	var elements = document.forms["cartForm"].elements;
	for (e = 0; e < elements.length; e++) {
		if (elements[e].type == "select-one") {
			elements[e].style.display = 'block';
		}
	}
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function chkLoad(myImage) {
	if(myImage.complete) {
		clearTimeout(isLoaded);
	}
	if(!myImage.complete) {
		var isLoaded = setTimeout('chkLoad(myImage)',100);
	}
}

function showhover(thumbpic,thumbw,thumbh,bigpic,bigw,bigh,title,desc){
	if (thumbpic == bigpic) {
		imagename = thumbpic;
		h = thumbh;
		w = thumbw;
	} else {
		imagename = bigpic;
		h = bigh;
		w = bigw;
	}		
	currentheight = h;
	t=w*.20;
	currentwidth = w+t;
	if (currentwidth<340) {
		currentwidth = 340;
	}
	if (currentwidth>400) {
		currentwidth = 400;
		if (w>400)
			w=400;
	}
	currentwidth = currentwidth + desc.length;
	newHTML = '<div style="width:'+currentwidth+'px; padding:15px; background-color:#fff; border:1px solid #888; text-align:center; font:11px verdana,arial,sans-serif;">';
	newHTML = newHTML + '<h4>' + title + '</h4>';
	newHTML = newHTML + '<img src="' + imagename + '" height="' + h + '" width="' + w + '" border="0" style="margin-bottom:8px;" /><br />';
	if (desc.length > 0)
		newHTML = newHTML + desc + '<br />';
	newHTML = newHTML + '</div>';
	gethoverobjnostyle().innerHTML = newHTML;
	gethoverobj().display="inline";
	document.onmousemove=followmouse;
}


function hidehover(){
	gethoverobj().innerHTML = " ";
	gethoverobj().display="none";
	document.onmousemove="";
	gethoverobj().left="-5000px";
}

function followmouse(e){

	var xcoord=15
	var ycoord=15

	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 (typeof e != "undefined"){
		//if (docwidth - e.pageX < currentwidth){
		//	xcoord = e.pageX - xcoord - currentwidth; // Move to the left side of the cursor
		//} else {
			xcoord += e.pageX;
		//}
		if (docheight - e.pageY < (currentheight + 120)){
			ycoord += e.pageY - Math.max(0,(120 + currentheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

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

}

