(function($){
		$.fn.gmap = function(method, options) {
			if (typeof options == 'function') { //if the options parameter is a function, reset the options object
				var attach = options;
				options = null;
			}

			var methods = {
				init: function(){
					var grantee = $(this)
					opts.center = new google.maps.LatLng(opts.center[0],opts.center[1])
					opts.mapTypeId = google.maps.MapTypeId[opts.mapTypeId.toUpperCase()]
					//console.log(opts)
					var mapDiv = document.getElementById(opts.mapDivId)
					$.fn.gmap.mapObject = new google.maps.Map(mapDiv, opts)
					google.maps.event.addListener($.fn.gmap.mapObject, "tilesloaded", function(){ //mapload callback
							opts.onLoad.call(grantee);
						})
					//console.log('init')
					return this
				},
				add: function(){
					if ($.fn.gmap.mapObject == null) methods['init']();
					return this.each(function(){ // for each grantee 
						var point = new google.maps.LatLng($(this).find('span.lat').text(),$(this).find('span.long').text(),1) // grab the lat and long of the location
                        var icon = new google.maps.MarkerImage(opts.iconUrl)
   						var marker = new google.maps.Marker({
							position: point, 
							icon: icon,
							map: $.fn.gmap.mapObject,
							zIndex: opts.zIndex,
							visible: true
						})
						$(this).data('marker', marker)
					})
				},
				remove: function(){
					return this.each(function(){ // for each grantee 
						var marker = $(this).data('marker').setMap(null)
						$(this).removeData('marker')
					})
				},
				show: function(){
					return this.each(function(){
						var marker = $(this).data('marker').setVisible(true)
					})
				},
				hide: function(){
					return this.each(function(){
						var marker = $(this).data('marker').setVisible(false)
					})
				},
				toggle: function(){
					return this.each(function(){
						($(this).data('marker').getVisible()) ? $(this).gmap('hide') : $(this).gmap('show')
					})
				},
				mouseover:  function(){
					return this.each(function(){
						var marker = $(this).data('marker')
						var grantee = $(this)
						google.maps.event.addListener(marker, "mouseover", function(){
							attach.call(grantee)
						})
					})
				},
				click:  function(){
					return this.each(function(){
						var marker = $(this).data('marker')
						var grantee = $(this)
						google.maps.event.addListener(marker, "click", function(){
							attach.call(grantee);
						})
					})
				}
			}
			
			if ((typeof arguments[0] != 'string') || !($.isFunction(methods[method]))){
				throw('Error: gmap function requires a valid argument of type string. Try "init".')
			}
			else {
				var opts = $.extend($.fn.gmap.defaults, options);
				methods[method].call(this)
			}
			return this
		}
	
	$.fn.gmap.defaults = { //set default options
				mapDivId: 'map',
				center: [2.37,16.06],
				zoom: 2,
				mapTypeId: 'satellite',
				mapTypeControl: false, 
				navigationControl: true
			}
			
	})(jQuery)
	
	function addDonateListener(){
		$('img.donate_arrow').click(function(){
			var donation = $('#donate_field').val()
			var donation = donation.match(/\d+\.?/)
			var donation = donation.toString()
			var donation = donation.replace(/\./, '')
			location.href = 'https://secure.ajws.org/site/Donation2?df_id=2720&2720.donation=form1&set.DonationLevel=3808&set.Value=' + donation
			   return false;
		})
	}

