(function($){


	$.jmap = $.jmap || {};
	$.jmap.store = {};
	$.jmap.gmarkers = {};
	$.jmap.gmarkercount = 0;
	
	
	$.jmap.JDetails = {
		name: "Obj-X Labs Google Maps Plugin",
		description: "Gmaps is a jQuery plugin that will help you use Google Maps API more easily",
		version: "1.0",
		releaseDate: "10/10/2008",
		author: "Johan Sikström <info@objx.se>",
		website: "http://www.objx.se",
		repository: "http://www.objx.se/gmaps",
		licenceType: "MIT",
		licenceURL: "http://www.opensource.org/licenses/mit-license.php"
	};
	

	$.jmap.JErrors = {
		en : {
			functionDoesNotExist : "jMap Error 1: The function does not exist",
			addressNotFound: "This address cannot be found.  Please modify your search.",
			browserNotCompatible: "This browser is reported as being not compatible with Google Maps.",
			cannotLoad: "Cannot load the Google Maps API at this time.  Please check your connection.",
			markerManagerNotLoaded : "Marker manager is not loaded."
		},
		fr : {
			addressNotFound: "Cette adresse ne peut pas être trouvée. Veuillez modifier votre recherche.",
			browserNotCompatible: "Ce navigateur est rapporté en tant qu'étant non compatible avec des cartes de Google.",
			cannotLoad: "Ne peut pas charger les cartes api de Google actuellement. Veuillez vérifier votre raccordement.",
			markerManagerNotLoaded : "Marker manager is not loaded."
		},
		de : {
			addressNotFound: "Diese Adresse kann nicht gefunden werden. Ändern Sie bitte Ihre Suche.",
			browserNotCompatible: "Diese Datenbanksuchroutine wird als seiend nicht kompatibel mit Google Diagrammen berichtet.",
			cannotLoad: "Kann nicht die Google Diagramme API diesmal laden. Überprüfen Sie bitte Ihren Anschluß.",
			markerManagerNotLoaded : "Marker manager is not loaded."
			
		},
		nl : {
			addressNotFound: "Dit adres kan worden gevonden niet. Gelieve te wijzigen uw onderzoek.",
			browserNotCompatible: "Dit browser wordt gemeld zoals zijnd niet compatibel met Kaarten Google.",
			cannotLoad: "Kan de Google Kaarten API op dit moment laden niet. Gelieve te controleren uw verbinding.",
			markerManagerNotLoaded : "Marker manager is not loaded."
		},
		es : {
			addressNotFound: "Esta dirección no puede ser encontrada. Modifique por favor su búsqueda.",
			browserNotCompatible: "Este browser se divulga como siendo no compatible con los mapas de Google.",
			cannotLoad: "No puede cargar los mapas API de Google en este tiempo. Compruebe por favor su conexión.",
			markerManagerNotLoaded : "Marker manager is not loaded."
		},
		sv : {
			addressNotFound: "Denna adress kunde ej hittas. Var god justera din sökning",
			browserNotCompatible: "Denna webbläsare är ej kompatibel med Google Maps",
			cannotLoad: "Kan inte ladda Google Maps API för tillfället. Var god kontrollera din anslutning.",
			markerManagerNotLoaded : "Marker manager är inte inläst."
		}
	};
	
	/**
	 *	The global object for .jmap("init") calls
	 *	@type Object
	 *	@cat jMapOptions
	 *	@name $.jmap.JDefaults
	 */	
	 $.jmap.JDefaults = {
		language: "se",
		mapType: "map",
		mapCenter: [62.512318,16.523438],
		mapDimensions: [400, 400],
		mapZoom: 4,
		mapControlSize: "small",
		mapEnableType: false,
		mapEnableOverview: false,
		mapEnableDragging: true,
		mapEnableInfoWindows: true,
		mapEnableDoubleClickZoom: false,
		mapEnableBounds : false,
		mapEnableGeoCoder : false,
		mapEnableGeoCache : false,
		mapEnableMarkerManager : false,
		mapEnableScrollZoom: false,
		mapEnableSmoothZoom: false,
		mapEnableGoogleBar: false,
		mapEnableScaleControl: false,
		mapEvents : false,
		mapShowjMapIcon: true,
		debugMode: false
	}
	
	$.jmap.JAdsManagerDefaults = {
		publisherId: ""
	};
	
	$.jmap.JFeedDefaults = {
		feedUrl: "", 
		mapCenter: [] 
	}

	$.jmap.JGroundOverlayDefaults = {
		
		overlaySouthWestBounds: [],
		overlayNorthEastBounds: [],
		overlayImage: ""
	}
	
	$.jmap.JIconDefaults = {
		iconImage: "",
		iconShadow: "",
		iconSize: null,
		iconShadowSize: null,
		iconAnchor: null,
		iconInfoWindowAnchor: null,
		iconPrintImage: "",
		iconMozPrintImage: "",
		iconPrintShadow: "",
		iconTransparent: ""
	};
	
	
	$.jmap.JMarkerManagerDefaults = {  
		borderPadding: 100,  
		maxZoom: 17, 
		trackMarkers: false
	};
	
	
	$.jmap.JMarkerDefaults = {
		index : null,
		point: null,
		lat : null,
		lng : null,		
		popup: null,
		pointOpenHTMLEvent: "click",
		draggable: false,
		removable: false,		
		removeon: "dblclick",
		minzoom: 4,
		maxzoom: 17,
		icon: null,
		maxcontent: null,
		maxtitle: null
	};
	
	
	$.jmap.JPolygonDefaults = {
		
		polygonPoints: [],  // An array of GLatLng objects
		polygonStrokeColor: "#000000",
	 	polygonStrokeWeight: 5,
	 	polygonStrokeOpacity: 1,
	 	polygonFillColor: "#ff0000",
	 	polygonFillOpacity: 1,
	 	mapCenter: [],
	 	polygonClickable: true
	};
	
	
	$.jmap.JPolylineDefaults = {
		
		polylinePoints: [], // An array of GLatLng objects
		polylineStrokeColor: "#ff0000",
		polylineStrokeWidth: 2,
		polylineStrokeOpacity: 1,
		mapCenter: [],
		polylineGeodesic: false,
		polylineClickable: true
	};
	
	$.jmap.JScreenOverlayDefaults = {
		
	}
	
	$.jmap.JSearchAddressDefaults = {
		address : null,
		street : null,
		city : null,
		zipcode : null,
		admarea:null,
		country:null,
		countrycode: 'se',
		focusonhit : true,
		onerror : null,
		onnull : null,
		onhit : null,
		cache: {}
		
	};
	
	$.jmap.JSearchDirectionsDefault = {
		fromAddress: "",
		toAddress: "",
		directionsPanel: ""
	};
	
	$.jmap.JTrafficDefaults = {
		method: "create",
		mapCenter: []
	};
	
	$.jmap.JMoveToDefaults = {
		centerMethod: 'normal',
		mapType: null,
		mapCenter: [],
		mapZoom: null
	}
	
	$.jmap.JSavePositionDefaults = {
		recall: false
	}
	
	$.jmap.variables = {
		mapType: "Unknown",
		mapCenter: []
	}
	
	$.jmap.init = function(el, opt, callback) {
	
		var options = $.extend({}, $.jmap.JDefaults, opt);
		/*var options = $.jmap.JOptions = $.meta ? $.extend({}, options, $(this).data()) : options;*/
		
		$.jmap._initChecks(el);

		el.jmap = $.jmap.GMap2 = new GMap2(el);
		
		if (options.mapShowjMapIcon && typeof adminmode != "undefined" && adminmode === true) {
			$.jmap.addScreenOverlay(
				{
					
					imageUrl : siteurl+"lib/img/ic/maps/copyright.png",
					/*imageUrl:'http://hg.digitalspaghetti.me.uk/jmaps/raw-file/3228fade0b3c/docs/images/jmaps-mapicon.png',*/
					screenXY:[70,10],
					overlayXY:[0,0],
					size:[59,28]
				}
			);
		}
				
				
		// Enable Map Events
		
		if(options.mapEvents){
			$.each(options.mapEvents,function(i,v){
				if(v){
					GEvent.addListener(el.jmap,i,v);				
				}
			});		
		}
		
		
		var mapType = $.jmap._initMapType(options.mapType);
		
		el.jmap.setCenter(new GLatLng(options.mapCenter[0], options.mapCenter[1]), options.mapZoom, mapType);
			
		switch(options.mapControlSize){
			case "small":el.jmap.addControl(new GSmallMapControl());break;
			case "large":el.jmap.addControl(new GLargeMapControl());break;
		}
		
		if(options.mapEnableType)
			el.jmap.addControl(new GMapTypeControl());		
		
		if(options.mapEnableOverview)
			el.jmap.addControl(new GOverviewMapControl());
		
		
		if(!options.mapEnableDragging)
			el.jmap.disableDragging();
			
		// Enable Info Windows
		if(!options.mapEnableInfoWindows)
			el.jmap.disableInfoWindow();
		
		// Enable double click zoom on the map
		if(options.mapEnableDoubleClickZoom)
			el.jmap.enableDoubleClickZoom();
		
		// Enable scrollwheel on the map
		if(options.mapEnableScrollZoom)
			el.jmap.enableScrollWheelZoom();
		
		// Enable smooth zooming
		if (options.mapEnableSmoothZoom)
			el.jmap.enableContinuousZoom();

		// Enable geocoder
		if (options.mapEnableGeoCoder){
			el.jmap.GClientGeocoder = new GClientGeocoder;
		}
		
		// Enable external marker manager
		if (options.mapEnableMarkerManager){
			if(!marker_manager_loaded){
				throw new Error($.jmap.JErrors[$.jmap.JOptions.language].markerManagerNotLoaded);
			}else{
				el.jmap.MarkerManager = new MarkerManager($.jmap.GMap2);
			}			
		}
		
		
		// Enable geo cache
		if(options.mapEnableGeoCache){
			el.jmap.GGeocodeCache = new GGeocodeCache();
		}
		
		// Enable bounds
		if (options.mapEnableBounds){
			el.jmap.GBounds = new GLatLngBounds();
		}			


		// Enable Google Bar
		if (options.mapEnableGoogleBar)
			el.jmap.enableGoogleBar(); 
			
		// Enables Scale bar
		if (options.mapEnableScaleControl)
			el.jmap.addControl(new GScaleControl());

		// output init to console
		if (options.debugMode) {
		    console.log(el.jmap);
		}

		// Initialise variables
		$.jmap.getMapType();
		
		if (typeof callback == 'function') return callback(el, options);
	}
	

	$.jmap.createIcon = function(options) {
		var options = $.extend({}, $.jmap.JIconDefaults, options);
		var icon = new GIcon(G_DEFAULT_ICON);
		
		if(options.iconImage)
			icon.image = options.iconImage;
		if(options.iconShadow)
			icon.shadow = options.iconShadow;
		if(options.iconSize)
			icon.iconSize = options.iconSize;
		if(options.iconShadowSize)
			icon.shadowSize = options.iconShadowSize;
		if(options.iconAnchor)
			icon.iconAnchor = options.iconAnchor;
		if(options.iconInfoWindowAnchor)
			icon.infoWindowAnchor = options.iconInfoWindowAnchor;
	
		return icon;
	}
	




	/**
	 *	Create a marker and add it as a point to the map
	 */
	$.jmap.addMarker = function(options, callback) {
		// Create options
		var options = $.extend({}, $.jmap.JMarkerDefaults, options);
		var markerOptions = {}

		if (typeof options.icon == 'object')
			$.extend(markerOptions, {icon: options.icon});
		
		
		if (options.draggable){
			$.extend(markerOptions, {draggable: options.draggable});

			
		}
		// Create marker, optional parameter to make it draggable
		if(options.point){
			var marker = new GMarker(new GLatLng(options.point[0],options.point[1]), markerOptions);
		}else if(options.lat && options.lng){
			
			var marker = new GMarker(new GLatLng(options.lat,options.lng), markerOptions);
		}
		
		if(options.draggable && options.ondragend && typeof options.ondragend == "function"){

			GEvent.addListener(marker, "dragend", function(){
				options.ondragend(marker);
			});
		}		
		
		// If it has HTML to pass in, add an event listner for a click
		if(options.popup)
			GEvent.addListener(marker, options.pointOpenHTMLEvent, function(){
				marker.openInfoWindowHtml(options.popup, {maxContent: options.maxcontent, maxTitle: options.maxtitle});
			});

		// If it is removable, add dblclick event
		if(options.removable){
			GEvent.addListener(marker, options.removeon, function(){
				$.jmap.GMap2.removeOverlay(marker);
			});
		}


		if(options.index){
			markerindex = options.index;	
		}else{
			markerindex = $.jmap.gmarkercount++;
		}
		if($.jmap.gmarkers[markerindex]){
			$.jmap.GMap2.removeOverlay($.jmap.gmarkers[markerindex]);
		}
		$.jmap.gmarkers[markerindex] = marker;
		
		// If the marker manager exists, add it
		if($.jmap.MarkerManager) {
			$.jmap.MarkerManager.addMarker(marker, options.minzoom, options.maxzoom);	
		} else {
			// Direct rendering to map

			$.jmap.GMap2.addOverlay(marker);
		}

		if (typeof callback == 'function') return callback();
	}


	$.jmap.searchLocation = function(options, callback) {
		var options = $.extend({}, $.jmap.JSearchAddressDefaults, options);
		var pass = $.extend({}, $.jmap.JMarkerManagerDefaults);
		if (typeof $.jmap.GClientGeocoder == 'undefined') {
			 var geocoder = new GClientGeocoder;
		} else {
			var geocoder = $.jmap.GClientGeocoder;
		}
		if(options.countrycode){
			geocoder.setBaseCountryCode(options.countrycode);
		}		
		
		var addr = "";
		if(options.address){
			addr = options.address;
		}else{
			if(options.street){addr += addr.length > 0 ? ", "+options.street : options.street;};
			if(options.city){addr += addr.length > 0 ? ", "+options.city : options.city;};
			if(options.zipcode){addr += addr.length > 0 ? ", "+options.zipcode : options.zipcode;};
			if(options.admarea){addr += addr.length > 0 ? ", "+options.admarea : options.admarea;};
			if(options.country){addr += addr.length > 0 ? ", "+options.country : options.country;};
						
		}
		
		geocoder.getLocations(addr, function(resp){

			if(typeof resp == "object" && typeof resp.Status != "undefined" && typeof resp.Status.code != "undefined" && resp.Status.code == 200){
				var points = $.jmap.parseResults(resp.Placemark);
				var p = resp.Placemark[0].Point ? resp.Placemark[0].Point.coordinates : null;

				if(!points.length || points.length <= 0){
					if(options.onnull){
						options.onnull(options.addr);
					}
				}
				if(options.onhit){
					options.onhit(points);
				}
				if(options.focusonhit && p){
					$.jmap.GMap2.setCenter(new GLatLng(p[1],p[0]));
				}
				return points;

			}else{
				
				if(options.onnull){
					options.onnull(options.addr);
				}else{
					throw new Error($.jmap.JErrors[$.jmap.JOptions.language].addressNotFound);
				}
				return false;
			}
		
		});
		
		/*
		geocoder.getLatLng(options.address, function(point){
				if (!point) {
					throw new Error($.jmap.JErrors[$.jmap.JOptions.language].addressNotFound);
				}
				if (typeof callback == 'function') return callback(options, point);
		});
		*/
	}
	
	$.jmap.parseResults = function(c){
		if (!c) {
			return false;
		}else{
			var ret = [];

			$.each(c,function(i,v){

				ret[i] = [];
				ret[i]['address'] = v.address;

				if(v.AddressDetails){
					if(v.AddressDetails.Country){

						if(v.AddressDetails.Country.AdministrativeArea){
							if(v.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName){
								ret[i]['administrativearea'] = v.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
							}
							if(v.AddressDetails.Country.AdministrativeArea.Locality){
								if(v.AddressDetails.Country.AdministrativeArea.Locality.LocalityName){
									ret[i]['locality'] = v.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
								}
								if(v.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare && v.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName){
									ret[i]['thoroughfare'] = v.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
								}
								if(v.AddressDetails.Country.AdministrativeArea.Locality.PostalCode && v.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber){
									ret[i]['postalcode'] = v.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber;
								}	
								if(v.AddressDetails.Country.AdministrativeArea.Locality.PostalCode && v.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber){
									ret[i]['postalcode'] = v.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber;
								}							
							}
						}
						if(v.AddressDetails.Country.CountryNameCode){
							ret[i]['countrycode'] = v.AddressDetails.Country.CountryNameCode;
						}					
					}
				}
				if(v.Point && v.Point.coordinates){
					ret[i]['lat'] = v.Point.coordinates[1];
					ret[i]['lng'] = v.Point.coordinates[0];
				}
			});


			return ret;
		}
	
	};

	$.jmap.searchDirections = function(options, callback) {	
		var options = $.extend({}, $.jmap.JSearchDirectionsDefaults, options);
		var panel = $('#' + options.directionsPanel).get(0);
		$.jmap.GDirections = new GDirections($.jmap.GMap2, panel);
		$.jmap.GDirections.load(options.fromAddress + ' to ' + options.toAddress);
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.moveTo = function(options, callback) {
		
		var options = $.extend({}, $.jmap.JMoveToDefaults, options);
		if (options.mapType)
			var mapType = $.jmap._initMapType(options.mapType);
		var point = new GLatLng(options.mapCenter[0], options.mapCenter[1]);
		switch (options.centerMethod) {
			case 'normal':
				$.jmap.GMap2.setCenter(point, options.mapZoom, mapType);
				break;
			case 'pan':
				$.jmap.GMap2.panTo(point);
				break;
		}
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.savePosition = function(options, callback) {
		var options = $.extend({}, $.jmap.JMoveToDefaults, options);
		if (options.recall) {
			$.jmap.GMap2.returnToSavedPosition();
		} else {
			$.jmap.GMap2.savePosition();
		}
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.createKeyboardHandler = function(callback){
		$.jmap.keyboardHandler = new GKeyboardHandler($.jmap.GMap2);
		if (typeof callback == 'function') return callback();
	}
	
	
	// Function currently not returning correctly
	$.jmap.getMapType = function() {
		var mapTypes = $.jmap.GMap2.getMapTypes();
		var actMap = $.jmap.GMap2.getCurrentMapType();
		if (actMap.Hz) {
			$.jmap.variables.mapType = actMap.Hz;
		}
	}
	
	$.jmap.getCenter = function(){
		var center = $.jmap.GMap2.getCenter();
		$.jmap.variables.mapCenter = center
		if (typeof callback == 'function') return callback(center);
	}
	
	$.jmap.getBounds = function(){
		var bounds = $.jmap.GMap2.getBounds();
		$.jmap.variables.mapBounds = bounds;
		if (typeof callback == 'function') return callback(bounds);
	}


	$.jmap.addGroundOverlay = function(options, callback) {
		var options = $.extend({}, $.jmap.JGroundOverlayDefaults, options);
		var boundries = new GLatLngBounds(new GLatLng(options.overlaySouthWestBounds[0], options.overlaySouthWestBounds[1]), new GLatLng(options.overlayNorthEastBounds[0], options.overlayNorthEastBounds[1]));
		
		$.jmap.GGroundOverlay = new GGroundOverlay(options.overlayImage, boundries);
		$.jmap.GMap2.addOverlay($.jmap.GGroundOverlay);
		
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.hideGroundOverlay = function(callback) {
		$.jmap.GGroundOverlay.hide();
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.showGroundOverlay = function(callback) {
		isHidden = $.jmap.GGroundOverlay.isHidden();
		if (isHidden)
			$.jmap.GGroundOverlay.show();
		if (typeof callback == 'function') return callback();
	}

	$.jmap.addFeed = function(options, callback) {
	
		var options = $.extend({}, $.jmap.JFeedDefaults, options);
			
		var feed = new GGeoXml(options.feedUrl);
		
		$.jmap.GMap2.addOverlay(feed);
		
		
		if (options.mapCenter[0] && options.mapCenter[1])
			$.jmap.GMap2.setCenter(new GLatLng(options.mapCenter[0], options.mapCenter[1]));
		
		if (typeof callback == 'function') return callback(feed, options);
	}
	

	

	
	/**
	 * Create a screen overlay
	 * @param {Object} options
	 * @param function callback
	 */
	$.jmap.addScreenOverlay = function(options, callback) {
		var options = $.extend({}, $.jmap.JScreenOverlayDefaults, options);
		var overlay = new GScreenOverlay(options.imageUrl, new GScreenPoint(options.screenXY[0],options.screenXY[1]), new GScreenPoint(options.overlayXY[0],options.overlayXY[1]), new GScreenSize(options.size[0],options.size[1]));
		$.jmap.GMap2.addOverlay(overlay);
		
		if (typeof callback == 'function') return callback(overlay, options);
	}
	
	/**
	 * Create a polygon and render to the map
	 */
	 $.jmap.addPolygon = function(options, callback) {
	 	
	 	var options = $.extend({}, $.jmap.JPolygonDefaults, options);
		polygonOptions = {};
	 	if (!options.polygonClickable)
			var polygonOptions = $.extend({}, polygonOptions, {
				clickable: false
			});
	 		
	 	if(options.mapCenter[0] && options.mapCenter[1])
	 		$.jmap.GMap2.setCenter(new GLatLng(options.mapCenter[0], options.mapCenter[1]));
		
		var polygon = new GPolygon(options.polygonPoints, options.polygonStrokeColor, options.polygonStrokeWeight, options.polygonStrokeOpacity, options.polygonFillColor, options.polygonFillOpacity, polygonOptions);

		$.jmap.GMap2.addOverlay(polygon);
		
		if (typeof callback == 'function') return callback();
	 }
	
	/**
	 *	Create a polyline and render on the map
	 */
	$.jmap.addPolyline = function (options, callback) {
		var options = $.extend({}, $.jmap.JPolylineDefaults, options);
		var polyLineOptions = {};
		if (options.polylineGeodesic)
			$.extend({}, polyLineOptions, {geodesic: true});
			
		if(!options.polylineClickable)
			$.extend({}, polyLineOptions, {clickable: false});

		if (options.mapCenter[0] && options.mapCenter[1])
			$.jmap.GMap2.setCenter(new GLatLng(options.mapCenter[0], options.mapCenter[1]));

		var polyline = new GPolyline(options.polylinePoints, options.polylineStrokeColor, options.polylineStrokeWidth, options.polylineStrokeOpacity, polyLineOptions);
		$.jmap.GMap2.addOverlay(polyline);
		
		if (typeof callback == 'function') return callback();
	}
		
	$.jmap.addTrafficInfo = function(options, callback) {
		var options = $.extend({}, $.jmap.JTrafficDefaults, options);
		
		switch(options.method) {
			case "create":
				$.jmap.GTrafficOverlay = new GTrafficOverlay;
				$.jmap.GMap2.addOverlay($.jmap.GTrafficOverlay);
				if (options.mapCenter[0] && options.mapCenter[1]) {
					$.jmap.GMap2.setCenter(new GLatLng(options.mapCenter[0], options.mapCenter[1]));
				}
			break;
			case "destroy":
				// Distroy overlay
				$.jmap.GMap2.removeOverlay($.jmap.GTrafficOverlay);
			break;
		
		}
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.disableTraffic = function(callback) {
		$.jmap.GTrafficOverlay.hide();
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.enableTraffic = function(callback) {
		$.jmap.GTrafficOverlay.show();
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.createAdsManager = function(options, callback) {
		var options = $.extend({}, $.jmap.JAdsManagerDefaults, options);
	
		$.jmap.GAdsManager = new GAdsManager($.jmap.GMap2, options.publisherId);
		
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.hideAds = function(callback){
		$.jmap.GAdsManager.disable();
		if (typeof callback == 'function') return callback();
	}
	
	$.jmap.showAds = function(callback){
		$.jmap.GAdsManager.enable();
		if (typeof callback == 'function') return callback();
	}
	
	

	

	


	/* Internal Functions */
	

	$.jmap._initMapType = function(option) {
		// Lets set our map type based on the options
		switch(option) {
			case "map":	// Normal Map
				var maptype = G_NORMAL_MAP;
			break;
			case "sat":	// Satallite Imagery
				var maptype = G_SATELLITE_MAP;
			break;
			case "hybrid":	//Hybrid Map
				var maptype = G_HYBRID_MAP;
			break;
		}
		return maptype;	
	}
	
	$.jmap._initChecks = function(el) {
		if (typeof GBrowserIsCompatible == 'undefined') {
			$(el).text($.jmap.JErrors[$.jmap.JOptions.language].cannotLoad).css({
				color: "#f00"
			});
			throw Error($.jmap.JErrors[$.jmap.JOptions.language].cannotLoad);
		}
		if (!GBrowserIsCompatible()) {
			$(el).text($.jmap.JErrors[$.jmap.JOptions.language].browserNotCompatible).css({color: "#f00"});
			throw Error($.jmap.JErrors[$.jmap.JOptions.language].browserNotCompatible);
		}
	}
	
	$.jmap.storePoints = function(options, callback) {
		$.jmap.store = $.extend({}, $.jmap.store, options);		
		if (typeof callback == 'function') return callback($.jmap.store);
	}
	
	$.fn.jmap = function(method, options, callback) {
		return this.each(function(){
			if (method == "init") {
				new $.jmap.init(this, options, callback);
			} else if (typeof method == 'object' || method == null) {
				new $.jmap.init(this, method, options);
			} else if (typeof options == 'function'){
				new $.jmap[method](options);
			} else {
				try {
					new $.jmap[method](options, callback);
				} catch(err) {
					throw Error($.jmap.JErrors[$.jmap.JOptions.language].functionDoesNotExist);
				}
			}
		});
	}
})(jQuery);
