$(function(){
	(function($) {  
		$.fn.googleMap = function(options) {
			var defaults = {
				address: false,
				LatLng: [0, 0],
				zoom: 8, //higher number means zoom in further
				icon: false,
				mapTypeId: google.maps.MapTypeId.ROADMAP 
				//mapTypeId: google.maps.MapTypeId.SATELLITE 
				//mapTypeId: google.maps.MapTypeId.HYBRID 
				//mapTypeId: google.maps.MapTypeId.TERRAIN 
			}
			var options = $.extend(defaults, options);
			return this.each(function() {
				var obj = $(this)[0];
				var map;
				var mapLatLng = new google.maps.LatLng(options.LatLng[0],options.LatLng[1]);
				var mapOptions = {
					zoom: options.zoom,
					center: mapLatLng,
					mapTypeId:options.mapTypeId
				}
				var map = new google.maps.Map(obj,mapOptions);
				if(options.address){
					var geocoder = new google.maps.Geocoder();	
					geocoder.geocode( { 'address': options.address}, function(results, status) {
						if (status == google.maps.GeocoderStatus.OK) {
							if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
								map.setCenter(results[0].geometry.location);
								if(options.icon){
									var marker = new google.maps.Marker({
										map: map, 
										position: results[0].geometry.location,
										icon:options.icon
									})
								} else {
									var marker = new google.maps.Marker({
										map: map, 
										position: results[0].geometry.location
									});
								}
							} else {
								alert("No results found");
							}
						} else {
							alert("Geocode was not successful for the following reason: " + status);
						}
					});
				}
			});
		}
	})(jQuery);
})


