function toRad(a){return a*Math.PI/180}function handleBlackBerryLocationTimeout(){bb_blackberryTimeout_id!=-1&&bb_errorCallback({message:"Timeout error",code:3})}function handleBlackBerryLocation(){if(clearTimeout(bb_blackberryTimeout_id),bb_blackberryTimeout_id=-1,bb_successCallback&&bb_errorCallback){if(0==blackberry.location.latitude&&0==blackberry.location.longitude)bb_errorCallback({message:"Position unavailable",code:2});else{var a=null;blackberry.location.timestamp&&(a=new Date(blackberry.location.timestamp)),bb_successCallback({timestamp:a,coords:{latitude:blackberry.location.latitude,longitude:blackberry.location.longitude}})}bb_successCallback=null,bb_errorCallback=null}}function showDistanceDirection(a){getCoords(a),setTimeout("showDistanceDirection("+a+")",3e3)}function getCoords(a,b){if(geo_position_js.init()){if("undefined"==typeof a)return null;"undefined"==typeof b&&(b=error_callback),geo_position_js.getCurrentPosition(a,b,{enableHighAccuracy:!0})}}function error_callback(a){}function getDistanceStr(a,b){var c="km";return b?a<1&&(c="m"):(c="mi",a<1.609344&&(c="yrd")),a=convertDistance(a,c),a+" "+c}function convertDistance(a,b){var c=1;switch(a=parseFloat(a),b){case"m":a=1e3*a,c=0;break;case"mi":a/=1.609344;break;case"yrd":a=1093.6133*a,c=0}var d=Math.pow(10,c);return Math.round(a*d)/d}function convertDegreesToDirection(a){if("number"!=typeof a||a<0||a>360)return null;for(var b=new Array("n","ne","e","se","s","sw","w","nw"),c=45,d=22.5,e="n",f=d*-1,g=d,h=0;h<b.length;h++){if(a>=f&&a<=g){e=b[h];break}f=g,g+=c}return e}function saveInSuccessFunc(){setCookie("findus_success","true",1)}function checkForFindUsCookie(){return null!=getCookie("findus_success")}function setCookie(a,b,c){var d="";if(c){var e=new Date;e.setTime(e.getTime()+24*c*60*60*1e3),d="; expires="+e.toGMTString()}document.cookie=a+"="+b+d+"; path=/"}function getCookie(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d<c.length;d++){for(var e=c[d];" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(b))return e.substring(b.length,e.length)}return null}function LatLon(a,b,c){"undefined"==typeof c&&(c=6371),this._lat=a,this._lon=b,this._radius=c}var bb_successCallback,bb_errorCallback,bb_blackberryTimeout_id=-1,geo_position_js=function(){var a={},b=null;return a.getCurrentPosition=function(a,c,d){b.getCurrentPosition(a,c,d)},a.init=function(){try{if("undefined"!=typeof geo_position_js_simulator)b=geo_position_js_simulator;else if("undefined"!=typeof bondi&&"undefined"!=typeof bondi.geolocation)b=bondi.geolocation;else if("undefined"!=typeof navigator.geolocation)b=navigator.geolocation,a.getCurrentPosition=function(a,c,d){function e(b){a("undefined"!=typeof b.latitude?{timestamp:b.timestamp,coords:{latitude:b.latitude,longitude:b.longitude}}:b)}b.getCurrentPosition(e,c,d)};else if("undefined"!=typeof window.google&&"undefined"!=typeof google.gears)b=google.gears.factory.create("beta.geolocation");else if("undefined"!=typeof Mojo&&"Mojo.Service.Request"!=typeof Mojo.Service.Request)b=!0,a.getCurrentPosition=function(a,b,c){parameters={},c&&(c.enableHighAccuracy&&1==c.enableHighAccuracy&&(parameters.accuracy=1),c.maximumAge&&(parameters.maximumAge=c.maximumAge),c.responseTime&&(c.responseTime<5?parameters.responseTime=1:c.responseTime<20?parameters.responseTime=2:parameters.timeout=3)),r=new Mojo.Service.Request("palm://com.palm.location",{method:"getCurrentPosition",parameters:parameters,onSuccess:function(b){a({timestamp:b.timestamp,coords:{latitude:b.latitude,longitude:b.longitude,heading:b.heading}})},onFailure:function(a){b(1==a.errorCode?{code:3,message:"Timeout"}:2==a.errorCode?{code:2,message:"Position Unavailable"}:{code:0,message:"Unknown Error: webOS-code"+errorCode})}})};else if("undefined"!=typeof device&&"undefined"!=typeof device.getServiceObject)b=device.getServiceObject("Service.Location","ILocation"),a.getCurrentPosition=function(a,c,d){function e(b,d,e){4==d?c({message:"Position unavailable",code:2}):a({timestamp:null,coords:{latitude:e.ReturnValue.Latitude,longitude:e.ReturnValue.Longitude,altitude:e.ReturnValue.Altitude,heading:e.ReturnValue.Heading}})}var f=new Object;f.LocationInformationClass="BasicLocationInformation",b.ILocation.GetLocation(f,e)};else if("undefined"!=typeof window.blackberry&&blackberry.location.GPSSupported){if("undefined"==typeof blackberry.location.setAidMode)return!1;blackberry.location.setAidMode(2),a.getCurrentPosition=function(a,b,c){bb_successCallback=a,bb_errorCallback=b,bb_blackberryTimeout_id=c.timeout?setTimeout("handleBlackBerryLocationTimeout()",c.timeout):setTimeout("handleBlackBerryLocationTimeout()",6e4),blackberry.location.onLocationUpdate("handleBlackBerryLocation()"),blackberry.location.refreshLocation()},b=blackberry.location}}catch(c){return alert("error="+c),"undefined"!=typeof console&&console.log(c),!1}return null!=b},a}();LatLon.prototype.distanceTo=function(a,b){"undefined"==typeof b&&(b=4);var c=this._radius,d=toRad(this._lat),e=toRad(this._lon),f=toRad(a._lat),g=toRad(a._lon),h=f-d,i=g-e,j=Math.sin(h/2)*Math.sin(h/2)+Math.cos(d)*Math.cos(f)*Math.sin(i/2)*Math.sin(i/2),k=2*Math.atan2(Math.sqrt(j),Math.sqrt(1-j)),l=c*k;return l.toPrecisionFixed(b)},LatLon.prototype.bearingTo=function(a){var b=toRad(this._lat),c=toRad(a._lat),d=toRad(a._lon-this._lon),e=Math.sin(d)*Math.cos(c),f=Math.cos(b)*Math.sin(c)-Math.sin(b)*Math.cos(c)*Math.cos(d),g=Math.atan2(e,f);return(g.toDeg()+360)%360},"undefined"==typeof String.prototype.toRad&&(Number.prototype.toRad=function(){return this*Math.PI/180}),"undefined"==typeof String.prototype.toDeg&&(Number.prototype.toDeg=function(){return 180*this/Math.PI}),"undefined"==typeof Number.prototype.toPrecisionFixed&&(Number.prototype.toPrecisionFixed=function(a){var b=this<0?-this:this,c=this<0?"-":"";if(0==b){for(e="0.";a--;)e+="0";return e}var d=Math.ceil(Math.log(b)*Math.LOG10E),e=String(Math.round(b*Math.pow(10,a-d)));if(d>0){for(l=d-e.length;l-- >0;)e+="0";d<e.length&&(e=e.slice(0,d)+"."+e.slice(d))}else{for(;d++<0;)e="0"+e;e="0."+e}return c+e});var goMobi=goMobi||{};goMobi.findUs=goMobi.findUs||{getLocationTimeout:0,closeOverlay:function(){$(".show-overlay").removeClass("show-overlay"),$("#find-us-overlay").removeAttr("class"),window.location.hash=$(".active").attr("id")},getDirections:function(a){goMobi.findUs.showItem(a);var b=window.innerWidth||self.innerWidth||document.body.clientWidth,c=window.innerHeight||self.innerHeight||document.body.clientHeight;q_width=200,q_left=b/2-q_width/2,q_top=c/2-q_width/2,$("#gm-middle").addClass("show-overlay"),window.location.hash="",window.scrollTo(0,0)},showItem:function(a){var b=$(a.currentTarget),c=b.closest(".find-us-section"),d=c.closest("#find-us-containter");d.hasClass(c.attr("id"))||(d.attr("class",c.attr("id")),$(".input").removeClass("input"),$(".active .find-us-right").html('<div class="find-us-zoom"></div>'),$(".active").removeClass("active"),c.addClass("active"),goMobi.findUs.initMap(b,500))},initMap:function(a,b){if(!navigator.geolocation)return!1;$(".find-us-right").removeClass("init"),a.hasClass("find-us-address-button")?a.closest(".find-us-section").find(".find-us-right").addClass("init"):a.addClass("init");var c=this,d=/(|-)\d{1,3}\.[0-9]*(,|%2C)(|-)\d{1,3}\.\d*/;a=a.closest(".find-us-section");var e=a.data("map")||a.find(".find-us-right").css("background-image"),f=null,g=a.data("latitude"),h=a.data("latitude");if(e.match(d)){var i=decodeURIComponent(e.match(d)[0]),j=i.split(",");g=j[0],h=j[1]}else{var k=new google.maps.Geocoder;k.geocode({address:a.find(".address-line-1").text()},function(a){return!!(f=a[0].geometry.location)&&(g=f.ob,void(h=f.pb))})}this.latlng=new google.maps.LatLng(g,h),a=a.find(".find-us-right");var l={zoom:16,mapTypeId:google.maps.MapTypeId.ROADMAP,backgroundColor:$("#app_container").css("backgroundColor"),streetViewControl:!0,center:c.latlng};setTimeout(function(){c.map=new google.maps.Map(a[0],l),c.marker=new google.maps.Marker({map:c.map,position:c.latlng})},b)},initDirections:function(){var a=this,b=/A\|(|-)\d{1,3}\.[0-9]*(,|%2C)(|-)\d{1,3}\.\d*/,c=/B\|(|-)\d{1,3}\.[0-9]*(,|%2C)(|-)\d{1,3}\.\d*/,d=decodeURIComponent($("#dir_map .findus-map").attr("src"));a.directionDisplay,a.directionsService=new google.maps.DirectionsService,a.map;var e=d.match(b)[0].substring(2).split(",");a.latlng=new google.maps.LatLng(e[0],e[1]),a.directionsDisplay=new google.maps.DirectionsRenderer;var f={backgroundColor:"#EEE",mapTypeId:google.maps.MapTypeId.ROADMAP,position:a.latlng};a.map=new google.maps.Map(document.getElementById("dir_map"),f),a.directionsDisplay.setMap(a.map),a.request={origin:d.match(b)[0].substring(2),destination:d.match(c)[0].substring(2),travelMode:google.maps.DirectionsTravelMode.DRIVING},a.directionsService.route(a.request,function(b,c){c==google.maps.DirectionsStatus.OK&&a.directionsDisplay.setDirections(b)})},geo_query:function(a){clearTimeout(goMobi.findUs.getLocationTimeout),$("#find-us-geolocation-dialog .find-us-overlay-dialog-button").trigger("click");var b=new Array,c=new LatLon(a.coords.latitude,a.coords.longitude),d=$("#find-us-container");d.find(".find-us-section").each(function(){if($(this).data("latitude")&&$(this).data("longitude")){var a=new LatLon($(this).data("latitude"),$(this).data("longitude"));b.push(a)}}),b.sort(function(a,b){return a.distanceTo(c)-b.distanceTo(c)});for(var e=b.length-1;e>=0;e--){var f=d.find(".find-us-section[data-latitude='"+b[e]._lat+"']");f&&f.insertAfter("div.find-us-show-nearest-button")}d.find("hr").remove(),d.find(".find-us-section:not(:last-child)").each(function(){$("<hr/>").insertAfter(this)}),$(".find-us-section").removeClass("active"),$(".busy-message").hide();var g=$("div.find-us-section[data-latitude='"+b[0]._lat+"']");g.addClass("active"),g.find(".find-us-right").trigger("click"),window.location="#"+g.attr("id")},error_log:function(a){switch(clearTimeout(goMobi.findUs.getLocationTimeout),$("#find-us-geolocation-overlay").show(),$(".busy-message").hide(),a.code){case a.PERMISSION_DENIED:$("#find-us-geolocation-disabled").show(),console.log("User has not enabled geolocation");break;case a.POSITION_UNAVAILABLE:$("#find-us-geolocation-couldnotdetect").show(),console.log("Could not detect current position");break;case a.TIMEOUT:$("#find-us-geolocation-timeout").show(),console.log("Retrieving position timed out");break;default:$("#find-us-geolocation-unknownerror").show(),console.log("Unknown error when retrieving users position")}},init:function(){var a=goMobi.findUs;if($(".find-us-section").length>0){if(a.initMap($(".active .find-us-right"),0),window.goMoFindloaded)return!1;window.goMoFindloaded=!0,navigator.geolocation&&$(".address-section").length>1&&$(".find-us-show-nearest-button").on("click",function(){clearTimeout(a.getLocationTimeout);var b=$(".active .find-us-right"),c=b.find(".busy-message");0===c.length&&(c=$('<div class="busy-message"><i class="icon-loading"></i></div>'),b.append(c)),c.show(),navigator.geolocation.getCurrentPosition(a.geo_query,a.error_log,{timeout:6e3}),a.getLocationTimeout=setTimeout(function(){a.error_log(new Object({code:1,PERMISSION_DENIED:1}))},1e4)}).show(),$(".find-us-address-button").on("click",function(){clearTimeout(a.getLocationTimeout),"block"==$(this).children(".button-icon").css("display")&&($("#find-us-directions-from-current-location").attr("href",$(this).attr("data-from-current-location-href")),$(".find-us-number-button, .find-us-email-button").addClass("button-color-bg"),$(this).parent().find(".find-us-email-button, .find-us-number-button").removeClass("button-color-bg"))}),$(".find-us-right").on("click",function(){clearTimeout(a.getLocationTimeout),1==$(this).find(".find-us-zoom").length&&($(".find-us-number-button, .find-us-email-button").addClass("button-color-bg"),$(this).closest(".find-us-section").find(".find-us-number-button, .find-us-email-button").removeClass("button-color-bg"))}),$("#find-us-geolocation-dialog .find-us-overlay-dialog-button").bind("click",function(){$("#find-us-geolocation-overlay, .find-us-gelocation-notification").hide()}),$(".find-us-right").bind("click",function(b){$(this).hasClass("init")||a.showItem(b)}),geo_position_js.init()?$(".find-us-address-button").bind("click",a.getDirections):$(".find-us-address-button").bind("click",function(b){a.showItem(b),$(b.currentTarget).closest(".find-us-section").addClass("input").children("input").trigger("focus")}),$("#find-us-overlay-address-close, #find-us-overlay-close, #find-us-overlay-background").bind("click",a.closeOverlay),$("#find-us-overlay-fromhere").bind("click",function(){a.closeOverlay()}),$("#find-us-overlay-fromaddress").bind("click",function(b){a.closeOverlay(),$(".active").addClass("input").find("input").trigger("focus")})}else $("#dir_map").length>0&&a.initDirections();a.loaded=!0}},$(function(){setTimeout(goMobi.findUs.init,500),$("#address0").find(".find-us-number-button, .find-us-email-button").removeClass("button-color-bg")});
window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,0)},window.addEventListener("deviceorientation",function(a){var b=document.getElementById("bearing");if(null==b)return!1;var c="undefined"==typeof window.orientation?0:window.orientation;if("undefined"==typeof a.a){if(-1!=navigator.userAgent.search("like Mac OS X"))return!1;c+=a.alpha}else c=-1*(c+a.a);a=(parseInt(b.getAttribute("data-bearing"),10)+c)%360,window.requestAnimationFrame(function(){b.style.setProperty("-moz-transform","rotate("+a+"deg)"),b.style.setProperty("-webkit-transform","rotate("+a+"deg)"),b.style.setProperty("-ms-transform","rotate("+a+"deg)"),b.style.setProperty("-o-transform","rotate("+a+"deg)"),b.style.setProperty("transform","rotate("+a+"deg)")})},!0);
