// JavaScript Document
// Office Locations
var projectLocations = new Array();
projectLocations[0] = new Array(8.979139, 38.798695, 'addis', 'purple-marker.png');
projectLocations[1] = new Array(43.6637907, 7.2128557, 'aeroport', 'purple-marker.png');
projectLocations[2] = new Array(46.2307636, 14.4549459, 'aerodrom', 'purple-marker.png');
projectLocations[3] = new Array(42.745153, -73.809543, 'albany', 'purple-marker.png');
projectLocations[4] = new Array(31.5213889, 74.4025, 'allama', 'purple-marker.png');
projectLocations[5] = new Array(36.922395, 30.808439, 'antalya', 'purple-marker.png');
projectLocations[6] = new Array(50.503887, 4.469936, 'belgian', 'orange-marker.png');
projectLocations[7] = new Array(-33.9665752, 18.5943834, 'cape', 'purple-marker.png');
projectLocations[8] = new Array(-34.8383333, -56.0308333, 'carrasco', 'purple-marker.png');
projectLocations[9] = new Array(19.090479, 72.867127, 'chhatrapati', 'purple-marker.png');
projectLocations[10] = new Array(36.114646, -115.172816, 'clark', 'green-marker.png');
projectLocations[11] = new Array(43.1397222, -89.3375, 'dane', 'purple-marker.png');
projectLocations[12] = new Array(55.4086111, 37.9061111, 'domodedovo', 'purple-marker.png');
projectLocations[13] = new Array(55.0441667, -8.3411111, 'donegal', 'purple-marker.png');
projectLocations[14] = new Array(25.254032, 55.365301, 'dubai-int', 'purple-marker.png');
projectLocations[15] = new Array(25.271139, 55.307485, 'dubai-metro', 'orange-marker.png');
projectLocations[16] = new Array(36.0919444, 10.4138889, 'enfidha', 'purple-marker.png');
projectLocations[17] = new Array(13.0744444, -59.4922222, 'grantley', 'purple-marker.png');
projectLocations[18] = new Array(49.4322933, -2.5963176, 'guernsey', 'purple-marker.png');
projectLocations[19] = new Array(44.885059, -63.514854, 'halifax', 'purple-marker.png');
projectLocations[20] = new Array(-17.9318056, 31.0928472, 'harare', 'purple-marker.png');
projectLocations[21] = new Array(40.4675, 50.0466667, 'heydar', 'purple-marker.png');
projectLocations[22] = new Array(49.2049054, -2.1939994, 'jersey', 'purple-marker.png');
projectLocations[23] = new Array(40.6444122, -73.782745, 'jfk', 'purple-marker.png');
projectLocations[24] = new Array(-12.0219444, -77.1144444, 'jorge', 'purple-marker.png');
projectLocations[25] = new Array(21.6794444, 39.1566667, 'king', 'purple-marker.png');
projectLocations[26] = new Array(36.0855096, -115.1499576, 'mccarran', 'purple-marker.png');
projectLocations[27] = new Array(15.5470278, -61.3, 'melville', 'purple-marker.png');
projectLocations[28] = new Array(25.796549, -80.275614, 'miami', 'purple-marker.png');
projectLocations[29] = new Array(35.7580556, 10.7547222, 'monastir', 'purple-marker.png');
projectLocations[30] = new Array(37.366695, -121.925906, 'norman', 'purple-marker.png');
projectLocations[31] = new Array(19.2927778, -81.3576944, 'owen', 'purple-marker.png');
projectLocations[32] = new Array(45.5708333, -84.7966667, 'pellston', 'purple-marker.png');
projectLocations[33] = new Array(45.58961, -122.592121, 'portland', 'purple-marker.png');
projectLocations[34] = new Array(12.503333, -70.014725, 'reina', 'purple-marker.png');
projectLocations[35] = new Array(39.504769, -119.775739, 'reno-tahoe', 'purple-marker.png');
projectLocations[36] = new Array(36.7548157, -107.9743611, 'reno', 'green-marker.png');
projectLocations[37] = new Array(40.785596, -111.980673, 'salt', 'purple-marker.png');
projectLocations[38] = new Array(37.615223, -122.389979, 'san', 'purple-marker.png');
projectLocations[39] = new Array(18.5036111, -77.9133333, 'sangster', 'purple-marker.png');
projectLocations[40] = new Array(47.44443, -122.300497, 'seattle', 'purple-marker.png');
projectLocations[41] = new Array(34.7177778, 10.6908333, 'sfax', 'purple-marker.png');
projectLocations[42] = new Array(1.3568, 103.9891, 'singapore', 'purple-marker.png');
projectLocations[43] = new Array(-24.555834, 25.918888, 'sir', 'purple-marker.png');
projectLocations[44] = new Array(47.6186111, -52.7525, 'st', 'purple-marker.png');
projectLocations[45] = new Array(-33.935723, 151.166246, 'sydney', 'purple-marker.png');
projectLocations[46] = new Array(43.6616667, -79.395, 'toronto', 'green-marker.png');
projectLocations[47] = new Array(53.3636413, -6.2753186, 'translink', 'orange-marker.png');
projectLocations[48] = new Array(32.6694444, 13.1566667, 'tripoli', 'purple-marker.png');
projectLocations[49] = new Array(36.8511111, 10.2272222, 'tunis', 'purple-marker.png');
projectLocations[50] = new Array(17.1366667, -61.7927778, 'vc', 'purple-marker.png');
projectLocations[51] = new Array(17.2056778, -62.5898694, 'vance', 'purple-marker.png');
projectLocations[52] = new Array(40.1472222, 44.3958333, 'zvartnots', 'purple-marker.png');

// Icon
var ukIcon;
ukIcon = new GIcon();
ukIcon.iconSize = new GSize(160, 96);
ukIcon.iconAnchor = new GPoint(87, 113);

// Icon
var icon;
icon = new GIcon();
icon.iconSize = new GSize(32, 35);
icon.iconAnchor = new GPoint(17, 30);

var map;

function initialize(urlPath) {

    if (GBrowserIsCompatible()) {
        var imgPath = urlPath + "images/maps/";
    
        map = new GMap2(document.getElementById("google-map"));
        map.setMapType(G_NORMAL_MAP);
        map.setCenter(new GLatLng(47.040182144806664, -72.44140625), 3);
        
        var mapTypeControl = new GMapTypeControl();
        var mapLargeControl = new GLargeMapControl3D();
        var mapScaleControl = new GScaleControl();
        
        var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
        var rightCentre = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,130));
        var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(100,10));
        
        map.addControl(mapLargeControl, rightCentre);
        map.addControl(mapScaleControl, bottomLeft);
        map.addControl(new GMapTypeControl(), topRight);
        
        var markers = [];
        for (var i = 0; i < projectLocations.length; i++) {
            var point = new GPoint(projectLocations[i][1], projectLocations[i][0]);
            icon.image = imgPath + projectLocations[i][3];
            marker = new GMarker(point, icon);
            map.addOverlay(marker);
            markers[i] = marker;
        }
        
        $(markers).each(function(i,marker){
			$("<li />")
				.html("Point "+i)
				.click(function(){
					displayPoint(marker, i);
				})
				.appendTo("#list");
			
			GEvent.addListener(marker, "click", function(){
				displayPoint(marker, i);
			});
		});
		
		$(".popup").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
		
		function displayPoint(marker, index){
			$(".popup").hide();
			
			$("#" + projectLocations[index][2] + " a.close").click(function() {
                $("#" + projectLocations[index][2]).fadeOut();
            });
			
			var moveEnd = GEvent.addListener(map, "moveend", function(){
				var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
				$("#" + projectLocations[index][2])
					.fadeIn()
					.css({ top:markerOffset.y - 160, left:markerOffset.x - 475 });
			
				GEvent.removeListener(moveEnd);
			});
			map.panTo(new GLatLng(marker.getLatLng().lat(), marker.getLatLng().lng()));
		}
		
		// UK Marker
		var ukPoint = new GPoint(-0.966796875, 53.27835301753182);
        ukIcon.image = urlPath + "images/maps/uk-marker.png";
        ukMarker = new GMarker(ukPoint, ukIcon);
        map.addOverlay(ukMarker);
        
        GEvent.addListener(ukMarker, "click", function(){
			window.location.replace("/recent-projects-uk.aspx");
		});
    }
}
