(function($) {
  $.fn.maps = function(options) {
    // build main options before element iteration
    var opts = $.extend({}, $.fn.maps.defaults, options);
	
    // Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	
    // iterate and reformat each matched element
    return this.each(function() {
	  var $this = $(this);
      var options = $.metadata ? $.extend({}, opts, $this.metadata()) : opts; 
	  
	  if (GBrowserIsCompatible())
	  {
			var map = new GMap2(this);
			$this.data('maps.gmap2', map);
			
			var point = new GLatLng(parseFloat(options.latitude), parseFloat(options.longitude));
			
			if(options.north)
			{
				var llbounds = new GLatLngBounds( 
							new GLatLng(parseFloat(options.south), parseFloat(options.west)), 
							new GLatLng(parseFloat(options.north), parseFloat(options.east))); 
				map.setCenter(point, map.getBoundsZoomLevel(llbounds)); 
			} else {
				map.setCenter(point, parseInt(options.zoom));
			}
			
			map.addControl(new GLargeMapControl ());
			map.addControl(new GMapTypeControl());
			
			map.enableScrollWheelZoom();
	/*			var bounds = <?= Zend_Json_Encoder::encode($this->prmLocation['LatLonBox']);?>;
			
				if (bounds) { 
				  var llbounds = new GLatLngBounds( 
								new GLatLng(bounds.south, bounds.west), 
								new GLatLng(bounds.north, bounds.east)); 
				  map.setCenter(point, map.getBoundsZoomLevel(llbounds)); 
				} 
				
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
			
				// Create a base icon for all of our markers that specifies the
				// shadow, icon dimensions, etc.
				var baseIcon = new GIcon(G_DEFAULT_ICON);
				baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
				baseIcon.iconSize = new GSize(20, 34);
				baseIcon.shadowSize = new GSize(37, 34);
				baseIcon.iconAnchor = new GPoint(9, 34);
				baseIcon.infoWindowAnchor = new GPoint(9, 2);
			
				// Creates a marker whose info window displays the letter corresponding
				// to the given index.
				function createMarker(point, index) {
				  // Create a lettered icon for this point using our icon class
				  var letter = String.fromCharCode("A".charCodeAt(0) + index);
				  var letteredIcon = new GIcon(baseIcon);
				  letteredIcon.image = "http://lab2.student.utwente.nl/image/marker-flogs.png";
			
				  // Set up our GMarkerOptions object
				  markerOptions = { icon:letteredIcon, draggable: true };
				  var marker = new GMarker(point, markerOptions);
			
				  GEvent.addListener(marker, "click", function() {
					 
					marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
				  });
				  return marker;*/
		}

    });
  };

  $.fn.getMap = function() {
	  return this.data('maps.gmap2');
  };

  $.fn.maps.defaults = {
    latitude: 4.33,
    longitude: 4.33,
	zoom: 3
  };
})(jQuery);

$(document).ready(function(){
    $(".maps").maps();
});
