var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;

if (nodyn) { event = "nope" }

var tipFollowMouse = true;	
var offX = 20;
var offY = 12; 

/////////////////////////
// IMAGES AND TOOLTIPS //
/////////////////////////
var messages = new Array();
messages[0] = new Array('images/galleries/PS_Mc1.jpg','Pavement Solutions');
messages[1] = new Array('images/galleries/PS_Mc2.jpg','Pavement Solutions');
messages[2] = new Array('images/galleries/PS_Mc3.jpg','Pavement Solutions');
messages[3] = new Array('images/galleries/PS_Mc4.jpg','Pavement Solutions');
messages[4] = new Array('images/galleries/PS_Mc5.jpg','Pavement Solutions');
messages[5] = new Array('images/galleries/PS_Tgt1.jpg','Pavement Solutions');
messages[6] = new Array('images/galleries/PS_Tgt2.jpg','Pavement Solutions');
messages[7] = new Array('images/galleries/PS_Tgt3.jpg','Pavement Solutions');
messages[8] = new Array('images/galleries/PS_Tgt4.jpg','Pavement Solutions');
messages[9] = new Array('images/galleries/PS_Tgt5.jpg','Pavement Solutions');
messages[10] = new Array('images/galleries/PS_01.jpg','Pavement Solutions');
messages[11] = new Array('images/galleries/PS_02.jpg','Pavement Solutions');
messages[12] = new Array('images/galleries/PS_03.jpg','Pavement Solutions');
messages[13] = new Array('images/galleries/PS_04.jpg','Pavement Solutions');
messages[14] = new Array('images/galleries/PS_05.jpg','Pavement Solutions');
messages[15] = new Array('images/galleries/PS_06.jpg','Pavement Solutions');
messages[16] = new Array('images/galleries/PS_07.jpg','Pavement Solutions');
messages[17] = new Array('images/galleries/PS_08.jpg','Pavement Solutions');

////////////////////
// PRELOAD IMAGES //
////////////////////
if (document.images) 
{
	var theImgs = new Array();
	for (var i=0; i<messages.length; i++) 
	{
  		theImgs[i] = new Image();
		theImgs[i].src = messages[i][0];
  	}
}

///////////////////
// INIT TOOL TIP //
///////////////////
var tooltip, tipstyle;
function init() 
{	
	if (nodyn) return;
	
	tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipstyle = tooltip.style;
	
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipstyle.width = "";
		tipstyle.fontFamily = "Arial,sans-serif";
		tipstyle.fontSize = "12px";
		tipstyle.color = "#000000";
		tipstyle.backgroundColor = "#ffffff";
		tipstyle.borderColor = "#cccccc";
		tipstyle.borderWidth = "0x";
		tipstyle.padding = "10px";
		tipstyle.borderStyle = "solid";
	}
	
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}

window.onload = init;

//////////////////////
// TOOLTIP FUNCTION //
//////////////////////
var tipOn = false;	// TOOLTIP NOT TURNED ON
function doTooltip(evt,num) 
{
	if (!tooltip) return; // IF THERE IS NO TOOLTIP, RETURN
	tipOn = true; // TOOLTIP TURNED ON
	
	if (ie4||ie5||ns5) 
	{
		tooltip.innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td align='center'><img src='" + messages[num][0] + "' border='0'></td></tr><tr><td valign='top'>" + '<div style="FONT:12px Arial,sans-serif; COLOR:#000000;">' + messages[num][1] + '</div>' + "</td></tr></table>";
	}
	
	setTimeout("tipstyle.visibility='visible'",100);
}

///////////////////////
// POSITION OF MOUSE //
///////////////////////
var mouseX, mouseY;
function trackMouse(evt) 
{
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (tipOn) positionTip(evt);
}

//////////////////////////////
// POSITION OF THE TOOL TIP //
//////////////////////////////
function positionTip(evt) 
{
	// TOOLTIP WIDTH AND HEIGHT
	var tipwidth = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tipheight = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	
	// DOCUMENT AREA IN VIEW (subtract scrollbar width for ns)
	var windowwidth = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var windowheight = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	
	//POSITION TOOLTIP
	if ((mouseX+offX+tipwidth) > windowwidth) 
		tipstyle.left = mouseX-(tipwidth+offX)+"px";
	else tipstyle.left = mouseX+offX+"px";
	if ((mouseY+offY+tipheight)>windowheight) 
		tipstyle.top = windowheight-(tipheight+offY)+"px";
	else tipstyle.top = mouseY+offY+"px";
}

///////////////////////
// HIDE THE TOOL TIP //
///////////////////////
function hideTip() 
{
	if (!tooltip) return;  // IF THERE IS NO TOOLTIP, RETURN
	
	setTimeout("tipstyle.visibility='hidden'",100);
	
	tipOn = false; // TOOLTIP NOT ON
}

document.write('<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>')