
//=== Do some initial stuff

//window.onError = null;

var using_netscape4 = (document.layers) ? 1 : 0;  // browser sniffer
var using_netscape6 = (document.getElementById&&!document.all) ? 1 : 0;
var using_ie4 = (document.all) ? 1 : 0;
var Mac = (navigator.userAgent.indexOf('Mac') != -1) ? 1 : 0;

var barSpacer = 4;

function init() {
	if (!Mac) {
		if (using_netscape4) {
			document.layers['cht'].top = document.layers['cht1'].pageY;
			document.layers['cht'].left = document.layers['cht1'].pageX;
			document.layers['cht'].visibility = "show";
			document.layers['cht'].onmousemove = handleMouseMove;
			document.layers['cht'].captureEvents(Event.MOUSEMOVE);

			document.layers['cht2'].top = document.layers['cht21'].pageY;
			document.layers['cht2'].left = document.layers['cht21'].pageX;
			document.layers['cht2'].visibility = "show";
			document.layers['cht2'].onmousemove = handleMouseMove2;
			document.layers['cht2'].captureEvents(Event.MOUSEMOVE);

		
		} else if (using_netscape6) {
			document.getElementById('cht1').style.visibility = "visible";		
			(document.getElementById('cht1')).addEventListener("mousemove", handleMouseMove, true);

	//		document.getElementById('cht21').style.visibility = "visible";		
	//		(document.getElementById('cht21')).addEventListener("mousemove", handleMouseMove2, true);

		} else if (using_ie4) {
			document.all['cht1'].visibility = "visible";
			document.all['cht1'].onmousemove = handleMouseMove;


			document.all['cht21'].visibility = "visible";
			document.all['cht21'].onmousemove = handleMouseMove2;
		}
	}
}


function handleMouseMove(e) {
	if (using_netscape4) {
		theObj = document.layers['cht']
		handleNS4Move(theObj, e, 0, 305);
//		return routeEvent(e);
		return;

		
	} else if (using_netscape6) {
	
	//	netscape 6 does not currently support rel pos divs
	//	so just return
	
		theObj = document.getElementById('cht1')
		handleNS6Move(theObj, e);
//		return routeEvent(e);
		return;
		

	} else if (using_ie4) {
	
		theObj = document.all['cht1'];
		handleIE4Move(theObj, e, 58);

//		return routeEvent(e);
		return;
	}
}


function handleMouseMove2(e) {
/*
	if (using_netscape4) {
		theObj = document.layers['cht2']
		handleNS4Move(theObj, e, 18, 305);
//		return routeEvent(e);
		return;
		
	} else if (using_netscape6) {
	
	//	netscape 6 does not currently support rel pos divs
	//	so just return
	
		theObj = document.getElementById('cht21');
		handleNS6Move(theObj, e);
//		return routeEvent(e);
		return;
		

	} else if (using_ie4) {
	
		theObj = document.all['cht21'];
		handleIE4Move(theObj, e, 13);

//		return routeEvent(e);
	}
*/
}

function handleNS4Move(theObj, e, offset, thew) {
	x = e.pageX; 
	y = e.pageY;
	l = theObj.pageX + 65 + offset;
	r = l + thew;
	t = theObj.pageY + 15;
	b = theObj.pageY + 92;
	if (x > l   &&  x < r && y > t &&  y < b) {
		setBarNS4(y, l, x, r, "show", thew);
	} else {
		document.layers['lBar'].visibility = "hide";
		document.layers['rBar'].visibility = "hide";
	}

}

function handleNS6Move(theObj, e) {
	x = e.pageX; 
	y = e.pageY;
	pxl = parseInt(theObj.style.left) + 65;
	py = parseInt(theObj.style.top);
	pxr = pxl+305;

/*alert("left = " + theObj.style.left +
      "\ntop = " + theObj.style.top +
      "\nx   = " + x + "\npxl = " + pxl + "\npxr = " + pxr +
      "\ny   = " + y + "\npy  = " + py);
*/

	if (x > pxl   &&  x < pxr && y > py+15 &&  y < py+92) {
		setBarNS6(y, pxl, x, pxr, "visible");
	} else {
//		setBarNS6(-1000, -1000, -1000, -1000, "hidden");
		document.getElementById('lBar').style.visibility = "hidden";
		document.getElementById('rBar').style.visibility = "hidden";
	}

}

function handleIE4Move(theObj, e, offset) {

	eletop = parseInt(theObj.offsetTop) + 15;
	elebot = eletop + 92 - 18;
	eleleft = parseInt(theObj.offsetLeft) + 65 + offset;
	eleright = eleleft + 305;
	
	x = parseInt(document.body.scrollLeft) + window.event.clientX;
	y = parseInt(document.body.scrollTop) + window.event.clientY;

	if (x > eleleft   &&  x < eleright && y > eletop &&  y < elebot) {
		setBarIE4(y, eleleft, x, eleright, "visible");
	} else {
		document.all['lBar'].style.visibility = "hidden";
		document.all['rBar'].style.visibility = "hidden";
	}

}


function setBarNS4(t, l, x, r, vis, thew) {
	document.layers['lBar'].top = t;
	document.layers['lBar'].left = l;
	document.layers['lBar'].clip.right = (x - l) - (barSpacer + 2);
	document.layers['lBar'].visibility = vis;

	document.layers['rBar'].top = t;
	document.layers['rBar'].left = x + barSpacer + 2;
	document.layers['rBar'].clip.right = r - (x + barSpacer + 2);
	document.layers['rBar'].visibility = vis;
}


function setBarNS6(t, l, x, r, vis) {
	document.getElementById('lBar').style.top = t + "px";
	document.getElementById('lBar').style.left = x - (305 + barSpacer) + "px";
	document.getElementById('lBar').style.clip.left = 305 - (x - l) + "px";
	document.getElementById('lBar').style.visibility = vis;

	document.getElementById('rBar').style.top = t + "px";
	document.getElementById('rBar').style.left = x + barSpacer + 2 + "px";
	document.getElementById('rBar').style.clip.right = r - (x + barSpacer + 2) + "px";
	document.getElementById('rBar').style.visibility = vis;

}

function setBarIE4(t, l, x, r, vis) {
	
	document.all['lBar'].style.top = t;
	document.all['lBar'].style.left = l;
	clipItem (document.all['lBar'], 0, 0, ((x - barSpacer) - l ), 3 );
	document.all['lBar'].style.visibility = vis;

	document.all['rBar'].style.top = t;
	document.all['rBar'].style.left = x + barSpacer + 2;
	clipItem (document.all['rBar'], 0, 0, (r - (x + barSpacer)), 3 );
	document.all['rBar'].style.visibility = vis;

}

function clipItem (theObj,clipleft,cliptop,clipright,clipbottom) {

//	alert('Clipping to: rect('+clipleft+' '+cliptop+' '+clipright+' '+clipbottom+')');

	if(using_netscape4) {
		theObj.clip.left=clipleft;
		theObj.clip.top=cliptop;
		theObj.clip.right=clipright;
		theObj.clip.bottom=clipbottom;
	} else if(using_ie4) {
		theObj.style.clip='rect('+cliptop+' '+clipright+' '+clipbottom+' '+clipleft+')';
	}
}
