var DHTML = (document.getElementById || document.all || document.layers);
var vis = 1;
var total = '20';
var mirror = '';
var email=swapPairs('aegdxn@gdl+log');

var mirrors=[
		"http://homepage.mac.com/demark/tsunami",
		"http://tsunami.ems.psu.edu/dotmacmirror",
		"http://tsunami.demark.org",
		"http://giraffedesign.com/tsunami",
		"http://www.third-core.org/mirrored/dotmacmirror",
		"http://icons.wunderground.com/dotmacmirror",
		"http://www.foxriverweb.net/dotmacmirror",
		"http://asuaf.org/~xander/dotmacmirror",
		"http://www.ax86.net/dotmacmirror",
		"http://weather.bgsu.edu/dotmacmirror",
		"http://ccn1.net/POTD/tsunami",
		"http://planetmirror.com/pub/asiantsunamipics/demark",
		"http://tsunami.frii.com",
		"http://home.swiftdsl.com.au/~mbottrell/tsunami",
		"http://www.swiftel-users.com/tsunami",
		"http://www.homedecorlighting.com/dotmacmirror",
		"http://dotmac.opinguim.net",
		"http://www.spirit-talk.co.uk/dotmacmirror",
		"http://www.issop.com/tsunami",
		"http://homepage.mac.com/demark/tsunami"
		];
var mirrorsCredit=[
		"Apple's <a href=\"http://www.mac.com\">.mac</a>",
		"<a href=\"http://www.ems.psu.edu\">College of Earth and Mineral Sciences, Penn State</a>",
		"<a href=\"http://www.ev1.net\">Everyones Internet (EV1)</a>",
		"<a href=\"http://www.giraffedesign.com\">Giraffe Design, Ltd</a>",
		"<a href=\"http://www.third-core.org\">TCNetworks</a>",
		"<a href=\"http://www.wunderground.com\">Weather Underground</a>",
		"<a href=\"http://www.foxriverweb.com\">Fox River Web - Yorkville, IL</a>",
		"<a href=\"mailto:fsajt@uaf.edu\">Alex Taylor</a>",
		"<a href=\"http://www.ax86.net\">ax86.net</a>",
		"<a href=\"http://weather.bgsu.edu\">weather.bgsu.edu</a>",
		"<a href=\"http://www.ccn1.net/darkred/directory/?&passurl=/Science/Earth_Sciences/Natural_Disasters_and_Hazards\">DarkRed.net</a>",
		"<a href=\"http://planetmirror.com\">Planet Mirror, Australia</a>",
		"<a href=\"http://www.frii.com/\">Front Range Internet, Inc.</a>",
		"<a href=\"http://www.swiftdsl.com.au/\">SwiftDSL</a>",
		"<a href=\"http://www.swiftel-users.com/\">Swiftel-Users</a>",
		"<a href=\"http://www.homedecorlighting.com/\">Home D&eacute;cor Lighting</a>",
		"<a href=\"http://www.opinguim.net/\">Opinguim.net Pro Hosting</a>",
		"<a href=\"http://www.spirit-talk.co.uk/\">www.spirit-talk.co.uk</a>",
		"<a href=\"http://www.issop.com/\">www.issop.com</a>",
		"Apple's <a href=\"http://www.mac.com\">.mac</a>"
		];
var mirrorWeight=[
		20,					// .Mac
		0,					// 8, EMS
		0,					// 7, EV1
		0,					// 1, Giraffe Design
		0,					// 1, TCNetworks
		0,					// Wunderground
		0,					// Fox River Web
		0,					// Alex Taylor
		0,					// ax86
		0,					// 1, weather.bgsu.edu
		0,					// Dark Red
		0,					// Planet Mirror
		0,					// Front Range Internet
		0,					// 2, Swift DSL
		0,					// SwiftTel
		0,					// HomeDecorLighting
		0,					// Opingium
		0,					// www.spirit-talk.co.uk
		0,					// www.issop.com
		0					// .Mac
		];
var totalWeight=eval(mirrorWeight.join("+"));
var weighedMirrors=new Array();
var weighedMirrorsCredit=new Array();
var currentMirror=0;

while(currentMirror<totalWeight){
	for(i=0;i<mirrorWeight[currentMirror];i++){
		weighedMirrors[weighedMirrors.length]=mirrors[currentMirror];
		weighedMirrorsCredit[weighedMirrorsCredit.length]=mirrorsCredit[currentMirror];
	}
currentMirror++;
}

var rndMirror=Math.floor(Math.random()*totalWeight);
mirror=weighedMirrors[rndMirror];
mirrorCredit=weighedMirrorsCredit[rndMirror];

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}


function toggle_vis()
{

	if (!DHTML) return;
	var after = new getObj('after');
	after.style.visibility = (vis) ? 'visible' : 'hidden';
	document.getElementById("toggle").value = (vis) ? 'After. Click To See Before.' : 'Before. Click To See After.'; 
	vis = (vis + 1) % 2;
}


function getImg() {
	num = Math.floor(Math.random() * 2000);

	if (num <= 50) {
		return 1;
	} else {
		return 0;
	}
}

function writeHdg() {

document.write("<div id=\"heading\">\n");
document.write("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n");
document.write("<tr>\n");
document.write("<td align=\"left\">\n");
document.write("Thanks to our <a href=\"http://homepage.mac.com/demark/mirrors.html\">mirrors</a>.\n");
document.write("</td>\n");
document.write("<td align=\"right\">\n");
document.write("Image storage space provided by: " + mirrorCredit + "\n");
document.write("</td>\n");
document.write("</tr>\n");
document.write("<tr>\n");
document.write("<td align=\"center\" colspan=\"2\">\n");
//document.write("Thanks to our <a href=\"http://homepage.mac.com/demark/mirrors.html\">mirrors</a>.\n");
document.write("</td>\n");
document.write("</tr>\n");
document.write("</table>\n");
document.write("<p>\n");
document.write("</p>\n");
document.write("<p>The \"Before/After\" button below (the one that is currently labelled <b>Before. Click To See After.</b>) toggles the image between the \"Before\" and \"After\" satellite photos. You can also toggle the image by clicking on the image itself. The \"PREV\" and \"NEXT\" links will take you to the previous or next image set ... there are 20 sets in this series.\n");
document.write("</p>\n");
document.write("</div>\n");


}

function writeCtrl(title,num,before,after) {

document.write("<div id=\"control\">\n");
document.write("<table width=\"100%\">\n");
document.write("<tr>\n");
document.write("<td align=\"left\" width=\"350\">Currently Viewing:<input id=\"toggle\" type=\"button\" value=\"Before. Click To See After.\" onclick=\"javascript:toggle_vis()\"></td>\n");
document.write("<td align=\"center\" width=\"100\"><a href=\"" + before + ".html\">PREV</a></td>\n");
document.write("<td align=\"center\" width=\"100\"><a href=\"" + after + ".html\">NEXT</a></td>\n");
document.write("<td align=\"right\" width=\"200\"><a href=\"http://www.google.com/tsunami_relief.html\"><b>Help Tsunami Victims</b></a></td>\n");
document.write("</tr>\n");
document.write("<tr>\n");
document.write("<td align=\"left\" width=\"350\" colspan=\"1\">Set " + num + " of " + total + ": " + title + "</td>\n");
document.write("<td align=\"right\" width=\"400\" colspan=\"3\">Page created by <a href=\"mailto:" + email + "\">Tony Demark</a>. Images &copy; <a href=\"http://www.digitalglobe.com\">DigitalGlobe</a></td>\n");
document.write("</tr>\n");
document.write("</table>\n");

document.write("</div>\n");

}

function writeImg(img) {

document.write("<div id=\"before\">\n");
document.write("<a name=\"#\" onclick=\"javascript:toggle_vis()\"><img src=\"" + mirror + "/" + img + "a.jpg\" border=\"0\"></a>\n");
document.write("</div>\n");
document.write("<div id=\"after\">\n");
document.write("<a name=\"#\" onclick=\"javascript:toggle_vis()\"><img src=\"" + mirror + "/" + img + "b.jpg\" border=\"0\"></a>\n");
document.write("</div>\n");

}

function writeCounter() {

document.write("<div id=\"counter\">\n");
document.write("<script type=\"text/javascript\">\n");
document.write("<!--\n");
document.write("// I'm trying to figure out where all this traffic is coming from! -Tony\n");
document.write("refpat=/homepage\\.mac\\.com\\/demark/;\n");
document.write("if (document.referrer&&document.referrer!=\"\"&&!refpat.test(document.referrer)) {\n");
document.write("document.write('<img src=\"http://tony.demark.org/counter.gif?ref=' + document.referrer + '\">');\n");
document.write("} else {\n");
document.write("if (getImg()) {\n");
document.write("document.write('<img src=\"http://tony.demark.org/counter.gif\">');\n");
document.write("}\n");
document.write("}\n");
document.write("//-->\n");
document.write("</script>\n");
document.write("</div>\n");


}

function writeCredit() {

document.write("<div id=\"credit\">\n");
document.write("Page created by <a href=\"mailto:" + email + "\">Tony Demark</a>. Images &copy; <a href=\"http://www.digitalglobe.com\">DigitalGlobe</a>.\n");
document.write("<p /><script type=\"text/javascript\"><!--\ngoogle_ad_client = \"pub-5520648487318020\";\ngoogle_ad_width = 728;\ngoogle_ad_height = 90;\ngoogle_ad_format = \"728x90_as\";\ngoogle_ad_type = \"text_image\";\n//2006-10-19: Tsunami\ngoogle_ad_channel = \"0061509821\";\n//--></script>\n<script type=\"text/javascript\"\n  src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n</script>");
document.write("</div>\n");

}

function swapPairs(s){
  var res = ""; 
  for (var i=0; i<s.length; i++){
    var ch = s.charCodeAt(i) ;
    res += String.fromCharCode(
           ( ch & 0xF0 ) +
           ((ch & 0x0C)>>2) + 
           ((ch & 0x03)<<2) 
           );
    }
  return res
  }
