// Constant Initialization
var AMAZON_imageserver = "images.amazon.com";
var DDRIVE_offsetxpoint = -60; //Customize x offset of tooltip
var DDRIVE_offsetypoint = 20; //Customize y offset of tooltip
var DDRIVE_ie = document.all;
var DDRIVE_ns6 = document.getElementById && !document.all;

// Variable Initialization
var DDRIVE_enabletip = false;
var DDRIVE_tipobj = null;

// Add the tooltip pane with requisite styling
document.write('<div id="DDRIVE_dhtmltooltip"></div>\n');
document.write('<style type="text/css">\n');
document.write('#DDRIVE_dhtmltooltip{\n');
document.write('position: absolute;\n');
document.write('width: 150px;\n');
document.write('border: 3px double black;\n');
document.write('padding: 2px;\n');
document.write('background-color: white;\n');
document.write('visibility: hidden;\n');
document.write('z-index: 9999;\n');
document.write('filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);\n');
document.write('}</style>\n');

// Set the tooltip pane object
if (ToolTipCompatibleBrowser()){
	DDRIVE_tipobj = document.all ? document.all["DDRIVE_dhtmltooltip"] : document.getElementById? document.getElementById("DDRIVE_dhtmltooltip") : "";
}
	
// Gets the "body" element
function DDRIVE_ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
}


// Shows a tooltip
function DDRIVE_tooltip(thetext, thecolor, thewidth){
	if (ToolTipCompatibleBrowser()){
		if (typeof thewidth!="undefined"){
			DDRIVE_tipobj.style.width = thewidth + "px";
		}
		else{
			DDRIVE_tipobj.style.width = "";
		}
		if (typeof thecolor!="undefined" && thecolor!=""){
			DDRIVE_tipobj.style.backgroundColor=thecolor;
		}
		DDRIVE_tipobj.innerHTML = thetext;
		DDRIVE_enabletip = true;
		return false;
	}
}


// Positions the tooltip pane
function DDRIVE_positiontip(e){
	if (ToolTipCompatibleBrowser() && DDRIVE_enabletip){
		var curX = (DDRIVE_ns6) ? e.pageX : event.x + DDRIVE_ietruebody().scrollLeft;
		var curY = (DDRIVE_ns6) ? e.pageY : event.y + DDRIVE_ietruebody().scrollTop;

		//Find out how close the mouse is to the corner of the window
		var rightedge = DDRIVE_ie && !window.opera ? DDRIVE_ietruebody().clientWidth - event.clientX-DDRIVE_offsetxpoint : window.innerWidth - e.clientX - DDRIVE_offsetxpoint - 20;
		var bottomedge = DDRIVE_ie && !window.opera ? DDRIVE_ietruebody().clientHeight - event.clientY-DDRIVE_offsetypoint : window.innerHeight - e.clientY - DDRIVE_offsetypoint - 20;

		var leftedge = (DDRIVE_offsetxpoint < 0) ? DDRIVE_offsetxpoint * (-1) : -1000;

		//if the horizontal distance isn't enough to accomodate the width of the context menu

		if (rightedge < DDRIVE_tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			DDRIVE_tipobj.style.left = DDRIVE_ie ? DDRIVE_ietruebody().scrollLeft + event.clientX - DDRIVE_tipobj.offsetWidth + "px" : window.pageXOffset + e.clientX-DDRIVE_tipobj.offsetWidth + "px";
		}
		else if (curX < leftedge){
			DDRIVE_tipobj.style.left = "5px";
		}
		else{
			//position the horizontal position of the menu where the mouse is positioned
			DDRIVE_tipobj.style.left = curX + DDRIVE_offsetxpoint + "px";
		}

		//same concept with the vertical position
		if (bottomedge < DDRIVE_tipobj.offsetHeight){
			DDRIVE_tipobj.style.top = DDRIVE_ie ? DDRIVE_ietruebody().scrollTop + event.clientY - DDRIVE_tipobj.offsetHeight - DDRIVE_offsetypoint + "px" : window.pageYOffset + e.clientY - DDRIVE_tipobj.offsetHeight - DDRIVE_offsetypoint + "px";
		}
		else{
			DDRIVE_tipobj.style.top = curY + DDRIVE_offsetypoint + "px";
		}
		DDRIVE_tipobj.style.visibility = "visible";
	}
}


// Hides the tooltip pane
function DDRIVE_hidetip(e){
	if (ToolTipCompatibleBrowser()){
		DDRIVE_enabletip = false;
		DDRIVE_tipobj.style.visibility = "hidden";
		DDRIVE_tipobj.style.left = "-1000px";
		DDRIVE_tipobj.style.backgroundColor = '';
		DDRIVE_tipobj.style.width = '';
	}
}

// Checks to see if the current browser is "tooltip compatible"
function ToolTipCompatibleBrowser(){
	if(DDRIVE_ns6||DDRIVE_ie){
		return true;
	}
	else{
		return false;
	}
}

document.onmousemove = DDRIVE_positiontip;

// Shows a tooltip with an Amazon product image in it (
function Tooltip(image, width, height) {
	DDRIVE_tipobj.innerHTML = '<img src=\'' + image + '\'/>';
	DDRIVE_tipobj.style.width = width + "px";
	DDRIVE_tipobj.style.height = height + "px";
	DDRIVE_enabletip = true;
	return false;
}
