
$.extend(Site,{
	Map: {
	
		mapList: [],
		geocoder: new google.maps.Geocoder(),
		defaultOptions: {
			zoom: 13,
			disableDefaultUI: true,
			navigationControl: true,
			mapTypeId: 	google.maps.MapTypeId.ROADMAP
		},
		
		create: function(idDiv,addressCenter,infoWindowString){
			var map = new google.maps.Map(document.getElementById(idDiv),this.defaultOptions); 
			this.mapList[idDiv] = map;
			if((typeof(addressCenter) != "undefined") && (typeof(infoWindowString) != "undefined")){ 
				Site.Map.addAddress(idDiv,addressCenter,infoWindowString,true);
			}	
		},
		
		addAddress: function(idDiv,address,infoWindowString,isCenter){
			var map = this.mapList[idDiv];
			this.geocoder.geocode({ 'address': address}, function(results, status){
				if (status == google.maps.GeocoderStatus.OK) {
					var latLng = results[0].geometry.location;
					if( (typeof(isCenter) != "undefined") && isCenter){
						map.setOptions({ center: latLng });
					}
					var marker = new google.maps.Marker({
					    position: 	latLng, 
					    map: 		map, 
					    draggable:	false
					});
					if( (typeof(infoWindowString) != "undefined") ){
						Site.Map.setInfoWindow(idDiv,marker,infoWindowString)
					}
			    } else {
			    	Shin.alert('error','Google Maps','This address is unknow. Please contact us at <a href="mailto:webmaster@z6creation.net">webmaster@z6creation.net</a>');
			    	return false;
			    }
			});
		},
		
		setOptions: function(idDiv,options){
			this.mapList[idDiv].setOptions(options);
		},
		
		setInfoWindow: function(idDiv,marker,contentString){
			var map = this.mapList[idDiv];
			var infowindow = new google.maps.InfoWindow({
			    content: contentString
			});
			google.maps.event.addListener(marker, 'click', function() {
				infowindow.open(map,marker);
			});
		}
		
	}
});
