//  Adapted from ALTTXT V1.2 BY: BRIAN GOSSELIN OF SCRIPTASYLUM.COM -- see http://www.dynamicdrive.com)
//  Introduced code branch for mac IE because changing innerHTML can cause instability there and must be done more reservedly than elsewhere

var center=true;     // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE
var centertext=false; // CENTERS THE TEXT INSIDE THE BOX. YOU CAN'T SIMPLY DO THIS VIA STYLE BECAUSE OF NS4.
                     // OTHERWISE, TEXT IS LEFT-JUSTIFIED. 

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;
var isMac = navigator.userAgent.toLowerCase().indexOf('mac')!=-1;

var w_y, w_x, rolloverDiv, boxheight, boxwidth;
var ishover=false;
var isloaded=false;

function getwindowdims(){
w_y=(NS4||NS6||window.opera)? window.innerHeight : (IE5||IE4)? document.body.clientHeight : 0;
w_x=(NS4||NS6||window.opera)? window.innerWidth : (IE5||IE4)? document.body.clientWidth : 0;
}

function getboxwidth(){
if(NS4)boxwidth=(rolloverDiv.document.width)? rolloverDiv.document.width : rolloverDiv.clip.width;
if(IE5||IE4)boxwidth=(rolloverDiv.style.pixelWidth)? rolloverDiv.style.pixelWidth : rolloverDiv.offsetWidth;
if(NS6)boxwidth=(rolloverDiv.style.width)? parseInt(rolloverDiv.style.width) : parseInt(rolloverDiv.offsetWidth);
}

function getboxheight(){
if(NS4)boxheight=(rolloverDiv.document.height)? rolloverDiv.document.height : rolloverDiv.clip.height;
if(IE4||IE5)boxheight=(rolloverDiv.style.pixelHeight)? rolloverDiv.style.pixelHeight : rolloverDiv.offsetHeight;
if(NS6)boxheight=parseInt(rolloverDiv.offsetHeight);

}

function moveRolloverDiv(x,y){
if(NS4)rolloverDiv.moveTo(x,y);
if(W3C||IE4){
rolloverDiv.style.left=x+'px';
rolloverDiv.style.top=y+'px';
}}

function getpagescrolly(){
if(NS4||NS6)return window.pageYOffset;
if(IE5||IE4)return ietruebody().scrollTop;
}

function getpagescrollx(){
if(NS4||NS6)return window.pageXOffset;
if(IE5||IE4)return ietruebody().scrollLeft;
}

function writeindiv(text){
if(NS4){
rolloverDiv.document.open();
rolloverDiv.document.write(text);
rolloverDiv.document.close();
}
if(isMac && (IE4 || IE5))rolloverDiv.innerHTML=text;
else if (W3C||IE4)rolloverDiv.innerHTML=text;
}

//**** END UTILITY FUNCTIONS ****//

function writetxt(text){
if(isloaded){
if(text!=0){
ishover=true;
if(NS4)text='<div class="navtext">'+((centertext)?'<center>':'')+text+((centertext)?'</center>':'')+'</div>';
writeindiv(text);
getboxheight();
}else{
if(NS4)rolloverDiv.visibility="hide";
if(IE4||W3C){
rolloverDiv.style.visibility="hidden";
}
writeindiv('');
ishover=false;
}}}

function moveobj(evt){
if(isloaded && ishover){
margin=(IE4||IE5)? 1 : 23;
if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
if(NS4)if(document.height-window.innerHeight<0)margin=10;
//mx=(NS4||NS6)? evt.pageX : (IE5||IE4)? event.clientX : 0;
//my=(NS4||NS6)? evt.pageY : (IE5||IE4)? event.clientY : 0;
if (NS4){
mx=evt.pageX
my=evt.pageY
}
else if (NS6){
mx=evt.clientX
my=evt.clientY
}
else if (IE5){
mx=event.clientX
my=event.clientY
}
else if (IE4){
mx=0
my=0
}

if(NS4){
mx-=getpagescrollx();
my-=getpagescrolly();
}
xoff=(center)? mx-boxwidth/2 : mx+5;
yoff=(my+boxheight+30-getpagescrolly()+margin>=w_y)? -15-boxheight: 30;
moveRolloverDiv( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getpagescrollx() , my+yoff+getpagescrolly());
if(NS4)rolloverDiv.visibility="show";
if(W3C||IE4)rolloverDiv.style.visibility="visible";
}}

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;

function initRolloverDiv() {
  rolloverDiv=(NS4)? document.layers['rolloverDiv'] : (IE4)? document.all['rolloverDiv'] : (W3C)? document.getElementById('rolloverDiv') : null;
  getboxwidth();
  getboxheight();
  getwindowdims();
  isloaded=true;
  if((W3C || IE4) && centertext)rolloverDiv.style.textAlign="center";
  if(W3C)rolloverDiv.style.padding='4px';
  }

addLoadEvent( initRolloverDiv );
window.onresize=getwindowdims;

ethnicData=[];
ethnicData[0]=["Black", 14, 1125, "#222", "#fff"];
ethnicData[1]=["Hispanic", 12, 900, "#95540f", "#fff"];
ethnicData[2]=["White", 8, 675, "#ededed", "#000"];
ethnicData[3]=["Asian", 2, 150, "#ffff75", "#000"];

function showEthnicData( t ) {
	var ret;
	if (t.length != 5) alert("not right num args: got " +  t.length);
	if (isMac && (IE4 || IE5)){
		ret=0;
	}
	else{
		ret='<h4 style="background-color: ' + t[3] + '; color:' + t[4] + ';">Avg. ' + t[0] + ' Person</h4>';
		ret+='<p>Est. yearly loans: <strong>' + t[1] + '</strong><br>Est. yearly profit: <strong>$' + t[2] + '</strong></p>';
	}
	writetxt( ret );
}


ageData=[];
ageData[0]=["15-24", 11, 900, "#4e8e0c", "#fff"];
ageData[1]=["25-34", 9, 735, "#477a79", "#fff"];
ageData[2]=["35-44", 8, 645, "#5d5088", "#fff"];
ageData[3]=["45-54", 7, 565, "#70282e", "#fff"];
ageData[4]=["55-64", 8, 645, "#868e88", "#fff"];
ageData[5]=["65+", 9, 735, "#2d5926", "#fff"];

function showAgeData( t ) {
	var ret;
	if (t.length != 5) alert("not right num args: got " +  t.length);
	if (isMac && (IE4 || IE5)){
		ret=0;
	}
	else{
		ret='<h4 style="background-color: ' + t[3] + '; color:' + t[4] + ';">Avg. ' + t[0] + ' Year Old</h4>';
		ret+='<p>Est. yearly loans: <strong>' + t[1] + '</strong><br>Est. yearly profit: <strong>$' + t[2] + '</strong></p>';
	}
	writetxt( ret );
}

function hideRollover(){
	writetxt(0);
}