//  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, infoDiv, 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=(infoDiv.document.width)? infoDiv.document.width : infoDiv.clip.width;
if(IE5||IE4)boxwidth=(infoDiv.style.pixelWidth)? infoDiv.style.pixelWidth : infoDiv.offsetWidth;
if(NS6)boxwidth=(infoDiv.style.width)? parseInt(infoDiv.style.width) : parseInt(infoDiv.offsetWidth);
}

function getboxheight(){
if(NS4)boxheight=(infoDiv.document.height)? infoDiv.document.height : infoDiv.clip.height;
if(IE4||IE5)boxheight=(infoDiv.style.pixelHeight)? infoDiv.style.pixelHeight : infoDiv.offsetHeight;
if(NS6)boxheight=parseInt(infoDiv.offsetHeight);

}

function moveinfoDiv(x,y){
if(NS4)infoDiv.moveTo(x,y);
if(W3C||IE4){
infoDiv.style.left=x+'px';
infoDiv.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){
infoDiv.document.open();
infoDiv.document.write(text);
infoDiv.document.close();
}
if(isMac && (IE4 || IE5))infoDiv.innerHTML=text;
else if (W3C||IE4)infoDiv.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)infoDiv.visibility="hide";
if(IE4||W3C){
infoDiv.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;
moveinfoDiv( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getpagescrollx() , my+yoff+getpagescrolly());
if(NS4)infoDiv.visibility="show";
if(W3C||IE4)infoDiv.style.visibility="visible";
}}

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;
window.onload=function(){
  infoDiv=(NS4)? document.layers['infoDiv'] : (IE4)? document.all['infoDiv'] : (W3C)? document.getElementById('infoDiv') : null;
  getboxwidth();
  getboxheight();
  getwindowdims();
  isloaded=true;
  if((W3C || IE4) && centertext)infoDiv.style.textAlign="center";
  if(W3C)infoDiv.style.padding='4px';
  }
window.onresize=getwindowdims;

stateText=[];
stateText[0]=["New Mexico", "5", "Oct. 5", "48", "286,783", "48", "286,417", "4", "21,251"];
stateText[1]=["Arizona", "10", "Oct. 4", "45", "685,341", "51", "781,652", "3", "45,645"];
stateText[2]=["Nevada", "5", "Oct. 2", "46", "279,978", "50", "301,575", "2", "15,008"];
stateText[3]=["Oregon", "7", "Oct. 12", "47", "720,342", "47", "713,577", "5", "77,357"];
stateText[4]=["Minnesota", "10", "Oct. 12", "48", "1,168,266", "46", "1,109,659", "5", "126,696"];
stateText[5]=["Iowa", "7", "Oct. 18", "49", "638,517", "48", "634,373", "2", "29,374"];
stateText[6]=["Missouri", "11", "Oct. 6", "47", "1,111,138", "50", "1,189,924", "2", "38,515"];
stateText[7]=["Arkansas", "6", "Oct. 3", "46", "422,768", "51", "472,940", "1", "13,421"];
stateText[8]=["Wisconsin", "10", "Oct. 20", "48", "1,242,987", "48", "1,237,279", "4", "94,070"];
stateText[9]=["Michigan", "17", "Oct. 4", "51", "2,170,418", "46", "1,953,139", "2", "84,165"];
stateText[10]=["Ohio", "20", "Oct. 4", "46", "2,183,628", "50", "2,350,363", "3", "117,799"];
stateText[11]=["Pennsylvania", "21", "Oct. 4", "51", "2,485,967", "46", "2,281,127", "2", "103,392"];
stateText[12]=["New Hampshire", "4", "Oct. 23", "47", "266,348", "48", "273,559", "4", "22,198"];
stateText[13]=["Tennessee", "11", "Oct. 3", "47", "981,720", "51", "1,061,949", "1", "19,781"];
stateText[14]=["Florida", "27", "Oct. 4", "49", "2,912,253", "49", "2,912,790", "2", "97,488"];
stateText[15]=["West Virginia", "5", "Oct. 13", "46", "295,497", "52", "336,475", "2", "10,680"];
stateText[16]=["Colorado", "9", "Oct. 4", "42", "738,227", "51", "883,748", "5", "91,434"];
stateText[17]=["North Carolina", "15", "Oct. 8", "43", "1,257,692", "56", "1,631,163", "--", "--"];
stateText[18]=["Maine", "4", "Oct. 19", "49", "319,951", "44", "286,616", "6", "37,127"];
stateText[19]=["Washington", "11", "Oct. 2", "50", "1,247,652", "45", "1,108,864", "4", "103,002"];

function showState( t ) {
	var ret;
	if (t.length != 9) alert("not right num args: got " +  t.length);
	if (isMac && (IE4 || IE5)){
		ret=t[0] + " - " + t[1] + " electoral votes<br>Registration Deadline: " + t[2] + "<br>" + t[3] + "% Democrat (" + t[4] + " votes)<br>" + t[5] + "% Republican (" + t[6] + " votes)<br>" + t[7] + "% Green (" + t[8] + " votes)";
	}
	else{
		ret="<h1><strong>" + t[0] + "</strong> - " + t[1] + " electoral votes</h1><p><strong>Registration Deadline: " + t[2] + "</strong><br>2000 election results:<br>" + t[3] + "% Democrat (" + t[4] + " votes)<br>" + t[5] + "% Republican (" + t[6] + " votes)<br>" + t[7] + "% Green (" + t[8] + " votes)</p>";
	}
	writetxt( ret );
}
function hideState(){
	writetxt(0);
}
