function doNode(node) {
	node.style.cursor = "pointer";
	var left = node.src.substring(0, node.src.indexOf(".png"));
	var right = node.src.substring(node.src.indexOf(".png"), node.src.length);
	
	var img = new Image();
	img.src = node.src;
	var rimg = new Image();
	rimg.src = left + "-over" + right;
	
	node.onmouseover = function() { node.src = rimg.src; }
	node.onmouseout = function() { node.src = img.src; }
}

function doRollovers() {
	var nodes = new Array();
	var elems = document.getElementsByTagName('*');
	var pattern = new RegExp("(^|\\s)rollover(\\s|$)");
	for (i = 0, j = 0; i < elems.length; i++) {
		if (pattern.test(elems[i].className) && elems[i].src) {
			nodes[j] = elems[i];
			j++;
		}
	}

	for (var x = 0; x < nodes.length; x++) {
		doNode(nodes[x]);
	}
}

doInit = function() {
	if (document.all && document.getElementById) {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		if (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7) {
			nav_root = document.getElementById("nav");
			for (i = 0; i < nav_root.childNodes.length; i++) {
				node = nav_root.childNodes[i];
				if (node.id && node.id.indexOf("nav-") != -1) {
					node.onmouseover = function() { this.className = "over"; }
					node.onmouseout = function() { this.className = this.className.replace("over", ""); }
				}
			}
		}
	}
	/*
	$("tools-text").addEvent("click", function(e) {
		var event = new Event(e);
		event.stop();
		var c = null;
		var textonly = Cookie.read("TEXTONLY");
		Cookie.dispose("TEXTONLY");
		if (!$chk(textonly) || textonly == "false") {
			c = Cookie.write("TEXTONLY", "true", {
				path: "/"
			});
		} else {
			c = Cookie.write("TEXTONLY", "false", {
				path: "/"
			});
		}
		var loc = window.location.href;
		var pound_loc = loc.indexOf("#")
		if (pound_loc != -1) { loc = loc.substr(0, pound_loc); }
		window.location.href = loc;
	});
	*/
	doRollovers();
}

window.onload = doInit;

//leaving the senate servers so we have to display this message:
function openWin(urlToOpen) {
	window.open("http://www.senate.gov/cgi-bin/exitmsg?url=" + urlToOpen);	
}

//leaving the current site, but staying on senate servers.
function openSenateWin(urlToOpen) {
	window.open(urlToOpen);	
}

function getQueryVal(param) {
		qs = window.location.search.substring(1);
		vals = qs.split("&");
		for (i=0;i<vals.length;i++) {
			ar = vals[i].split("=");
			if (ar[0] == param) {
				return ar[1];
			}
		}
}


//font size functions
var currentSize = 1;
var textIncrease = null; 
var textDecrease = null;

function SetCookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length; 
	return unescape( document.cookie.substring( len, end ) );
}

function CE_FixIE6(which) {
	document.getElementById("font_select").style.cssText = "background-position:0px 0px";
	document.getElementById("font_select_med").style.cssText = "background-position:0px 0px";
	document.getElementById("font_select_large").style.cssText = "background-position:0px 0px";
	if (which == "") {
		document.getElementById("font_select").style.cssText = "background-position:0px -14px";
	} else {
		document.getElementById("font_select_" + which).style.cssText = "background-position:0px -14px";
	}
}

function CE_SetPageFont(which) {
	document.body.className = "body_" + which;
	
	document.getElementById("tools-font-label").className = which;
	document.getElementById("tools-font-label").setAttribute("className", which);

	// IE6 hack
	if (document.all && !window.XMLHttpRequest) {
		CE_FixIE6(which);
	}
	var domain = site_webroot.substring(site_webroot.indexOf("http://") + 7, site_webroot.length - 1);

	SetCookie("font_size", which, 1, "/");
	window.location.href = window.location.href;
}

function CE_LoadPageFont() {
	if(Get_Cookie("font_size")) {
		fs = Get_Cookie("font_size");

		document.body.className = "body_" + fs;
		document.getElementById("tools-font-label").className = fs;
		
		// IE6 hack
		if (document.all && !window.XMLHttpRequest) {
			CE_FixIE6(fs);
		}
	}
}
