

;var GoogleMaps = (function(window, document, $, undefined) {
	
	'use strict';
	
	var DOM = {
		conatainer : '.googlemaps'
	},
	
	_ = {
		setMap : function (e, options) {
			var map = new google.maps.Map(document.getElementById(e.id), options); 
			var marker = new google.maps.Marker({
				map: map,
				position: options.center
		    });
		}
	};

	return {
		
		init : $(window).load( function () {
			
			$(DOM.conatainer).each( function (i,e) {
				
				var data = $(e).data().googlemaps,
					latlng,
					lat = data.latitude,
					lng = data.longitude;
					
				// console.log($(e).data());
				
				e.style.width  = data.width;
				e.style.height = data.height;
				
				// console.log(e.style.width, e.style.height);
				
				var options = {
					zoom			: window.parseInt(data.zoom) || 14,
					mapTypeId		: google.maps.MapTypeId.ROADMAP,
					zoomControl		: data.zoomControl,
					mapTypeControl	: data.mapTypeControl,
					streetViewControl : data.streetViewControl
			   };
			  
				if (!lat || !lng)
				{
					if (data.address !== false)
					{
						var geocoder = new google.maps.Geocoder();
						geocoder.geocode( { 'address': data.address }, function (results, status) {
							
							if (status == google.maps.GeocoderStatus.OK)
							{
								lat 	= results[0].geometry.location.lat();
								lng 	= results[0].geometry.location.lng();
								latlng 	= [lat, lng];
								
								options.center = new google.maps.LatLng(lat,lng);
								_.setMap(e, options);
							}
							else if (typeof Debug !== 'undefined')
							{
								Debug.error("Geocode for " + e.id + " was not successful for the following reason: " + status);
							};
						});
					} 
					else if (typeof Debug !== 'undefined') 
					{
						Debug.error("No LatLong or Address set for " + e.id);
					};
				} else {
					options.center = new google.maps.LatLng(lat,lng);
					_.setMap(e, options);
				};
			
			});
		})
	};

})(this, this.document, jQuery);
