(function(k,g){(function(l){var e=k.simplegeo;if(e===g)e={};if(e.Client===g){e.Client=function(b,a){if(!(this instanceof e.Client))return new e.Client(b,a);a=a||{};this.token=b;this.options=a;this.proto=a.proto||"https";this.host=a.host||"api.simplegeo.com";this.port=a.port||(this.proto==="https"?"443":"80");var c=parseFloat(l.fn.jquery.match(/^[0-9]+\.[0-9]+/)[0]),d=l.fn.jquerymin;if(a.cors&&d)throw Error("You cannot use CORS unless you use the jQuery version of the SimpleGeo client");this.cors=
a.cors||(!d&&c>=1.4?"auto":false);this.apiUrl=this.proto+"://"+this.host+":"+this.port;this.name="Client"};var j=k.navigator;e.Client.prototype={request:function(b,a,c){this.cors?this.requestCORS(b,a,c):this.requestJSONP(b,a,c)},requestCORS:function(b,a,c){var d=this;a.token=this.token;try{l.ajax({url:this.apiUrl+b,dataType:"json",data:a,success:function(h){c(null,h)},error:function(h,m,i){if(i){k.console&&console.error(b,h,m,i);if(d.cors==="auto"){d.cors=false;d.requestJSONP(b,a,c)}else c(i)}else{i=
{error:true,code:h.status};try{i.message=JSON.parse(responseText).message}catch(n){i.message=h.statusText}c(i)}}})}catch(f){k.console&&console.error(b,xhr,textStatus,f);if(d.cors==="auto"){d.cors=false;d.requestJSONP(b,a,c)}else throw f;}},requestJSONP:function(b,a,c){a.token=this.token;a=l.param(a)+"&callback=?";l.ajax({url:this.apiUrl+b,dataType:"json",data:a,success:function(d){if(d.error){var f=Error(d.message);f.code=d.code;c(f)}else c(null,d.data)},error:function(d,f,h){c(h)}})},getFeature:function(b,
a,c){if(c===g){c=a;a={}}return this.request("/1.0/features/"+b+".json",a,c)},getFeatureCategories:function(b){return this.request("/1.0/features/categories.json",{},b)},watchLocationFromBrowser:function(b,a){if(a===g){a=b;b={}}j&&j.geolocation?j.geolocation.watchPosition(function(c){a(null,c)},function(c){a(c)},b):a(Error("navigator.geolocation not available"))},getLocationFromBrowser:function(b,a){if(a===g){a=b;b={}}j&&j.geolocation?j.geolocation.getCurrentPosition(function(c){a(null,c)},function(c){a(c)},
b):a(Error("navigator.geolocation not available"))},getLocationFromIP:function(b,a){var c;if(a===g){a=b;c="/0.1/locate.json"}else c="/0.1/locate/"+b+".json";return this.request(c,{},function(d,f){d?a(d):a(null,{coords:{latitude:f.geometry.coordinates[1],longitude:f.geometry.coordinates[0],accuracy:1E5},timestamp:new Date,source:"simplegeo"})})},getLocation:function(b,a){var c=this;if(a===g){a=b;b={}}c.getLocationFromBrowser(b,function(d,f){d?c.getLocationFromIP(a):a(null,f)})},getNearbyAddress:function(b,
a,c){return this.request("/0.1/nearby/address/"+b+","+a+".json",{},c)}}}e.ContextClient=function(b,a){if(!(this instanceof e.ContextClient))return new e.ContextClient(b,a);e.Client.call(this,b,a);this.name="ContextClient"};e.ContextClient.prototype=new e.Client;e.ContextClient.prototype.getContext=function(b,a,c){return this.request("/1.0/context/"+b+","+a+".json",{},c)};e.ContextClient.prototype.getContextFromIP=function(b,a){if(a===g){a=b;b="ip"}return this.request("/1.0/context/"+b+".json",{},
a)};e.ContextClient.prototype.getContextFromAddress=function(b,a){return this.request("/1.0/context/address.json",{address:b},a)};k.simplegeo=e})(jQuery)})(window);

