var GoogleMaps = {
	load : function (id) {
		if (GBrowserIsCompatible()) {
			this.map = new GMap2(document.getElementById(id));
			//this.directionsPanel = document.getElementById("directions");;
			this.map.addControl( new GSmallMapControl() );
			this.identica();
		}
	},
	identica : function () {
		var point = GoogleMapPoint.get('identicaNew');
		var p = new GLatLng(parseFloat(point.x),parseFloat(point.y));
		this.map.setCenter(p, 15);
		this.map.addOverlay(new GMarker(p, GoogleMapPoint.icon()));
		//this.map.addOverlay(new GMarker(p));
	},
	showDirections : function (from, to) {
		this.destroy();
		directionsPanel = document.getElementById("directions");
		this.directions = new GDirections(this.map, directionsPanel);
		var searchFrom = GoogleMapPoint.get(from);
		var searchTo   = GoogleMapPoint.get(to);		
		var searchStr  = searchFrom.x+','+searchFrom.y +' to '+searchTo.x+','+searchTo.y;
		this.directions.load(searchStr, {travelMode:G_TRAVEL_MODE_WALKING});		
		GEvent.addListener(this.directions, "addoverlay", function() { 
			//GoogleMaps.map.setZoom(14);
		});
		$("#directions").hide();
	},
	destroy : function () {
		this.map.clearOverlays();
	}
}

var GoogleMapPoint = {
	get : function (key) {
		switch (key){
			case 'identica' 			: return {x:51.51800,y:-0.13160, s:'W1T 7QX', z:'15'}; 													break; 
			case 'identicaNew' 			: return {x:51.520440,y:-0.141004, s:'W1W 6XH', z:'6'}; 												break; 
			case 'tottenhamCourtRoad' 	: return {x:51.51649,y:-0.13085, s:'Tottenham+Court+Road+station+(Tottenham+Court+Road)', z:'6'};  		break;
			case 'goodgeStreet'	 		: return {x:51.52039,y:-0.13467, s:'Goodge+Street+station+(Goodge+Street)', z:'6'};  					break;
			case 'euston'	 			: return {x:51.52863,y:-0.13345, s:'Euston+station+(Euston)', z:''};  									break;
			case 'charingCross'	 		: return {x:51.508744,y:-0.12511, s:'Charing+Cross+station+(Charing+Cross)', z:'15'};  					break;
		}
	},
	icon : function () {
		var icon = new GIcon();
		icon.image = "/wp-content/themes/identica/images/googlepin/IdenticaPIN.png";
		icon.shadow = "/wp-content/themes/identica/images/googlepin/shadow.png";
		icon.iconSize = new GSize(93, 47);
		icon.shadowSize = new GSize(117, 47);
		icon.iconAnchor = new GPoint(0, 50); // identica New Location
		//icon.iconAnchor = new GPoint(0, 40);
		icon.infoWindowAnchor = new GPoint(0, 0);
		icon.infoShadowAnchor = new GPoint(0, 0);
		return icon;
	}
}
