(function() {
"use strict";

	var doCalc;

	window.voteSite = function(url,snUrl) {
		window.open(url);
		window.location=snUrl;
	};

	doCalc = function(type, number, totalDest) {
		var i = 1, total = 0, df=document.FORM;
		for(; i<=number; i++) {
			total += df[type+i].value * 1;
		}
		df[totalDest].value = total;
	};

	// Recalculate total number of ports, summing over level
	window.levelCalc = function(maxPortLevel) {
		doCalc('port', maxPortLevel, 'total');
	};

	// Recalculate sum of port race percentages
	window.raceCalc = function() {
		doCalc('race', 9, 'racedist');
	};

	// Set the total number of ports to zero
	window.setZero = function(maxPortLevel) {
		var df = document.FORM;
		for (var i=1; i<=maxPortLevel; i++) {
			df['port'+i].value = 0;
		}
		df.total.value = 0;
	};

	// Set the port race distribution to be equal
	window.setEven = function() {
		var i = 2, df=document.FORM;
		df.race1.value = 12;
		for(; i<=9; i++) {
			df['race'+i].value = 11;
		}
		df.racedist.value = 100;
	};

	var body, currentlyFlashing=false, flashColour, origColour, intervalFlash, timeoutStopFlash, stopFlash, bgFlash;

	stopFlash = function() {
		clearInterval(intervalFlash);
		body.style.backgroundColor = origColour;
		currentlyFlashing = false;
	};

	bgFlash = function() {
		var body = document.getElementsByTagName('body')[0];
		if(body.style.backgroundColor === origColour) {
			body.style.backgroundColor = flashColour;
		}
		else {
			body.style.backgroundColor = origColour;
		}
	};

	window.triggerAttackBlink = function(colour) {
		if(origColour == null) {
			origColour = document.getElementsByTagName('body')[0].style.backgroundColor;
		}
		flashColour = '#'+colour;
		clearTimeout(timeoutStopFlash);
		if (currentlyFlashing === false) {
			currentlyFlashing = true;
			//flash 3 times
			bgFlash();
			intervalFlash = setInterval(bgFlash,500);
		}
		timeoutStopFlash = setTimeout(stopFlash,3500);
	};
})();

@@ -26,22 +26,8 @@
 %22;%0A%0A
-%09var doCalc;%0A%0A
 %09win
@@ -118,25 +118,16 @@
 ;%0A%0A%09
-doCalc = 
 function
 (typ
@@ -122,16 +122,23 @@
 function
+ doCalc
 (type, n
@@ -1085,52 +1085,30 @@
 lash
-, stopFlash, bgFlash;%0A%0A%09stopFlash = function
+;%0A%0A%09function stopFlash
 () %7B
@@ -1222,26 +1222,16 @@
 ;%0A%0A%09
-bgFlash = 
 function
 () %7B
@@ -1218,32 +1218,40 @@
 ;%0A%09%7D;%0A%0A%09function
+ bgFlash
 () %7B%0A%09%09var body 

remove free function variables