//  
//  ~/include/scripts/gmap.js
//  

var GMap = {
	APIKey:		'ABQIAAAAyZiqlEAb7KkrcFPsjnF9DRR7_m1za6nNNjT2I2_isZdZH7gKtxTTDZ8qjDRDXeE5kOuXxFuZn0OE_Q',
	Items:		[],
	Groups:		['golf','stay'],
	Lat:		false,
	Lng:		false,
	
	Item:		function(itemid, itemgroup,itemname,itemaddress,latitude,longitude){
		this.ID		= itemid;
		this.Group	= itemgroup;
		this.Name	= itemname;
		this.Address	= itemaddress;
		this.Latitude	= latitude;
		this.Longitude	= longitude;
	},
	
	DisplayMap:	function(spoint){
		switch(spoint){
			case 'north_okanagan':
				GMap.Lat = '50.449793';
				GMap.Lng = '-119.202351';
				GMap.Zoom = 9;
			break;
			case 'central_okanagan':
				GMap.Lat = '49.966667';
				GMap.Lng = '-119.266667';
				GMap.Zoom = 9;
			break;
			case 'south_okanagan':
				GMap.Lat = '49.299765';
				GMap.Lng = '-119.585692';
				GMap.Zoom = 9;
			break;
			default:
				GMap.Lat = GMap.Items[0].Latitude;
				GMap.Lng = GMap.Items[0].Longitude;
				GMap.Zoom = 12;
		}
		if(google.maps.BrowserIsCompatible()){
			GMap.GeoCoder	= new google.maps.ClientGeocoder();
			GMap.Map	= new google.maps.Map2(document.getElementById("gmap"));
			
			GMap.Map.setCenter(new google.maps.LatLng(GMap.Lat, GMap.Lng), GMap.Zoom);
			GMap.Map.addControl(new google.maps.MapTypeControl());
			GMap.Map.addControl(new google.maps.LargeMapControl());
		}
	},
	
	DisplayItem:	function(item,openinfo){
		var point  = new google.maps.LatLng(item.Latitude,item.Longitude);
		var marker = new google.maps.Marker(point);
		if(openinfo){
			GMap.Map.openInfoWindowHtml(point,"<strong>"+item.Name+"</strong><br />"+item.Address);
		}
		google.maps.Event.addListener(marker, "click", function(){
			GMap.Map.openInfoWindowHtml(point,"<strong>"+item.Name+"</strong><br />"+item.Address);
		});
		GMap.Map.addOverlay(marker);
	},
	
	DisplayIcons:	function(group){
		GMap.Map.clearOverlays();
		for(i=0; i<GMap.Items.length; i++){
			if((!group) || ((group) && (GMap.Items[i].Group == group))){
				GMap.DisplayItem(GMap.Items[i]);
			}
		}
	}
}
