var themap;

var bigIcon = new GIcon();
bigIcon.iconSize = new GSize(80, 52);
bigIcon.iconAnchor = new GPoint(40, 26);
bigIcon.infoWindowAnchor = new GPoint(40, 26);

var mediumIcon = new GIcon();
mediumIcon.iconSize = new GSize(50, 32);
mediumIcon.iconAnchor = new GPoint(25, 16);
mediumIcon.infoWindowAnchor = new GPoint(25, 16);

var smallIcon = new GIcon();
smallIcon.iconSize = new GSize(30, 19);
smallIcon.iconAnchor = new GPoint(15, 9);
smallIcon.infoWindowAnchor = new GPoint(15, 9);

var napoleon;
var bernadotte;
var davout;
var soult;
var lannes;
var murat;
var bessieres;
var vandamme;
var sthilaire;
var grenadier;
var friant;
var legrand;
var suchet;
var caffarelli;

var napPt = new Array(2);
napPt[0] = new GLatLng(49.15566415187021, 16.70145034790039);
napPt[1] = new GLatLng(49.14196561090204, 16.750717163085938);

var bernPt = new Array(2);
bernPt[0] = new GLatLng(49.18417191471276, 16.743850708007812);
bernPt[1] = new GLatLng(49.14454841243055, 16.798267364501953);

var davPt = new Array(2);
davPt[0] = new GLatLng(49.09702579370594, 16.655616760253906);
davPt[1] = new GLatLng(49.11388299706436, 16.693382263183594);

var souPt = new Array(2);
souPt[0] = new GLatLng(49.139719587107166, 16.706256866455078);
souPt[1] = new GLatLng(49.12275882199536, 16.756038665771484);

var lanPt = new Array(2);
lanPt[0] = new GLatLng(49.17872977122587, 16.75715446472168);
lanPt[1] = new GLatLng(49.19011831503412, 16.791229248046875);

var murPt = new Array(2);
murPt[0] = new GLatLng(49.16599169431055, 16.729516983032227);
murPt[1] = new GLatLng(49.16587944999166, 16.81783676147461);

var besPt = new Array(2);
besPt[0] = new GLatLng(49.1786175557849, 16.735525131225586);
besPt[1] = new GLatLng(49.14432382633713, 16.76959991455078);

var vanPt = new Array(2);
vanPt[0] = new GLatLng(49.1536432938359, 16.73543930053711);
vanPt[1] = new GLatLng(49.10837694043441, 16.76788330078125);

var sthPt = new Array(2);
sthPt[0] = new GLatLng(49.154429192867944, 16.72745704650879);
sthPt[1] = new GLatLng(49.118489636107526, 16.749000549316406);

var legrPt = new Array(2);
legrPt[0] = new GLatLng(49.122084764444836, 16.709518432617188);
legrPt[1] =  new GLatLng(49.119500792293046, 16.73046112060547);

var friPt = new Array(2);
friPt[0] = new GLatLng(49.0885950444746, 16.604461669921875);
friPt[1] = new GLatLng(49.11365827202097, 16.709861755371094);

var grenPt = new Array(2);
grenPt[0] = new GLatLng(49.17474596726841, 16.747026443481445);
grenPt[1] = new GLatLng(49.13309322385766, 16.752777099609375);

var suchPt = new Array(2);
suchPt[0] = new GLatLng(49.18417191471276, 16.763591766357422);
suchPt[1] = new GLatLng(49.19527876244063, 16.80685043334961);

var cafPt = new Array(2);
cafPt[0] = new GLatLng(49.17339925679931, 16.757068634033203);
cafPt[1] = new GLatLng(49.1843963201528, 16.808910369873047);

var kutusov;
var bagration;
var doctorov;
var kienmayer;
var langeron;
var kollowrat;
var constantine;
var przb;
var lichtenstein;
var buxhowden;

var bagrPt = new Array(2);
bagrPt[0] = new GLatLng(49.18417191471276, 16.839981079101562);
bagrPt[1] = new GLatLng(49.18843544405412, 16.84856414794922);

var langPt = new Array(2);
langPt[0] = new GLatLng(49.13938267475864, 16.78213119506836);
langPt[1] = new GLatLng(49.12287116402973, 16.816463470458984);

var lichPt = new Array(2);
lichPt[0] = new GLatLng(49.15779719035517, 16.859893798828125);
lichPt[1] = new GLatLng(49.14117951415229, 16.832942962646484);

var consPt = new Array(2);
consPt[0] = new GLatLng(49.14612048658428, 16.83980941772461);
consPt[1] = new GLatLng(49.147467939019485, 16.843242645263672);

var buxPt = new Array(2);
buxPt[0] = new GLatLng(49.121972420629, 16.791229248046875);
buxPt[1] = new GLatLng(49.104556052226336, 16.735610961914062);


var frenchLineMorning;
var alliedLineMorning;
var frenchLineAfternoon;
var alliedLineAfternoon1;
var alliedLineAfternoon2;


function loadMap()
{
	if(GBrowserIsCompatible())
	{
		themap = new GMap2(document.getElementById("map"));
		themap.enableDoubleClickZoom();
		themap.enableContinuousZoom();
		//themap.enableScrollWheelZoom();
		themap.addControl(new GLargeMapControl());		
		themap.addControl(new GHierarchicalMapTypeControl());
		themap.setCenter(new GLatLng(49.15005045376566, 16.758956909179688), 12);
		themap.setMapType(G_PHYSICAL_MAP);
		themap.addMapType(G_PHYSICAL_MAP);

		loadFrench();
		loadAllied();
		showHide();
		document.getElementById("beforeBattleRadio").checked = true;
	}
	else
	{
		alert("Your browser is not compatible with google maps.  Please update your browser to the latest version or get the newest release of a free browser such as Firefox or Opera.");
	}
}

function showHide()
{
	// this is only to get around a stupid firefox bug
	napoleon.showTooltip();
	napoleon.hideTooltip();
	bernadotte.showTooltip();
	bernadotte.hideTooltip();
	davout.showTooltip();
	davout.hideTooltip();
	soult.showTooltip();
	soult.hideTooltip();
	lannes.showTooltip();
	lannes.hideTooltip();
	murat.showTooltip();
	murat.hideTooltip();
	bessieres.showTooltip();
	bessieres.hideTooltip();
	vandamme.showTooltip();
	vandamme.hideTooltip();
	sthilaire.showTooltip();
	sthilaire.hideTooltip();
	grenadier.showTooltip();
	grenadier.hideTooltip();
	friant.showTooltip();
	friant.hideTooltip();
	legrand.showTooltip();
	legrand.hideTooltip();
	suchet.showTooltip();
	suchet.hideTooltip();
	caffarelli.showTooltip();
	caffarelli.hideTooltip();

	kutusov.showTooltip();
	kutusov.hideTooltip();
	bagration.showTooltip();
	bagration.hideTooltip();
	doctorov.showTooltip();
	doctorov.hideTooltip();
	kienmayer.showTooltip();
	kienmayer.hideTooltip();
	langeron.showTooltip();
	langeron.hideTooltip();
	kollowrat.showTooltip();
	kollowrat.hideTooltip();
	constantine.showTooltip();
	constantine.hideTooltip();
	przb.showTooltip();
	przb.hideTooltip();
	lichtenstein.showTooltip();
	lichtenstein.hideTooltip();
	buxhowden.showTooltip();
	buxhowden.hideTooltip();
}

function loadFrench()
{
	var napIcon = new GIcon(bigIcon);
	napIcon.image = "/static/images/maps/battles/corps.png";
	napoleon = new PdMarker(napPt[0], napIcon);
	napoleon.setTooltip("La Grande Armee<br>73,200<br>Emperor Napoleon<br><img src='/static/images/maps/officers/bonaparte.jpg' width=80 height=89/>");
	napoleon.setOpacity(85);
	themap.addOverlay(napoleon);

	var bernadotteIcon = new GIcon(mediumIcon);
	bernadotteIcon.image = "/static/images/maps/battles/icorps.png";
	bernadotte = new PdMarker(bernPt[0], bernadotteIcon);
	bernadotte.setTooltip("I Corps<br>13,000<br>Marshal Bernadotte<br><img src='/static/images/maps/officers/bernadotte.jpg' width=80 height=85/>");
	bernadotte.setOpacity(85);
	themap.addOverlay(bernadotte);

	var davoutIcon = new GIcon(mediumIcon);
	davoutIcon.image = "/static/images/maps/battles/iiicorps.png";
	davout = new PdMarker(davPt[0], davoutIcon);
	davout.setTooltip("III Corps<br>6,600<br>Marshal Davout<br><img src='/static/images/maps/officers/davout.jpg' width=80 height=97/>");
	davout.setOpacity(85);
	themap.addOverlay(davout);
		
	var soultIcon = new GIcon(mediumIcon);
	soultIcon.image = "/static/images/maps/battles/ivcorps.png";
	soult = new PdMarker(souPt[0], soultIcon);
	soult.setTooltip("IV Corps<br>23,600<br>Marshal Soult<br><img src='/static/images/maps/officers/soult.jpg' width=80 height=92/>");
	soult.setOpacity(85);
	themap.addOverlay(soult);

	var lannesIcon = new GIcon(mediumIcon);
	lannesIcon.image = "/static/images/maps/battles/vcorps.png";
	lannes = new PdMarker(lanPt[0], lannesIcon);
	lannes.setTooltip("V Corps<br>12,700<br>Marshal Lannes<br><img src='/static/images/maps/officers/lannes.jpg' width=80 height=105/>");
	lannes.setOpacity(85);
	themap.addOverlay(lannes);

	var muratIcon = new GIcon(mediumIcon);
	muratIcon.image = "/static/images/maps/battles/cavalry.png";
	murat = new PdMarker(murPt[0], muratIcon);
	murat.setTooltip("Cavalry Reserve<br>5,600<br>Marshal Murat<br><img src='/static/images/maps/officers/murat.jpg' width=80 height=88/>");
	murat.setOpacity(85);
	themap.addOverlay(murat);


	var divisionIcon = new GIcon(smallIcon);
	divisionIcon.image = "/static/images/maps/battles/corps.png";

	bessieres = new PdMarker(besPt[0], divisionIcon);
	bessieres.setTooltip("Imperial Guard<br>5,500<br>Marshal Bessieres<br><img src='/static/images/maps/officers/bessieres.jpg' width=80 height=89/>");
	bessieres.setOpacity(85);
	themap.addOverlay(bessieres);

	vandamme = new PdMarker(vanPt[0], divisionIcon);
	vandamme.setTooltip("Division Vandamme<br>IV Corps<br><img src='/static/images/maps/officers/vandamme.jpg' width=80 height=96/>");
	vandamme.setOpacity(85);
	themap.addOverlay(vandamme);

	sthilaire = new PdMarker(sthPt[0], divisionIcon);
	sthilaire.setTooltip("Division St. Hilaire<br>IV Corps");
	sthilaire.setOpacity(85);
	themap.addOverlay(sthilaire);

	grenadier = new PdMarker(grenPt[0], divisionIcon);
	grenadier.setTooltip("Grenadier Division<br>General Duroc<br><img src='/static/images/maps/officers/duroc.jpg' width=80 height=96/>");
	grenadier.setOpacity(85);
	themap.addOverlay(grenadier);

	friant = new PdMarker(friPt[0], divisionIcon);
	friant.setTooltip("Division Friant<br>III Corps<br><img src='/static/images/maps/officers/friant.jpg' width=80 height=94/>");
	friant.setOpacity(85);
	themap.addOverlay(friant);

	legrand = new PdMarker(legrPt[0], divisionIcon);
	legrand.setTooltip("Division Legrand<br>IV Corps<br><img src='/static/images/maps/officers/legrand.jpg' width=80 height=96/>");
	legrand.setOpacity(85);
	themap.addOverlay(legrand);

	suchet = new PdMarker(suchPt[0], divisionIcon);
	suchet.setTooltip("Division Suchet<br>V Corps<br><img src='/static/images/maps/officers/suchet.jpg' width=75 height=98/>");
	suchet.setOpacity(85);
	themap.addOverlay(suchet);

	caffarelli = new PdMarker(cafPt[0], divisionIcon);
	caffarelli.setTooltip("Division Cafarelli<br>V Corps");
	caffarelli.setOpacity(85);
	themap.addOverlay(caffarelli);


	var flineMorn = new Array(6);
	flineMorn[0] = new GLatLng(49.18770618218592, 16.772260665893555);
	flineMorn[1] = new GLatLng(49.167338606291075, 16.757583618164062);
	flineMorn[2] = new GLatLng(49.15218373398289, 16.735267639160156);
	flineMorn[3] = new GLatLng(49.13702422419125, 16.72565460205078);
	flineMorn[4] = new GLatLng(49.11377063466991, 16.725997924804688);
	flineMorn[5] = new GLatLng(49.10051008519475, 16.715869903564453);
	frenchLineMorning = new GPolyline(flineMorn, "#3322AA", 4, 0.5);
	themap.addOverlay(frenchLineMorning);

	var flineAft = new Array(6);
	flineAft[0] = new GLatLng(49.195727471557426, 16.809253692626953);
	flineAft[1] = new GLatLng(49.14915220303468, 16.823501586914062);
	flineAft[2] = new GLatLng(49.107140802916284, 16.77011489868164);
	flineAft[3] = new GLatLng(49.116130191506805, 16.739044189453125);
	flineAft[4] = new GLatLng(49.11590547664366, 16.71947479248047);
	flineAft[5] = new GLatLng(49.1037693622485, 16.70642852783203);
	frenchLineAfternoon = new GPolyline(flineAft, "#3322AA", 4, 0.5);
	themap.addOverlay(frenchLineAfternoon);
	frenchLineAfternoon.hide();
}

function loadAllied()
{
	var kutIcon = new GIcon(bigIcon);
	kutIcon.image = "/static/images/maps/battles/ecorps.png";
	kutusov = new PdMarker(new GLatLng(49.12888109184936, 16.86504364013672), kutIcon);
	kutusov.setTooltip("Russo-Austrian Army<br>85,400<br>General Kutusov<br><img src='/static/images/maps/officers/allied/kutusov.jpg' width=80 height=97 />");
	kutusov.setOpacity(85);
	themap.addOverlay(kutusov);

	var acorpsIcon = new GIcon(mediumIcon);
	acorpsIcon.image = "/static/images/maps/battles/ecorps.png";

	bagration = new PdMarker(bagrPt[0], acorpsIcon);
	bagration.setTooltip("Right Wing<br>17,600<br>General Bagration<br><img src='/static/images/maps/officers/allied/bagration.jpg' width=80 height=90 />");
	bagration.setOpacity(85);
	themap.addOverlay(bagration);

	langeron = new PdMarker(langPt[0], acorpsIcon);
	langeron.setTooltip("Second Column<br>11,700<br>General Langeron<br><img src='/static/images/maps/officers/allied/langeron.jpg' width=80 height=92 />");
	langeron.setOpacity(85);
	themap.addOverlay(langeron);

	przb = new PdMarker(new GLatLng(49.150499573024106, 16.802215576171875), acorpsIcon);
	przb.setTooltip("Third Column<br>10,000<br>General Przbyswski");
	przb.setOpacity(85);
	themap.addOverlay(przb);

	kollowrat = new PdMarker(new GLatLng(49.14174101310303, 16.810970306396484), acorpsIcon);
	kollowrat.setTooltip("Fourth Column<br>23,900<br>General Kollowrat");
	kollowrat.setOpacity(85);
	themap.addOverlay(kollowrat);		

	var cavIcon = new GIcon(smallIcon);
	cavIcon.image = "/static/images/maps/battles/ecavalry.png";

	lichtenstein = new PdMarker(lichPt[0], cavIcon);
	lichtenstein.setTooltip("Fifth Column<br>5,500<br>General Lichtenstein<br><img src='/static/images/maps/officers/allied/lichtenstein.jpg' width=80 height=86/>");
	lichtenstein.setOpacity(85);
	themap.addOverlay(lichtenstein);

	kienmayer = new PdMarker(new GLatLng(49.10927593019541, 16.755352020263672), cavIcon);
	kienmayer.setTooltip("Advance Guard<br>5,100<br>General Kienmayer<br><img src='/static/images/maps/officers/allied/kienmayer.jpg' width=80 height=89 />");
	kienmayer.setOpacity(85);
	themap.addOverlay(kienmayer);


	var divisionIcon = new GIcon(smallIcon);
	divisionIcon.image = "/static/images/maps/battles/ecorps.png";

	doctorov = new PdMarker(new GLatLng(49.11208516821251, 16.768741607666016
), divisionIcon);
	doctorov.setTooltip("First Column<br>8,500<br>General Doctorov<br><img src='/static/images/maps/officers/allied/doctorov.jpg' width=80 height=87 />");
	doctorov.setOpacity(85);
	themap.addOverlay(doctorov);

	constantine = new PdMarker(consPt[0], divisionIcon);
	constantine.setTooltip("Russian Imperial Guard<br>8,500<br>Grand Duke Constantine<br><img src='/static/images/maps/officers/allied/constantine.jpg' width=80 height=91 />");
	constantine.setOpacity(85);
	themap.addOverlay(constantine);

	buxhowden = new PdMarker(buxPt[0], acorpsIcon);
	buxhowden.setTooltip("Left Wing<br>General Buxhowden");
	buxhowden.setOpacity(85);
	themap.addOverlay(buxhowden);


	var alineMorn = new Array(3);
	alineMorn[0] = new GLatLng(49.18417191471276, 16.809082031250);
	alineMorn[1] = new GLatLng(49.16599169431055, 16.809768676757812);
	alineMorn[2] = new GLatLng(49.10871406350364, 16.74762725830078);
	alliedLineMorning = new GPolyline(alineMorn, "#CC1100", 4, 0.5);
	themap.addOverlay(alliedLineMorning);

	var alineAft1 = new Array(2);
	alineAft1[0] = new GLatLng(49.19583964820061, 16.824016571044922);
	alineAft1[1] = new GLatLng(49.16587944999166, 16.844615936279297);
	alliedLineAfternoon1 = new GPolyline(alineAft1, "#CC1100", 4, 0.5);
	themap.addOverlay(alliedLineAfternoon1);
	alliedLineAfternoon1.hide();
	
	var alineAft2 = new Array(4);
	alineAft2[0] = new GLatLng(49.10107204478571, 16.744537353515625);
	alineAft2[1] = new GLatLng(49.10983779052439, 16.742477416992188);
	alineAft2[2] = new GLatLng(49.10893881094389, 16.728057861328125);
	alineAft2[3] = new GLatLng(49.10287027271691, 16.722564697265625);
	alliedLineAfternoon2 = new GPolyline(alineAft2, "#CC1100", 4, 0.5);
	themap.addOverlay(alliedLineAfternoon2);
	alliedLineAfternoon2.hide();
}

function doBefore()
{
	frenchLineMorning.show();
	alliedLineMorning.show();
	frenchLineAfternoon.hide();
	alliedLineAfternoon1.hide();
	alliedLineAfternoon2.hide();
	napoleon.setPoint(napPt[0]);
	bernadotte.setPoint(bernPt[0]);
	davout.setPoint(davPt[0]);
	soult.setPoint(souPt[0]);
	lannes.setPoint(lanPt[0]);
	murat.setPoint(murPt[0]);
	bessieres.setPoint(besPt[0]);
	vandamme.setPoint(vanPt[0]);
	sthilaire.setPoint(sthPt[0]);
	legrand.setPoint(legrPt[0]);
	friant.setPoint(friPt[0]);
	grenadier.setPoint(grenPt[0]);
	suchet.setPoint(suchPt[0]);
	caffarelli.setPoint(cafPt[0]);

	bagration.setPoint(bagrPt[0]);	
	langeron.setPoint(langPt[0]);
	lichtenstein.setPoint(lichPt[0]);
	constantine.setPoint(consPt[0]);
	buxhowden.setPoint(buxPt[0]);

	kutusov.show();
	doctorov.show();
	przb.show();
	kienmayer.show();
	kollowrat.show();
}


function doAttack()
{
	frenchLineMorning.hide();
	alliedLineMorning.hide();
	frenchLineAfternoon.show();
	alliedLineAfternoon1.show();
	alliedLineAfternoon2.show();
	napoleon.setPoint(napPt[1]);
	bernadotte.setPoint(bernPt[1]);
	davout.setPoint(davPt[1]);
	soult.setPoint(souPt[1]);
	lannes.setPoint(lanPt[1]);
	murat.setPoint(murPt[1]);
	bessieres.setPoint(besPt[1]);
	vandamme.setPoint(vanPt[1]);
	sthilaire.setPoint(sthPt[1]);
	legrand.setPoint(legrPt[1]);
	friant.setPoint(friPt[1]);
	grenadier.setPoint(grenPt[1]);
	suchet.setPoint(suchPt[1]);
	caffarelli.setPoint(cafPt[1]);

	bagration.setPoint(bagrPt[1]);	
	langeron.setPoint(langPt[1]);
	lichtenstein.setPoint(lichPt[1]);
	constantine.setPoint(consPt[1]);
	buxhowden.setPoint(buxPt[1]);

	kutusov.hide();
	doctorov.hide();
	przb.hide();
	kienmayer.hide();
	kollowrat.hide();
}

