//  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;

rolloverInfo=[];
rolloverInfo[0]=["Washington DC", "Protests planned on Jan. 20th.  More info TBA."];
rolloverInfo[1]=["San Francisco", "Jan. 20th Counter-Inaugural Demonstration.<br>Gather at 5pm, Civic Center."];
rolloverInfo[2]=["Los Angeles", "Jan. 20th Demonstration, 6pm<br>Westwood Federal Building."];

function showInfo( t ) {
	var ret;
	if (t.length != 2) alert("not right num args: got " +  t.length);
	if (isMac && (IE4 || IE5)){
		ret=t[0] + "<br>" + t[1];
	}
	else{
		ret="<h1><strong>" + t[0] + "</strong></h1><p>" + t[1];
	}
	writetxt( ret );
}
function hideState(){
	writetxt(0);
}

/* stateText functions from the statelabelDiv.js */
stateText=[];
stateText[0]=["New Mexico"];
stateText[1]=["Arizona"];
stateText[2]=["Nevada"];
stateText[3]=["Oregon"];
stateText[4]=["Minnesota"];
stateText[5]=["Iowa"];
stateText[6]=["Missouri"];
stateText[7]=["Arkansas"];
stateText[8]=["Wisconsin"];
stateText[9]=["Michigan"];
stateText[10]=["Ohio"];
stateText[11]=["Pennsylvania"];
stateText[12]=["New Hampshire"];
stateText[13]=["Tennessee"];
stateText[14]=["Florida"];
stateText[15]=["West Virginia"];
stateText[16]=["Washington"];
stateText[17]=["California"];
stateText[18]=["Idaho"];
stateText[19]=["Montana"];
stateText[20]=["Wyoming"];
stateText[21]=["Colorado"];
stateText[22]=["Utah"];
stateText[23]=["North Dakota"];
stateText[24]=["South Dakota"];
stateText[25]=["Nebraska"];
stateText[26]=["Kansas"];
stateText[27]=["Oklahoma"];
stateText[28]=["Texas"];
stateText[29]=["Illinois"];
stateText[30]=["Indiana"];
stateText[31]=["Louisiana"];
stateText[32]=["Kentucky"];
stateText[33]=["Mississippi"];
stateText[34]=["Alabama"];
stateText[35]=["Georgia"];
stateText[36]=["South Carolina"];
stateText[37]=["North Carolina"];
stateText[38]=["Virginia"];
stateText[39]=["Maryland"];
stateText[40]=["Delaware"];
stateText[41]=["New Jersey"];
stateText[42]=["New York"];
stateText[43]=["Vermont"];
stateText[44]=["Massachusetts"];
stateText[45]=["Rhode Island"];
stateText[46]=["Connecticut"];
stateText[47]=["Maine"];
stateText[48]=["Washington DC"];
stateText[49]=["San Francisco"];
stateText[50]=["Los Angeles"];

function showStateName( t ) {
	var ret;
	if (isMac && (IE4 || IE5)){
		ret=t[0]; //non html vers
	}
	else{
		ret="<h1><strong>" + t[0] + "</strong></h1>";//html vers
	}
	writetxt( ret );
}
function hideNonSwing(){
	writetxt(0);
}
