<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Ground Zero Mapplet" 
	description="Displays the thermal damage area of a nuclear explosion on a map. You can select the city and the weapon. Radiation and overpressure effects are not included here, as most people will be familiar with the consequences of heat and burns."
	author="Carlos Mari" author_affiliation="Carlos Labs Pty" author_location="Sydney, Australia" author_email="sales@carloslabs.com" title_url="http://www.carloslabs.com" author_link="http://www.carloslabs.com" author_photo="http://www.carloslabs.com/files/vertical_72dpi.png" screenshot="http://www.carloslabs.com/projects/200712B/img/gz_prev.png" thumbnail="http://www.carloslabs.com/projects/200712B/img/gz_thmb.png"
	height="250">
	<Require feature="sharedmap"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
<style>
.Small
{
	font-weight: normal;
	font-size: 10px;
	font-family: Arial, Helvetica;
	color: black;
}
.SmallCombo
{
	font-weight: bolder;
	font-size: 11px;
	font-family: Arial, Helvetica;
	color: #131313;
	background-color: #ceecee;
}
.TitleBoldRed
{
	font-weight: bold;
	font-size: 12px;
	font-family: Arial, Helvetica;
	color: #AA3333;
	margin: 2px;
}
.Buttons
{
	font-weight: bold;
	font-size: 12px;
	font-family: Arial, Helvetica;
	color: #AA3333;	
}
</style>
<script>
/*	Javascript Mapplet, Ground Zero ,v.1.5
	Carlos Labs Pty, 2007-2008
	PID: 200712B, http://www.carloslabs.com
	
	This code is released under a Creative Commons license. 
	http://creativecommons.org/licenses/by/3.0/legalcode

	You may use this code in any software project, provided you
	do not remove or modify this header and you credit us as the
	original authors of the code. */

var map = new GMap2();
var gZ = null;
		
var gr = new Array();
var w = new Array();
var c = new Array();
var step = 22;		// steps in a circle
var mapzoom = 13;	
var idx = 0;
var y = 0;
var town = ""		

var f = loadWepData();
f = loadCityData();

var n = "<b>Ground Zero Mapplet<b><br>";
n += "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\"><tr align=\"center\"><th width=\"40%\"><font size=\"2\" color=\"#333333\">Zone</font></th>";
if (is_MS() == 0)	{
	n += "<th width=\"60%\"><font size=\"2\" color=\"#333333\">Physical Effects</font></th></tr><tr align=\"center\"><td bgcolor=\"#ff9933\" width=\"40%\"><font size=\"1\" color=\"#ffffff\">1st Degree Burns</font>";	
	n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Sunburn-like mild discomfort, skin redness</font></td></tr><tr  align=\"center\"><td bgcolor=\"#cc6666\" width=\"40%\"><font size=\"1\" color=\"#ffffff\">2nd Degree Burns</font>";
	n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Blisters and pain, like burns caused by boiling water</font></td></tr><tr  align=\"center\"><td bgcolor=\"#660066\" width=\"40%\"><font size=\"1\" color=\"#ffffff\">3rd Degree Burns</font>";
	n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Skin charring and necrosis, requiring medical care</font></td></tr><tr  align=\"center\"><td bgcolor=\"#333333\" width=\"40%\"><font size=\"1\" color=\"#ffffff\">Conflagration</font>";
}
else	{
	n += "<th width=\"60%\"><font size=\"2\" color=\"#333333\">Physical Effects</font></th></tr><tr  align=\"center\"><td width=\"40%\"><font size=\"1\" color=\"#ff9933\">Tan, 1st Degree Burns</font>";	
	n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Sunburn-like mild discomfort, skin redness</font></td></tr><tr  align=\"center\"><td width=\"40%\"><font size=\"1\" color=\"#cc6666\">Salmon, 2nd Degree Burns</font>";
	n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Blisters and pain, like burns caused by boiling water</font></td></tr><tr align=\"center\"><td width=\"40%\"><font size=\"1\" color=\"#660066\">Purple, 3rd Degree Burns</font>";
	n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Skin charring and necrosis, requiring medical care</font></td></tr><tr align=\"center\"><td width=\"40%\"><font size=\"1\" color=\"#333333\">Black, Conflagration</font>";	
}
n += "</td><td width=\"60%\"><font size=\"1\">&nbsp;Most people will die within 24 hours of exposure</font></td></tr></table>";
 
// crude function to compensate for the earth's funny shape	
function kmToDegX(kms, latitude) {
	latitude = Math.abs(latitude);
	return (kms / (111.12 + (latitude * 1.3 ))); }
function kmToDegY(kms) {
	return (kms / 111.12); }
// sourced and inspired by www.fas.org and wikipedia.org
function b1dg(kt) {
	return Math.pow(kt,0.38) * 1.20;	}
function b2dg(kt) {
	return Math.pow(kt,0.40) * 0.87;	}
function b3dg(kt) {
	return Math.pow(kt,0.34) * 0.67;	}
function b4dg(kt) {
	return Math.pow(kt,0.30) * 0.55;	}				
function cX(x, radius, angle) {
	return x + radius * Math.cos(radians(angle));	}
function cY(y, radius, angle) {
	return y + radius * Math.sin(radians(angle));	}
function radians(degrees) {
	return degrees*Math.PI/180;		}
		
// Creates a marker at the given point with a narrative text
function createMarker(point, narrative) {
	 var marker = new GMarker(point,{draggable: true, bouncy: false});
	 GEvent.addListener(marker, "click", function() {
	   marker.openInfoWindowHtml(narrative);
	 });
	GEvent.addListener(marker, "dragend", function() {
		marker.getPointAsync(function(center)	{
			gZ = center;
			gr[0] = parseFloat(gZ.lat());
			gr[1] = parseFloat(gZ.lng());			
			//alert(gr[0].toString() + ' ' + gr[1].toString());
			map.clearOverlays();
			dropBomb();
		});
	});  
	return marker;
}	
// List of weapons
// yield in kilotons, year, country, narrative, map zoom
function loadWepData()	{
	w[0] = "0,0,0,0";
	w[1] = "15,1945,US,The uranium Hiroshima bomb was the 1st device used in war.,13";
	w[2] = "21,1945,US,The plutonium Nagasaki bomb was the 2nd device used in war.,13";
	w[3] = "400,1953,USSR,Named after Joseph Stalin; this was the 1st soviet H-bomb.,11";
	w[4] = "1400,1958,US,A cowboy was seen riding this bomb in the Dr Strangelove movie.,11";
	w[5] = "50000,1961,USSR,This was the largest explosion ever produced in history.,9";
	w[6] = "340,1991,US,A modern nuclear bomb that can be carried by a fighter jet.,11";
	w[7] = "140,2001,China,A modern nuclear bomb carried by an intercontinental missile.,11";
	w[8] = "9000000000,Prehistory,Cosmic Event,The Chicxulub impact caused the end of the dinosaurs.,3";	
	return 1;
}
// List of targets
// latitude, longitude, narrative
function loadCityData()	{
	c[0] = "0,0,0";
	c[1] = "10.485,-66.855,Capital of Venezuela; with 4 million people. Some are leftists and some are not.";
	c[2] = "37.423,-122.085,Right there in Silicon Valley; it rhymes with search engines and quirky widgets.";
	c[3] = "34.385,132.45,Now a modern major city; it was destroyed in the 1st ever nuclear attack.";
	c[4] = "51.510,-0.095,A very large and expensive city in England; full of black cabs and red buses.";
	c[5] = "40.415,-3.685,The capital of Spain is one of the best places in the world to go out clubbing.";	
	c[6] = "55.752,37.624,With over 10 million people; Moscow has been a target since the times of Napoleon.";
	c[7] = "32.77,129.866,Target of the 2nd nuclear attack in history. The bomb exploded over its cathedral.";
	c[8] = "28.632,77.22,The capital and second largest city in India with more than 14 million people.";
	c[9] = "43.6525,-79.395,The financial center of Canada can be a very cold place in the middle of winter.";
	c[10] = "-33.875,151.210,Many people think this is the capital of Australia. It is not. Sorry about that.";
	c[11] = "31.76,35.231,An ancient city at the center of three major religions and stage of much conflict.";
	c[12] = "38.897,-77.037,There are many museums and public buildings here; even some kind of House.";
	c[13] = "19.427,-99.1676,The largest city in all the Americas has almost 20 million inhabitants.";
	c[14] = "52.379,4.9,The capital of The Netherlands is a nice city; full of bicycles and tulips.";
	c[15] = "18.96,72.825,The largest city of India and capital of Bollywood films. How good is that?";
	c[16] = "25.059,121.57,Capital of Taiwan. Lots of computers and electronics come from this place. ";
	c[17] = "-37.82,144.968,Many people think this is the capital of Australia. It is not. Sorry about that.";
	c[18] = "40.443,-79.945,Steel capital of the U.S.A. City of bridges and home of the Mendicant Bug.";	
	return 1;
}
// Load the combo for weapons
function loadWeapon(form) {
	idx = form.selector.value;
	var wd = w[idx].split(",");
	y = parseInt(wd[0]);
	mapzoom = parseInt(wd[4]);
	document.getElementById('t_1').innerHTML = wd[1] + ", " + wd[2] + ", " + wd[3];
	return 1;
}
// Load the combo for Towns
function loadTown(form) {
	town = form.selector.value;
	if (town==0)
		return;
	var cd = c[town].split(",");
	gr[0] = parseFloat(cd[0]);
	gr[1] = parseFloat(cd[1]);
	gZ = new GLatLng(gr[0], gr[1]); 
	document.getElementById('t_2').innerHTML = cd[2];	
	map.setCenter(gZ, mapzoom);
	map.addOverlay(new GMarker(gZ));
	return 1;
}
// Run the script
function dropBomb() {
	var err = "";
	var vX = 0, vY = 0;
	var polyOptions = {geodesic:true};
	var zX = new Array();
	var zY = new Array();		
	var arrZero = new Array();
	var arrOne = new Array();
	var arrTwo = new Array();
	var arrThree = new Array();
	
	if (idx == 0) {
		err = "Select a Weapon from the list";
		alert(err);
		return 0;
	}
	if (town == 0) {
		err = "Select a City from the list";
		alert(err);		
		return 0;
	}	
	map.clearOverlays();
	map.setCenter(gZ, mapzoom);	
				
	map.addOverlay(createMarker(gZ, n));		
	zX[0] = kmToDegX(b1dg(y), gr[0]);
	zX[1] = kmToDegX(b2dg(y), gr[0]);
	zX[2] = kmToDegX(b3dg(y), gr[0]);
	zX[3] = kmToDegX(b4dg(y), gr[0]);	
	zY[0] = kmToDegY(b1dg(y));
	zY[1] = kmToDegY(b2dg(y));
	zY[2] = kmToDegY(b3dg(y));
	zY[3] = kmToDegY(b4dg(y));
	// many thanks to http://mendicantbug.com/ for picking this one up
	var tV = 0;
	if (zX[1] > zX[0])	{
		tV = zX[1];
		zX[1] = zX[0];
		zX[0] = tV;
	}
	if (zY[1] > zY[0])	{
		tV = zY[1];
		zY[1] = zY[0];
		zY[0] = tV;
	}	
	for (var i = 0; i < (step+1); i++) {
		vX = cX(gr[0], zX[0], (i * (360 / step)));
		vY = cY(gr[1], zY[0], (i * (360 / step))); 
		arrZero[i] = new GLatLng(vX, vY);
		vX = cX(gr[0], zX[1], (i * (360 / step)));
		vY = cY(gr[1], zY[1], (i * (360 / step))); 
		arrOne[i] = new GLatLng(vX, vY);
		vX = cX(gr[0], zX[2], (i * (360 / step)));
		vY = cY(gr[1], zY[2], (i * (360 / step))); 
		arrTwo[i] = new GLatLng(vX, vY);
		vX = cX(gr[0], zX[3], (i * (360 / step)));
		vY = cY(gr[1], zY[3], (i * (360 / step))); 
		arrThree[i] = new GLatLng(vX, vY);
	}		
	map.addOverlay(new GPolygon(arrZero, "#ff9933", 4, 0.6, "#ff9933", 0.4, polyOptions ));
	map.addOverlay(new GPolygon(arrOne, "#cc6666", 4, 0.6, "#cc6666", 0.4, polyOptions));
	map.addOverlay(new GPolygon(arrTwo, "#660066", 4, 0.6, "#660066", 0.4, polyOptions));
	map.addOverlay(new GPolygon(arrThree, "#333333", 4, 0.6, "#333333", 0.4, polyOptions));
	document.getElementById('t_3').innerHTML = "Click the marker for details, or drag the marker on the map";	
	return 1;
}
// Clears the map and resets all
function clearAll() {
	map.clearOverlays();
	document.forms.yields.selector.value = 0;
	document.forms.towns.selector.value = 0;
	document.getElementById('t_1').innerHTML = "&nbsp;";
	document.getElementById('t_2').innerHTML = "&nbsp;";
	document.getElementById('t_3').innerHTML = "&nbsp;";
	idx=0;town=0;
	mapzoom=13;
	return 1;
}
// the narrative must have a version for IE
function is_MS() 
{ 
    if (window.navigator.userAgent.indexOf("MSIE ") > 0)    	
    	return 1;
    else
    	return 0;
} 
</script>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<table bgcolor="#f9f9f9" align="center" width="100%" height="*" border=0 cellspacing=2 cellpadding=1>
<tr align="justified" valign="top">
	<td colspan="3">
		<div class="TitleBoldRed" align="center">Ground Zero Mapplet</div>
		<div class="Small">This mapplet shows the thermal damage caused by a nuclear explosion.<p> 
		Just select a city and a suitable weapon, and press "Nuke It!"</div>
	</td>
</tr>
<tr align="center" valign="top" height="64px">
	<form name="towns">
	<td width="48%">	
		<select class="SmallCombo" name="selector" onchange="loadTown(this.form)">
			<option value=0> Select a City </option>
			<option value=14>Amsterdam</option>
			<option value=1>Caracas</option>
			<option value=2>Googleplex</option>
			<option value=3>Hiroshima</option>
			<option value=11>Jerusalem</option>	
			<option value=4>London</option>
			<option value=5>Madrid</option>
			<option value=13>Mexico City</option>
			<option value=17>Melbourne</option>			
			<option value=15>Mumbai</option>							
			<option value=6>Moscow</option>			
			<option value=7>Nagasaki</option>
			<option value=8>New Delhi</option>
			<option value=18>Pittsburgh</option>			
			<option value=16>Taipei</option>			
			<option value=9>Toronto</option>						
			<option value=10>Sydney</option>
			<option value=12>Washington</option>								
		</select>
		<br>
		<div class="Small" align="center" id="t_2">&nbsp;</div>		 					
	</td>
	</form>
		<td width="2%">
			&nbsp;
		</td>	
	<form name="yields">
	<td width="48%">	
		<select class="SmallCombo" name="selector" onchange="loadWeapon(this.form)">
			<option value=0> Select a Weapon </option>
			<option value=1>"Little Boy" 15kt</option>
			<option value=2>"Fat Man" 21kt</option>
			<option value=3>"Joe-4" 400kt</option>
			<option value=4>"Mk28" 1.4mt</option>
			<option value=5>"Tsar Bomba" 50mt</option>
			<option value=6>"B61" 340kt</option>
			<option value=7>"DF-31" 140kt</option>
			<option value=8>Asteroid Impact</option>
		</select>
		<br>
		<div class="Small" align="center" id="t_1">&nbsp;</div>		 					
	</td>
	</form>
</tr>
<tr valign="middle">
	<td colspan="3" align="center">
		<div class="Small" align="center" id="t_3">&nbsp;</div>			
	</td>
</tr>		
<tr>
	<td align="center" valign="middle" colspan="3">
		<input id="btn" class="Buttons" type="button" value="Nuke It!" name="btnRun" onclick="javascript:dropBomb();"/> - 
		<input id="btn" class="Buttons" type="button" value="Reset" name="btnClear" onclick="javascript:clearAll();"/>
	</td>
</tr>
</table>
]]>
</Content>
</Module>