// Javascript tests
// Playing with Google Maps
// by Josef Spidlen

var map = null;
var already_focused = false;
var points = new Array(4);
points[0] = new GLatLng(49.65,-53);             // World
points[1] = new GLatLng(49.2603,-122.89038);	// Vancouver (Coquitlam)
points[2] = new GLatLng(49.262468,-123.119571); // BCCRC
points[3] = new GLatLng(50.106413, 14.582982);  // Prague

var markers = new Array(4);
for(var i = 1; i <= 3; i++) {
  markers[i] = new GMarker(points[i]);
}

function load() {
	if(GBrowserIsCompatible()) {
        if(map == null) {
        	map = new GMap2(document.getElementById("map"));
        	map.setCenter(points[0], 2);
        	map.addControl(new GSmallMapControl());
        	map.addControl(new GMapTypeControl());
        	GEvent.addListener(markers[1], "click", function() { 
        		markers[1].openInfoWindowHtml("Josef Spidlen<br>#301-2446 Granville Street<br>Vancouver, BC<br>V6H 3G6, Canada"); });
        	GEvent.addListener(markers[2], "click", function() { 
        		markers[2].openInfoWindowHtml("Terry Fox Laboratory<br>BC Cancer Research Centre<br>675 West 10th Avenue<br>Vancouver, BC<br>V5Z 1L3, Canada"); });
        	GEvent.addListener(markers[3], "click", function() { 
        		markers[3].openInfoWindowHtml("Josef Spidlen<br>Bryksova 761/42<br>Praha 9 - Cerny Most<br>198 00, The Czech Republic"); });
        	map.addOverlay(markers[1]);
        	map.addOverlay(markers[2]);
        	map.addOverlay(markers[3]);
      	}
	} else {
		throw "Unsupported web browser!";
	}
}

function focus(i) {
	if((GBrowserIsCompatible()) && (i >= 0) && (i <=3)) {
		if(already_focused) {
			map.setCenter(points[i]);
		} else {
       		map.setCenter(points[i], i > 0 ? 15 : 2);
       		already_focused = true;
		}
	} else {
		throw "Wrong focus!";
	}
}

function focus_vancouver() {
	focus(1);
}

function focus_bccrc() {
	focus(2);
}

function focus_prague() {
	focus(3);
}

