var message = "Table Top Rally\nBen Crossley\nCopyright 2003."

function click(e) {
	if (document.all) {
		if (event.button == 2) {
		alert(message);
		return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
		alert(message);
		return false;
		}
	}
}

if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
}


document.onmousedown=click;

var checkpoint = 0;
var startindex = 0;
var lastindex = 0;
var spot_left = [97,159,374,447,644,700,243,68];

function ttrally(tt)	{

//DBug.value += "\n" + checkpoint + " " + areas[0].coords ;

checkpoint = checkpoint + 1;

window.scroll(0,0);

switch (checkpoint)	{

case 1:
	ob("spot0").style.left = "97px";
	ob("map0").style.display = "none";
	ob("map1").style.display = "block";
	ob("are1").title = "2: Erq Yvba, Uhapbgr".rot13();
	document.clue.here.value += "\nPbeerpg: Gur Urngupbgr Nezf, Pebsg\n\n2: Gur Erq cynpr jr hfrq gb zrrg. Frr Pyho Avtugf".rot13();
	var starttime = new Date();
	startindex = starttime.getTime();
	startindex = Math.floor(startindex/1000)-lastindex;
//	document.cookie = "ttrally=" + startindex;
break;

case 2:
	ob("spot1").style.left = "159px";
	ob("map1").style.display = "none";
	ob("map2").style.display = "block";
	ob("are2").title = "3: Gur Cybhtu, Yvggyrgubecr".rot13();
	document.clue.here.value += "\nPbeerpg: Erq Yvba, Uhapbgr\n\n3: Phg n sheebj gb rneyl 70f Fhaqnl avtug. Tvir yvggyr gubhtug.".rot13();
break;

case 3:
	ob("spot2").style.left = "374px";
	ob("map2").style.display = "none";
	ob("map3").style.display = "block";
	ob("are3").title = "4: Sbkuhagre, Raqreol".rot13();
	document.clue.here.value += "\nPbeerpg: Gur Cybhtu, Yvggyrgubecr\n\n4: Fbzr bs hf zrg urer Abirzore 2002. Frr Cubgb Tnyyrel".rot13();
break;

case 4:
	ob("spot3").style.left = "447px";
	ob("map3").style.display = "none";
	ob("map4").style.display = "block";
	ob("are4").title = "5: Onxref Nezf, Oynol".rot13();
	document.clue.here.value += "\nPbeerpg: Sbkuhagre, Raqreol\n\n5: Nsgre fjvzzvat vs jr unq gur qbhtu".rot13();
break;

case 5:
	ob("spot4").style.left = "644px";
	ob("map4").style.display = "none";
	ob("map5").style.display = "block";
	ob("are6").title = "6: Envyjnl, Pbhagrfgubecr".rot13();
	document.clue.here.value += "\nPbeerpg: Onxref Nezf, Oynol\n\n6: Bar bs Qnir'f genvarq enyyl pyhrf".rot13();
break;

case 6:
	ob("spot5").style.left = "700px";
	ob("map5").style.display = "none";
	ob("map6").style.display = "block";
	ob("are6").title = "7: Oebhtugba Nfgyrl olcnff pebffebnq".rot13();
	document.clue.here.value += "\nPbeerpg: Envyjnl, Pbhagrfgubecr\n\n7: Gur pbzzvggrr fgnegrq trggvat ohfgrq urer".rot13();
break;

case 7:
	ob("spot6").style.left = "243px";
	ob("map6").style.display = "none";
	ob("map7").style.display = "block";
	ob("are7").title = "8: Genafcbeg pnsr, O4114".rot13();
	document.clue.here.value += "\nPbeerpg: Oebhtugba Nfgyrl olcnff pebffebnq\n\n8: Jurer jr uryq n pbasrerapr bs pyhof".rot13();
break;

case 8:
	document.clue.here.value += "\nPbeerpg: Genafcbeg pnsr, O4114\n\n".rot13();
	ob("spot7").style.left = "68px";
	ob("map7").style.display = "none";
	deleteLocal();
	var endtime = new Date();
	var endindex = endtime.getTime();
	endindex = Math.floor(endindex/1000);
	var tottime = endindex - startindex;
	var ttsec = tottime % 60;
	var ttmin = Math.floor(tottime/60)%60;
	var tthrs = Math.floor(tottime/3600);
	var rallytime = tthrs + "hrs " + ttmin + "mins " + ttsec + "secs";
	document.clue.here.value += "\n\nRally Completed in " + rallytime ;
	var faddr = "../forms/formtt.htm?" + tottime;
	WindowOpen(faddr,500,460);
break;

default:
	document.clue.here.value = "Oops! Something\'s gone wrong.";
break;

	}

document.clue.here.scrollTop = document.clue.here.scrollHeight;
//DBug.value += "\n" + checkpoint + " " + areas[0].coords ;
}

//=====================================================
//subroutine library

if (!localStorage) alert("You need to complete the whole Table Top Rally without leaving the page.");

//-----------------------------------------------------
function ob(id) {return document.getElementById(id); }
//-----------------------------------------------------
function writeLocal() {
if (!localStorage || checkpoint == 0 || checkpoint == 8) {
	alert("Start from the beginning when you return to this page.");
	} else {
	var endtime = new Date();
	var endindex = endtime.getTime();
	endindex = Math.floor(endindex/1000);
	var tottime = (endindex - startindex) + "";
	checkpoint = checkpoint + "";

	var ldata = [];
	ldata.push(tottime);
	ldata.push(checkpoint);

	localStorage["ttrally"] = ldata.join("|");
	alert("You have not completed the rally.\nYou will continue from checkpoint " + (checkpoint*1+1) + "\nwhen you return to this page.");
	}
}
//-----------------------------------------------------
function deleteLocal() {
localStorage.removeItem("ttrally") ;
}
//-----------------------------------------------------
function readLocal() {
document.clue.here.value = "1: Start at the present club.";
var msg = "Starting from scratch";
if (localStorage) {
	var ldata = localStorage.getItem("ttrally").split("|");
	if (ldata) {
		lastindex = ldata[0]*1;
		var savepoint = ldata[1]*1;
		for (var x=0;x<savepoint;x++) ttrally();
		msg = "Continue: Find checkpoint " + (savepoint+1);
		} 
	}	
alert(msg);
}
//-----------------------------------------------------


