function toggleElement(e) {
	if (document.getElementById(e).style.display == "block") {
		document.getElementById(e).style.display="none";
		if (document.getElementById("arrow_"+e) != null) {
			document.getElementById("arrow_"+e).src="rightArrow.gif";
			document.getElementById("arrow_"+e).alt="Show Grandchildren";
		}
	}
	else {
		document.getElementById(e).style.display="block";
		if (document.getElementById("arrow_"+e) != null) {
			document.getElementById("arrow_"+e).src="downArrow.gif";
			document.getElementById("arrow_"+e).alt="Hide Grandchildren";
		}
	}
}

function showRef(event, rc, s) {

	s = s.replace(/%apos;/g, "'");
	s = s.replace(/%quot;/g, "\"");
	s = s.replace(/<td>/g, "<td valign=\"top\">");

	r = document.getElementById("refDiv");
	r.style.width = 300;

	r.innerHTML = "<table class=\"reference\" width=\"100%\"><tr><td><b><u>Reference #" + rc + "</u></b></td>"+
			"<td align=\"right\">"+
			"<a href=\"#\" onclick=\"hideRef(); return false;\"><img src=\"closeButton.gif\" border=0></a></td></tr></table>"+
			"<table class=\"reference\">"+s+"</table>";

	if (event.pageX || event.pageY) {
		r.style.left = event.pageX + "px";
		r.style.top = event.pageY-50 + "px";
	}
	else if (document.documentElement) {
		r.style.left = event.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft;
		r.style.top = event.clientY + document.documentElement.scrollTop  - document.documentElement.clientTop - 50;
	}
	else {
		r.style.left = event.clientX + document.body.scrollLeft - document.body.clientLeft;
		r.style.top = event.clientY + document.body.scrollTop  - document.body.clientTop - 50;
	}
	r.style.display="block";

	return false;
}

function hideRef() {
	document.getElementById("refDiv").style.display="none";
}

function setImageWidth(w) {
	document.images["image"].width = w;
	document.images["image"].height = fullHeight*w/fullWidth;
	if (document.getElementById("imageData")) {
		document.getElementById("imageData").innerHTML = "<table align=\"center\">"+
				"<tr><td>Full Width: </td><td>"+fullWidth+"</td></tr>"+
				"<tr><td>Full Height: </td><td>"+fullHeight+"</td></tr>"+
				"<tr><td>Current Width: </td><td>"+Math.round(w)+"</td></tr>"+
				"<tr><td>Current Height: </td><td>"+Math.round(document.images["image"].height)+"</td></tr>"+
				"<tr><td>Scaling: </td><td>"+Math.round(w*10000/fullWidth)/100+"%</td></tr>"+
				"</table>";
	}
}
function getDisplaySize() {
	dispWidth=0;
	dispHeight=0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    dispWidth = window.innerWidth;
	    dispHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    dispWidth = document.documentElement.clientWidth;
	    dispHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    dispWidth = document.body.clientWidth;
	    dispHeight = document.body.clientHeight;
	}
	return {width: dispWidth, height: dispHeight};
}

function imageReady() {
	fullWidth = preload.width;
	fullHeight = preload.height;
	heightFit = fullWidth*displaySize.height/fullHeight;
	if (heightFit < document.body.offsetWidth) {
		setImageWidth(heightFit);
	}
	else {
		setImageWidth(displaySize.width);
	}
	document.getElementById("image").src = preload.src;
}

function showImage(im) {
	window.open(im, "TSBImage", "menubar=no,scrollbars=yes,location=no").focus();
}

function initalizeMap() {
  var map = document.getElementById("map");
  var dispSize = getDisplaySize();
  map.style.height = (dispSize.height - map.offsetTop) + "px";
  if (GBrowserIsCompatible()) {
    var qs = location.search.substring(1).split("&");
    arg = new Array();
    for (var i=0; i < qs.length; i++) {
        var pqs = qs[i].split("=");
        arg[unescape(pqs[0])] = unescape(pqs[1].replace(/\+/g, ' '));
    }

    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(30, -20), 2);
    map.addControl(new GLargeMapControl());
    map.enableScrollWheelZoom();

    for (var i=0; i < mapLocation.length; i++) {
        var loc = mapLocation[i];
        var marker = new GMarker(new GLatLng(loc.lat, loc.lon), 
		{title: loc.label});
        marker.loc = loc;
		loc.marker = marker;
		
		var minRel = 99999999;
		for (k=0; k < loc.event.length; k++) {
		    for (kk=0; kk < loc.event[k].relDist.length; kk++)
			minRel = Math.min(minRel, loc.event[k].relDist[kk]);
		}
 
        map.addOverlay(marker);
		if (minRel == 1) { marker.setImage("yellowMarker.png"); }
		if (minRel == 2) { marker.setImage("greenMarker.png"); }
		if (minRel > 90000000) { marker.setImage("blueMarker.png"); }

		GEvent.addListener(map, "click", function(marker) {  
	    	if (marker != null) {
				var html = marker.loc.head;
				for (k=0; k < marker.loc.event.length; k++) 
					html += marker.loc.event[k].text;
				marker.openInfoWindowHtml(html);
	    	}
        });
 
        if (arg['where'] && loc.head.indexOf(">"+arg['where']+"<") > 0) {
			map.setCenter(marker.getLatLng(), 6);
			GEvent.trigger(marker, "click");
        }
    }
  }
}

function dumpinfo(x) {
	s = "";
	for(i in x)
		if (""+x[i] != "") s = s + i+": "+x[i]+"\n";
	alert(s);
}