(function(b){var a={map:function(){return b(this).data("cabulous:googleMap")}};b.fn.cabulous=function(K){var r=this.get(0);if(typeof(a[K])==="function"){return a[K].apply(r)}var z;var h=false;var e=false;var G=false;var F="";if(typeof(K)=="object"){var u=K;if(u.center&&u.center.latitude&&u.center.longitude){z=new google.maps.LatLng(u.center.latitude,u.center.longitude)}if(u.show_search){h=u.show_search}if(u.show_live_cities){e=u.show_live_cities}if(u.show_companies){G=u.show_companies}if(u.company_filter){Cabulous.Shared.COMPANY_FILTER=u.company_filter}if(u.default_city){F=u.default_city}if(u.mode){if(u.mode=="dispatch"){Cabulous.Status.IS_DISPATCH=true}}}var L=new google.maps.LatLng(37.7749,-122.4194);var m=L;z=z||m;var g={mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:false,zoom:12,center:z};if(!!b(r).data("cabulous:googleMap")){return this}var E=new google.maps.Map(r,g);Cabulous.Shared.MAP=E;b(r).data("cabulous:googleMap",E);function C(){b(r).append(Cabulous.Partials.controlOverlayUI());b("._cabulousControlContents").css("opacity","0.75");var U=b("._cabulousControlOverlay");b(U).attr("hidden",true);var P=true;var S=15;if(h){b("._cabulousControlContents").append(Cabulous.Partials.controlOverlaySearchUI());S+=29}if(e){b("._cabulousControlContents").append(Cabulous.Partials.controlOverlayContentsLiveCabCitiesUI());b("._cabulousCitiesSelectDiv").html(Cabulous.Partials.spinner());S+=29}var R=b("._cabulousControlContents div");b(R[0]).css("padding-top","11px");b(U).height(S);b(U).css("top","-"+S+"px");var N=null;function Q(){if(N!=null){clearTimeout(N);N=null}}function T(){b.getJSON("/extend/get_cities_with_online_cabbie_count?show_entity_ids=true&filter="+Cabulous.Shared.COMPANY_FILTER,function(Y){var W=b("._cabulousCitiesSelectDiv");b(W).html("");b(W).append("<select>");var X=b("._cabulousCitiesSelectDiv select");b(X).append("<option value=''>("+Cabulous.Language.select_a_city+")</option>");for(city in Y){var V=Y[city];b(X).append("<option value='"+V+"'>"+city+"</option>")}b(W).append("</select>");b(X).change(function(){var Z=b(this).val();if(Z==""){return}y.askForCabsByEntity(Z,Cabulous.Shared.COMPANY_FILTER);O()})})}b(U).mouseover(function(){Q();if(P==true){P=false;T();b(U).animate({top:"0px"},500)}}).mouseout(function(){if(N==null){N=setTimeout(function(){O()},2000)}});function O(){b(U).animate({top:"-"+S+"px"},500,function(){P=true;b("._cabulousCitiesSelectDiv").html(Cabulous.Partials.spinner())})}b("#_cabulous_center_map_location").keydown(function(V){Q();if(V.keyCode==13){b("#_cabulous_center_map_button").click()}});b("#_cabulous_center_map_button").click(function(){b("#_cabulous_wait2").css("visibility","visible");var V=b("#_cabulous_center_map_location").val();var W=new google.maps.Geocoder();W.geocode({address:V,bounds:E.getBounds()},function(Z,Y){if(Z.length>=1){var aa=Z[0].geometry.location.lat();var ab=Z[0].geometry.location.lng();var X=new google.maps.LatLng(aa,ab);E.setCenter(X);E.setZoom(15);O()}else{alert("Unable to find "+V)}b("#_cabulous_wait2").css("visibility","hidden")})})}if(h||e){C()}b(r).append(Cabulous.Partials.loadingUI());b("._cabulousLoadingDiv ._cabulousLoadingOpaque").css("opacity","0.75");var y=new Cabulous.Connection(r);Cabulous.Shared.CONNECTION=y.stropheConnection;function l(){var O=E.getCenter();var N={northLatitude:E.getBounds().getNorthEast().lat(),eastLongitude:E.getBounds().getNorthEast().lng(),southLatitude:E.getBounds().getSouthWest().lat(),westLongitude:E.getBounds().getSouthWest().lng()};y.listenWithinBounds(N)}var t=l;setInterval(l,15000);google.maps.event.addListener(E,"idle",l);var M=new Array();var D=null;function I(){var O=b(".hailForm :input[name=hail[pickup_location]]").val();if(O==""){o.setContent(Cabulous.Partials.noResultsFoundUI("empty address"));return}function N(R,Q){if(R.length>=1){var S=new Object();S.country_code=b(".hailForm :input[name='hail[country_code]']   ").val();S.phone_number=b(".hailForm :input[name='hail[phone_number]']   ").val();S.password=b(".hailForm :input[name='hail[password]']       ").val();S.notes_to_driver=b(".hailForm :input[name='hail[notes_to_driver]']").val();S.cab_jid=b(".hailForm :input[name='hail[cab_jid]']        ").val();S.pickup_location=R[0].formatted_address;S.latitude=R[0].geometry.location.lat();S.longitude=R[0].geometry.location.lng();o.setContent(Cabulous.Partials.confirmationFormUI(S))}else{o.setContent(Cabulous.Partials.noResultsFoundUI(O))}}var P=new google.maps.Geocoder();P.geocode({address:O,bounds:E.getBounds()},N)}function k(O,S){function R(W){return b(S).find(":input[name='hail["+W+"]']").val()}j();var Q=R("country_code");var V=R("phone_number");var U=R("password");var N={cab_jid:R("cab_jid"),latitude:R("latitude"),longitude:R("longitude"),pickup_location:R("pickup_location"),notes_to_driver:R("notes_to_driver"),country_code:Q,phone_number:V,password:U};function T(){var X=new google.maps.LatLng(parseFloat(R("latitude")),parseFloat(R("longitude")));if(D!=null){D.setPosition(X);D.setTitle(R("pickup_location"))}else{var W=new google.maps.Marker({position:X,map:E,title:R("pickup_location"),icon:"http://cabulous.com/images/cabulous-man-med.png"});D=W}function Z(ac,ah,ab,af){var ae=(ac<ab)?ac:ab;var ag=(ah<af)?ah:af;var ai=(ac>ab)?ac:ab;var aj=(ah>af)?ah:af;var aa=new google.maps.LatLng(ae,ag);var ad=new google.maps.LatLng(ai,aj);E.fitBounds(new google.maps.LatLngBounds(aa,ad))}var Y=M[H(Cabulous.Status.HAILING_CAB_JID)];if(Y!=undefined){Z(X.lat(),X.lng(),Y.position.lat(),Y.position.lng())}}T();function P(W,X){if(X.validPassword){N.passenger_jid=X.passenger_jid;b(r).unbind(Cabulous.Event.AUTHENTICATION_SUCCESS);b(r).bind(Cabulous.Event.AUTHENTICATION_SUCCESS,function(){J(N)});y.reconnectAsJid(N.passenger_jid,N.password)}else{n()}}b(r).unbind(Cabulous.Event.EXISTENT_ACCOUNT_FOUND);b(r).bind(Cabulous.Event.EXISTENT_ACCOUNT_FOUND,P);b(r).unbind(Cabulous.Event.ALREADY_LOGGED_IN);b(r).bind(Cabulous.Event.ALREADY_LOGGED_IN,function(W){J(N)});b(r).unbind(Cabulous.Event.NEW_ACCOUNT_CREATED);b(r).bind(Cabulous.Event.NEW_ACCOUNT_CREATED,function(){J(N)});b(r).bind(Cabulous.Event.HAIL_ACCEPTED,function(){v();A(Cabulous.Shared.LAST_CAB_CLICKED)});b(r).bind(Cabulous.Event.HAIL_DECLINED,function(){s();t()});b(r).bind(Cabulous.Event.HAIL_TIMEOUT,function(){w();t()});b(r).unbind(Cabulous.Event.SESSION_ENDED);b(r).bind(Cabulous.Event.SESSION_ENDED,function(){if(Cabulous.Status.PASSENGER_CANCELLING==false){f()}else{q()}t()});b(r).unbind(Cabulous.Event.NOT_AVAILABLE);b(r).bind(Cabulous.Event.NOT_AVAILABLE,function(){B();t()});b(r).unbind(Cabulous.Event.CLEAR_CABS_FOR_SESSION);b(r).bind(Cabulous.Event.CLEAR_CABS_FOR_SESSION,function(){var W=[];for(var Y in M){W.push(Y)}for(var X=0;X<W.length;X++){var Z=M[0];if(Z.jid==Cabulous.Status.HAILING_CAB_JID){var aa=M.shift();M.push(aa)}else{b(r).trigger(Cabulous.Event.CAB_REMOVED,{jid:Z.jid})}}t()});y.signInOrSignUp(Q,V,U)}function J(N){Cabulous.Status.LOGGED_IN=true;y.hail(N.cab_jid,N.latitude,N.longitude,N.pickup_location,N.notes_to_driver)}function j(){Cabulous.Status.MODE="hail";o.setContent(Cabulous.Partials.hailingScreen())}function v(){Cabulous.Status.MODE="posthail";o.setContent(Cabulous.Partials.hailSuccessPartial());var N=o.getContent();b(N).find("._cabulousEndPickup").bind("click",function(){if(confirm("Click OK to end your pickup session.")){b(N).find("._cabulousEndPickup").unbind("click");y.cancelHail(Cabulous.Status.SESSION_ID)}else{}})}function s(){Cabulous.Status.MODE="prehail";o.setContent(Cabulous.Partials.hailFailPartial())}function w(){Cabulous.Status.MODE="prehail";o.close();alert("The driver didn't respond in time...  Let's try and hail another!")}function f(){Cabulous.Status.MODE="prehail";alert("The cab driver has ended the pickup session");var N=o.getContent();b(N).unbind("click");b(N).find("._cabulousEndPickup").css("display","none")}function q(){Cabulous.Status.MODE="prehail";Cabulous.Status.PASSENGER_CANCELLING=false;alert("You have successfully ended the pickup session");var N=o.getContent();b(N).unbind("click");b(N).find("._cabulousEndPickup").css("display","none")}function n(){Cabulous.Status.MODE="prehail";o.close();alert("We were unable to log you in using this phone number and password.  If you would like to reset your password please call us at 1-415-683-7401.  Thank you!")}function B(){Cabulous.Status.MODE="prehail";o.close();var N=H(Cabulous.Status.HAILING_CAB_JID);if(N==-1){alert("Oops, looks like we just missed this cab.  Let's try and get another one.")}else{alert("Sorry, this cab is too far away to pick you up.")}}var o;var A=function(R){Cabulous.Shared.LAST_CAB_CLICKED=R;var O=H(R.jid);var N=M[O];if(o){o.close()}var Q={cab:R};Q.country_code=Q.country_code||"1";Q.phone="";Q.password="";Q.pickup="";Q.note="";var P=new google.maps.InfoWindow();o=P;Cabulous.Shared.INFO_WINDOW=P;if(Cabulous.Status.MODE=="prehail"){if(Cabulous.Status.IS_DISPATCH==false){P.setContent(Cabulous.Partials.initialHailingFormUI(Q));google.maps.event.addListener(P,"domready",function(){var T=P.getContent();b(T).find(".hailForm").bind("submit",function(){var U=b(T).find(".hailForm");Q.country_code=U.find("#hail_country_code").val();Q.phone=U.find("#hail_phone_number").val();Q.password=U.find("#hail_password").val();Q.pickup=U.find("#hail_pickup_location").val();Q.note=U.find("#hail_notes").val();I(P)});b(T).find(".pickupConfirmationForm").bind("submit",function(){Cabulous.Status.HAILING_CAB_PHONE=R.phone,Cabulous.Status.HAILING_CAB_JID=R.jid,k(P,this)});b(T).find(".noButton").bind("click",function(){o.setContent(Cabulous.Partials.initialHailingFormUI(Q))})})}else{dispatchShowBubble(y,N,P,Q)}}else{if(Cabulous.Status.MODE=="hail"){P.setContent(Cabulous.Partials.hailingScreen())}else{if(Cabulous.Status.MODE=="posthail"){v()}}}P.open(N.getMap(),N);function S(){if(o){o.close();Cabulous.Shared.LAST_CAB_CLICKED=null}}google.maps.event.clearListeners(E,"click");google.maps.event.addListener(E,"click",S)};function d(R,T){var U=new google.maps.LatLng(parseFloat(T.latitude)-0.00005,parseFloat(T.longitude));var P=H(T.jid);var S=(T.from_presence)?T.from_presence:false;var N=function(V){if(Cabulous.Status.IS_DISPATCH&&S==false){var X="green";var Y=T.id.replace(/ /gi,"");var W=4-Y.length;for(var Z=0;Z<W;Z++){Y="0"+Y}if(T.is_private=="true"){X="red"}V.setIcon("http://cabulous.com/webapp/cab_img.php?number="+Y+"&color="+X);b(V).data("is_private",T.is_private)}};if(P>-1){var Q=M[P].getPosition();if(Math.abs(Q.lat()-U.lat())>0.0001||Math.abs(Q.lng()-U.lng())>0.0001){M[P].setPosition(U)}N(M[P])}else{if(S==false){var O=new google.maps.Marker({position:U,map:E,title:T.title||"",icon:"http://cabulous.com/images/cab_"+T.image+".png"});O.jid=T.jid;N(O);M.push(O);google.maps.event.addListener(O,"click",function(){A(T)})}}}Cabulous.Shared.openHailingWindowOnMarker=A;function c(P,Q){var N=H(Q.jid);if(N>-1){var O=M[N];google.maps.event.clearListeners(O,"click");O.setMap(null);M.splice(N,1)}}function x(P,T){var S=T.split(",");var R=new Array();function N(V){for(var U=0;U<S.length;U++){if(V==S[U]){return true}}return false}for(var O=0;O<M.length;O++){var Q=M[O];if(N(Q.jid)==false){R.push(Q.jid)}}for(var O=0;O<R.length;O++){b(r).trigger(Cabulous.Event.CAB_REMOVED,{jid:R[O]})}}b(r).bind(Cabulous.Event.CAB_UPDATE,d);b(r).bind(Cabulous.Event.CAB_REMOVED,c);b(r).bind(Cabulous.Event.RECEIVED_JIDS,x);b(r).unbind(Cabulous.Event.AUTO_ZOOM);b(r).bind(Cabulous.Event.AUTO_ZOOM,function(){var T=10000;var P=10000;var U=-10000;var R=-10000;if(M.length>0){for(var Q=0;Q<M.length;Q++){var O=M[Q];if(O.position.lat()<T){T=O.position.lat()}if(O.position.lng()<P){P=O.position.lng()}if(O.position.lat()>U){U=O.position.lat()}if(O.position.lng()>R){R=O.position.lng()}}if(M.length==1){T-=0.003;P-=0.003;U+=0.003;R+=0.003}var N=new google.maps.LatLng(T,P);var S=new google.maps.LatLng(U,R);E.fitBounds(new google.maps.LatLngBounds(N,S))}else{if(F!=""){y.askForCabsByEntity(F,Cabulous.Shared.COMPANY_FILTER);F=""}}});function H(N){for(i in M){if(M[i].jid==N){return i}}return -1}b(r).unbind(Cabulous.Event.DISCONNECTED);b(r).bind(Cabulous.Event.DISCONNECTED,function(){var P=M.length;for(var O=0;O<P;O++){var N=M.shift();N.setMap(null);google.maps.event.clearListeners(N,"click")}});return this}})(jQuery);Cabulous={Event:{CAB_UPDATE:"cabulous:cab_update",AUTO_ZOOM:"cabulous:auto_zoom",CAB_REMOVED:"cabulous:cab_removed",RECEIVED_JIDS:"cabulous:received_jids",HAIL_ACCEPTED:"cabulous:hail_accepted",HAIL_DECLINED:"cabulous:hail_declined",HAIL_TIMEOUT:"cabulous:hail_timeout",NEW_ACCOUNT_CREATED:"cabulous:new_account_created_from_guest_jid",EXISTENT_ACCOUNT_FOUND:"cabulous:existent_account_found",AUTHENTICATION_SUCCESS:"cabulous:authentication_success",DISCONNECTED:"cabulous:disconnected",ALREADY_LOGGED_IN:"cabulous:already_logged_in",NOT_AVAILABLE:"cabulous:not_available",SESSION_ENDED:"cabulous:session_ended",CLEAR_CABS_FOR_SESSION:"cabulous:clear_cabs_for_session"},Status:{LOGGED_IN:false,HAILING_CAB_PHONE:"",HAILING_CAB_JID:"",MODE:"prehail",SESSION_ID:"",PASSENGER_CANCELLING:false,IS_REFRESHING:false,AUTO_ZOOM_REFRESH:false,IS_DISPATCH:false,PASSENGER_JID:null,PASSENGER_PASS:null},Shared:{CONNECTION:null,MAP:null,INFO_WINDOW:null,COMPANY_FILTER:""}};Cabulous.Connection=function(a){this.mapElement=a;this.stropheConnection=Cabulous.ConnectionFactory.createConnection();this.eventDispatcher=new EventDispatcher(this.mapElement)};Cabulous.Connection.prototype.askForNewListOfCabs=function(b){var a=Cabulous.QueryBuilder.buildGetNearbyCabbies(b);this.stropheConnection.send(a);Cabulous.Status.IS_REFRESHING=true};Cabulous.Connection.prototype.askForCabsByEntity=function(b,a){var c=Cabulous.QueryBuilder.buildGetCabsByEntity(b,a);this.stropheConnection.send(c)};Cabulous.Connection.prototype.listenWithinBounds=function(d){var b=this;var a=function(e){if(e==Strophe.Status.CONNECTED||e==Strophe.Status.ATTACHED){if(Cabulous.Status.IS_DISPATCH){addDispatchHandlers();Cabulous.Dispatch.Queue.start();syncQueue()}b.askForNewListOfCabs(d)}else{if(e==Strophe.Status.CONNFAIL||e==Strophe.Status.AUTHFAIL||e==Strophe.Status.ERROR){if(Cabulous.Status.PASSENGER_JID==null){b.stropheConnection.disconnect();b.connected=false;setTimeout(function(){c()},700)}}}};var c=function(){Cabulous.Connection.Utils.proxyStropheEvents(b.stropheConnection,b.eventDispatcher);if(Cabulous.Status.IS_DISPATCH==false){if(Cabulous.Status.PASSENGER_JID!=null){b.authenticate(Cabulous.Status.PASSENGER_JID,Cabulous.Status.PASSENGER_PASS)}else{b.connectAsGuest(a)}}else{b.eventDispatcher.trigger(Cabulous.Event.DISCONNECTED);b.getDispatchInfoAndLogin(a)}b.connected=true};if(this.connected){b.askForNewListOfCabs(d)}else{c()}};Cabulous.Connection.prototype.connectAsGuest=function(a){var b=this;$.get("/http-prebind/webapp_guest",function(d){var c=d.split("\n");b.stropheConnection.attach(c[0],c[1],c[2],a)})};Cabulous.Connection.prototype.getDispatchInfoAndLogin=function(a){var c=this;var b=new Date();$.getJSON("/extend/get_dispatch_info?"+b.getTime(),function(d){initDispatch(d,function(){Cabulous.Dispatch.BOX_IDS="row"+d.jid;var e="dispatch"+b.getTime();Cabulous.Dispatch.RESOURCE=e;$.get("/http-prebind/dispatch/"+d.jid+"/"+e+"/"+d.key,function(g){var f=g.split("\n");c.stropheConnection.attach(f[0],f[1],f[2],a)})})})};Cabulous.Connection.prototype.signInOrSignUp=function(b,a,c){this.stropheConnection.send(Cabulous.QueryBuilder.registerGuestAsUser(b,a,c))};Cabulous.Connection.prototype.hail=function(d,e,b,f,a){var c=Cabulous.QueryBuilder.buildAttemptSession(d,e,b,f,a);this.stropheConnection.send(c)};Cabulous.Connection.prototype.dispatchHail=function(g,d,e,c,f,b,a){var h=Cabulous.QueryBuilder.buildAttemptDispatchSession(g,d,e,c,f,b,a);this.stropheConnection.send(h)};Cabulous.Connection.prototype.cancelHail=function(b){var a=Cabulous.QueryBuilder.buildCancelHail(b);Cabulous.Status.PASSENGER_CANCELLING=true;this.stropheConnection.send(a)};Cabulous.Connection.prototype.reconnectAsJid=function(b,a){Cabulous.Status.PASSENGER_JID=b;Cabulous.Status.PASSENGER_PASS=a;this.stropheConnection.disconnect();this.stropheConnection=Cabulous.ConnectionFactory.createConnection();Cabulous.Connection.Utils.proxyStropheEvents(this.stropheConnection,this.eventDispatcher);this.authenticate(b,a)};Cabulous.Connection.prototype.authenticate=function(c,b){var a=this;a.authReceivedResponse=false;var d=function(){a.authAttempt=$.get("/http-prebind/webapp/"+c+"/webapp/"+b,function(f){a.authReceivedResponse=true;clearInterval(a.attemptCheckInterval);var e=f.split("\n");a.stropheConnection.attach(e[0],e[1],e[2],function(g){var h=0;if(g==Strophe.Status.ATTACHED){a.eventDispatcher.trigger(Cabulous.Event.AUTHENTICATION_SUCCESS)}else{if(g==Strophe.Status.CONNFAIL||g==Strophe.Status.AUTHFAIL||g==Strophe.Status.ERROR){setTimeout(function(){a.authenticate(c,b)},500)}}})})};d();a.attemptCheckInterval=setInterval(function(){if(a.authReceivedResponse==false){a.authAttempt.abort();d()}},3000)};Cabulous.Connection.prototype.getCompaniesForCity=function(b){var a=Cabulous.QueryBuilder.buildCabulousQueryForCompanies(b);this.stropheConnection.send(a)};Cabulous.Connection.Utils={};Cabulous.Connection.Utils.proxyStropheEvents=function(c,a){function b(d){var e=$(d).find("type").text();var g=($(d).find("not-a-guest").length===1);if(g){a.trigger(Cabulous.Event.ALREADY_LOGGED_IN)}else{if(e==="existent_account"){var f={passenger_jid:$(d).find("jid").text(),validPassword:($(d).find("valid_password").text()==="true")};a.trigger(Cabulous.Event.EXISTENT_ACCOUNT_FOUND,f)}else{if(e==="new_account"){a.trigger(Cabulous.Event.NEW_ACCOUNT_CREATED)}}}return true}c.addHandler($.proxy(a,"triggerCabUpdatesForEachItem"),null,"iq","result","get_nearby_cabbies","localhost");c.addHandler($.proxy(a,"triggerEntityGetResult"),null,"iq","result","get_entity_cabbies","localhost");c.addHandler($.proxy(a,"triggerCabUpdateForPresence"),"jabber:iq:cabbie:update","presence",null,null,"localhost");c.addHandler($.proxy(a,"triggerItemUpdateForPresence"),null,"presence",null,"item_presence",null,null,"localhost");c.addHandler($.proxy(a,"triggerCabRemovedForPresence"),null,"presence",null,"goodbye_cabbie","localhost");c.addHandler($.proxy(a,"triggerHailAccepted"),null,"iq",null,"hail_accepted","localhost");c.addHandler($.proxy(a,"triggerHailDeclined"),null,"iq",null,"other_party_canceled","localhost");c.addHandler($.proxy(a,"triggerHailTimeout"),null,"iq",null,"session_hail_timeout","localhost");c.addHandler(b,null,"iq",null,"convert_guest","localhost");c.addHandler($.proxy(a,"triggerSessionEnded"),null,"iq",null,"end_session","localhost");c.addHandler($.proxy(a,"triggerAttemptSession"),null,"iq",null,"attempt_session","localhost");c.addHandler($.proxy(a,"triggerCabulousQueryCompanies"),null,"iq","result","companies_query","localhost")};Cabulous.ConnectionFactory={createJidConnection:function createJidConnection(){return new Strophe.Connection("/http-bind/")},createConnection:function createConnection(){return new Strophe.Connection("/http-bind/")}};Cabulous.QueryBuilder={buildGetNearbyCabbies:function(a){return $iq({id:"get_nearby_cabbies",type:"get",to:"localhost"}).c("query",{xmlns:"jabber:iq:public:presence:get"}).c("options",{hailing_nearest:"false",including_outside:"false"}).up().c("filter",{company:Cabulous.Shared.COMPANY_FILTER}).up().c("upper_left").t(a.southLatitude+","+a.westLongitude).up().c("lower_right").t(a.northLatitude+","+a.eastLongitude).tree()},buildGetCabsByEntity:function(b,a){return $iq({id:"get_entity_cabbies",type:"get",to:"localhost"}).c("query",{xmlns:"jabber:iq:entity:get"}).c("parameters",{entity_id:b,filter:a}).tree()},buildRegisterGuest:function(){return $iq({id:"register_guest",type:"set",to:"localhost"}).c("query",{xmlns:"jabber:iq:register:cabulous"}).c("username").t("guest").up().c("password").t("random").up().c("device").t("webapp").tree()},registerGuestAsUser:function(b,a,c){return $iq({to:"localhost",type:"set",id:"convert_guest"}).c("query",{xmlns:"jabber:iq:register:cabulous"}).c("password").t(c).up().c("role").t("user").up().c("phone").t(a).up().c("cc").t(b).tree()},buildAttemptSession:function(b,e,c,d,a){return $iq({to:"localhost",type:"set",id:"attempt_session"}).c("query",{xmlns:"jabber:iq:cabulous:session"}).c("for").t(b).up().c("location",{latitude:e,longitude:c,is_using_gps:0,start:d,end:a}).tree()},buildAttemptDispatchSession:function(g,d,e,c,f,b,a){return $iq({to:"localhost",type:"set",id:"attempt_session"+a}).c("query",{xmlns:"jabber:iq:cabulous:session"}).c("queue_item_id").t(g).up().c("for").t(d).up().c("location",{latitude:e,longitude:c,is_using_gps:0,start:f,end:b}).up().c("dispatch",{passenger_phone:a}).tree()},buildCancelHail:function(a){return $iq({to:"localhost",type:"set",id:"end_session"}).c("query",{xmlns:"jabber:iq:cabulous:session"}).c("session").t(a).up()},buildCancelUnacceptedHail:function(a){return $iq({to:"localhost",type:"set",id:"user_cancel_session"}).c("query",{xmlns:"jabber:iq:cabulous:session"}).c("session_id").t(a).up()},buildCabulousQueryForCompanies:function(a){return $iq({to:"localhost",type:"set",id:"companies_query"}).c("query",{xmlns:"jabber:iq:cabulous:query"}).c("type").t("company").up().c("q",{field:"city"}).t(a).up().c("sort").t("true").up().c("online").t("true").up()},buildCreateNewQueue:function(a){return $iq({to:"localhost",type:"set",id:"create_new_queue"}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("add_queue").c("name").t(a).up()},buildRegisterForQueue:function(a){return $iq({to:"localhost",type:"set",id:"register_for_queue"}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("register").c("queue_id").t(a).up()},buildAddItemToQueue:function(g,f,b,a,d,e,c){return $iq({to:"localhost",type:"set",id:g}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("add_item").c("queue_id").t(f).up().c("passenger_address").t(b).up().c("passenger_phone").t(a).up().c("note").t(d).up().c("passenger_lat").t(e).up().c("passenger_lng").t(c).up()},buildDeleteItemFromQueue:function(b,a){return $iq({to:"localhost",type:"set",id:b}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("remove_item").c("item_id").t(a).up()},buildUpdateItemInQueue:function(d,b,c,a){return $iq({to:"localhost",type:"set",id:d}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("update_item").c("item_id").t(b).up().c(c).t(a).up()},buildEditItemInQueue:function(c,b,a){return $iq({to:"localhost",type:"set",id:c}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("update_item").c("item_id").t(b).up().c("passenger_address").t(a.passenger_address).up().c("passenger_phone").t(a.passenger_phone).up().c("passenger_lat").t(a.passenger_lat).up().c("passenger_lng").t(a.passenger_lng).up().c("note").t(a.note).up()},buildGetPageInHistory:function(d,c,b,a){return $iq({to:"localhost",type:"get",id:"get_history"}).c("query",{xmlns:"jabber:iq:cabulous:queue"}).c("from").t(d).up().c("to").t(c).up().c("page").t(b).up().c("page_size").t(a).up()}};(function(){Cabulous.Partials={};Cabulous.Partials.Styles={};var a=["font-family : Arial,Helvetica,sans-serif;","font-size : 12px;","color : #000;","text-align: left;","float: none;"];Cabulous.Partials.Styles.loadingPartialStyle=["position: absolute;","width: 100%;","height: 100%;","background-color: #000;","z-index: 100;","display: block;"].concat(a).join(" ");Cabulous.Partials.Styles.loadingPartialText=a.concat(["position: absolute;","left: 50%;","margin-left: -40px;","top: 46%;","color: #ddd;","font-size: 18px;","z-index:101"]).join(" ");Cabulous.Partials.Styles.disconnectedPartialText=a.concat(["position: absolute;","left: 50%;","margin-left: -155px;","top: 38%;","color: #ddd;","font-size: 18px;","z-index:101;"]).join(" ");Cabulous.Partials.Styles.controlOverlayPartialStyle=a.concat(["position:absolute;","width:100%;","height:0px;","top:0px;","z-index:90;","display:block;",]).join(" ");Cabulous.Partials.Styles.controlContentsStyle=["position:absolute;","width:100%;","height:100%;","background-color:#000;","z-index:130;","display:block;",].concat(a).join(" ");Cabulous.Partials.Styles.controlOverlayLabel=a.concat(["font-size:15px;","color:#fff;","font-weight:normal;"]).join(" ");Cabulous.Partials.Styles.controlOverlayContentsDivStyle=a.concat(["padding-top:0px;","padding-left:20px;","padding-right:20px;","padding-bottom:7px;","color:#fff;","font-size:16px;","line-height:18px;"]).join(" ");Cabulous.Partials.Styles.infoContentStyle=["padding-bottom: 1em;","float: left;","width: 300px;"].concat(a).join(" ");Cabulous.Partials.Styles.hailFormStyle=["float: left;width:160px;"];Cabulous.Partials.Styles.cabbieName=["font-size: 14px;font-weight:bold;"];Cabulous.Partials.Styles.cabbieSubtitle=["color:#888;"];Cabulous.Partials.Styles.cabbiePhone=["color:#888;"];Cabulous.Partials.Styles.cabbieNotes=["color:#444;padding-top:5px;"];Cabulous.Partials.Styles.label=["display: block;color:#444;margin-top:5px;"];Cabulous.Partials.Styles.labelIcon=["padding-left:18px;margin-top:0;height:14px;padding-top:3px;"];Cabulous.Partials.Styles.p=["padding: 0;",].concat(a).join(" ");Cabulous.Partials.Styles.phoneInput=["width: 10em;"].concat(a).join(" ");Cabulous.Partials.Styles.countryCode=["width: 2em;","text-align: right;"].concat(a).join(" ");Cabulous.style=function(c){return Cabulous.Partials.Styles[c]};Jaml.register("loadingPartial",function(){div({style:"position:absolute;width:100%;height:100%;z-index:99;","class":"_cabulousLoadingDiv"},div({style:Cabulous.style("loadingPartialStyle"),"class":"_cabulousLoadingOpaque"}),div({style:Cabulous.style("loadingPartialText")},Cabulous.Language.loading+"..."),img({src:"http://cabulous.com/images/wait.gif",style:"position:absolute;left:50%; margin-left:-110px;top:47%;margin-top:20px;z-index:101;"}))});Jaml.register("disconnectedPartial",function(){div({style:"position:absolute;width:100%;height:100%;z-index:99;","class":"_cabulousDisconnectedDiv"},div({style:Cabulous.style("loadingPartialStyle"),"class":"_cabulousLoadingOpaque"}),div({style:Cabulous.style("disconnectedPartialText")},"Oops!  We've lost contact with the server.<br/>Please click below to reload the map."),input({type:"button",id:"_cabulousReloadButton",value:"Reload",style:"position:absolute;left:50%; margin-left:-30px;top:47%;margin-top:20px;z-index:101;"}))});Jaml.register("controlOverlayPartial",function(){div({style:Cabulous.style("controlOverlayPartialStyle"),"class":"_cabulousControlOverlay"},div({style:Cabulous.style("controlContentsStyle"),"class":"_cabulousControlContents"}),img({src:"http://cabulous.com/images/search2.png",style:"position:absolute;top:102%;left:50%;margin-left:-15px;","class":"_cabulousDownArrowBox"}))});Jaml.register("controlOverlayContentsSearch",function(){div({style:Cabulous.style("controlOverlayContentsDivStyle"),"class":"_cabulousControlOverlayContentsSearch"},label({"for":"_cabulous_center_map_location",style:Cabulous.style("controlOverlayLabel")+"float:none;"},Cabulous.Language.search_by_address+" "),input({type:"text",id:"_cabulous_center_map_location",style:"margin-left:5px;font-size:12px;width:295px;"}),input({type:"button",id:"_cabulous_center_map_button",style:"font-size:13px;width:70px;",value:Cabulous.Language.search}),img({src:"/images/wait2.gif",id:"_cabulous_wait2",style:"padding-left:10px;top:5px;visibility:hidden;"}))});Jaml.register("controlOverlayContentsLiveCabCities",function(){div({style:Cabulous.style("controlOverlayContentsDivStyle"),"class":"_cabulousControlOverlayContentsLiveCabCities"},label({"for":"_cabulousCitiesSelectDiv",style:Cabulous.style("controlOverlayLabel")+"float:left;padding-right:10px;"},Cabulous.Language.available_cabs_by_city),div({"class":"_cabulousCitiesSelectDiv",style:"padding:0;margin-top:0px;font-size:15px;"}))});Jaml.register("spinner",function(){img({src:"/images/wait2.gif",style:"padding-left:10px;top:5px;"})});Jaml.register("controlOverlayContentsCompanies",function(){div({style:Cabulous.style("controlOverlayContentsDivStyle"),"class":"_cabulousControlOverlayContentsCompanies"},label({"for":"_cabulousCompaniesDiv",style:"float:none;font-size:18px;color:#fff;font-weight:normal;"},"Display Cabs for Companies: "),div({style:"margin-top:7px;height:65px;overflow-y:auto;font-size:16px;","class":"_cabulousCompaniesDiv"}))});Jaml.register("initialHailingFormPartial",function(e){var d=Cabulous.Status.LOGGED_IN==true?"none":"block";if(decodeURIComponent(e.cab.id)!="0001"){var c=decodeURIComponent(e.cab.subtitle)+" #"+decodeURIComponent(e.cab.id)}else{var c=decodeURIComponent(e.cab.subtitle)}if(decodeURIComponent(unescape(e.cab.more_info))!=""){var f="Notes: "+decodeURIComponent(unescape(e.cab.more_info))}else{var f=""}div({style:Cabulous.style("infoContentStyle")},div({"class":"cabInfo",style:"margin-bottom: 1em; float:left;width:130px;min-height:110px;padding-right:5px;"},div({style:Cabulous.style("cabbieName")+"background:url(http://cabulous.com/images/cab_"+e.cab.image+".png) 0 -10px no-repeat;padding-left:33px;"},decodeURIComponent(e.cab.title)),div({style:Cabulous.style("cabbieSubtitle")},c),div({style:Cabulous.style("cabbiePhone")},decodeURIComponent(e.cab.phone)),div({style:Cabulous.style("cabbieNotes")},f)),div({style:Cabulous.style("hailFormStyle")},form({"class":"hailForm",onsubmit:"return false;"},label({"for":"hail_pickup_location",style:Cabulous.style("label")+Cabulous.style("labelIcon")+"background:url(/images/map.png) 0 0 no-repeat;"},Cabulous.Language.pickup_location),input({type:"text",id:"hail_pickup_location","class":"pickupLocation",style:"width:155px;",name:"hail[pickup_location]",value:e.pickup}),span({"class":"login_span",style:"display: "+d},label({"for":"hail_country_code",style:"display: none"},"Country Code"),label({"for":"hail_phone_number",style:Cabulous.style("label")+Cabulous.style("labelIcon")+"background:url(/images/phone.png) 0 0 no-repeat;"},Cabulous.Language.your_phone_number),input({type:"text",id:"hail_country_code",name:"hail[country_code]",value:e.country_code,style:Cabulous.style("countryCode")}),input({type:"text",id:"hail_phone_number",name:"hail[phone_number]",value:e.phone,style:Cabulous.style("phoneInput")}),input({type:"hidden",id:"hail_password",name:"hail[password]",value:e.password})),label({"for":"hail_notes","class":"forTextarea",style:Cabulous.style("label")+Cabulous.style("labelIcon")+"background:url(/images/pencil.png) 0 0 no-repeat;"},Cabulous.Language.note_for_driver),input({type:"text",id:"hail_notes","class":"note",style:"width:155px",name:"hail[notes_to_driver]",value:e.note}),input({type:"hidden",id:"cab_jid",name:"hail[cab_jid]"}),input({type:"submit","class":"submit",style:"float:right;",value:Cabulous.Language.lets_go}))))});Jaml.register("confirmationFormPartial",function(c){div({style:Cabulous.style("infoContentStyle")},div({style:"font-size:14px;font-weight:bold;"},Cabulous.Language.please_verify_your_information),form({"class":"pickupConfirmationForm",onsubmit:"return false;"},div({style:Cabulous.style("labelIcon")+"background:url(/images/map.png) 0 0 no-repeat;color:#444;"},Cabulous.Language.pickup_location),div({style:"padding-top:5px;"},c.pickup_location),div({style:Cabulous.style("labelIcon")+"background:url(/images/pencil.png) 0 0 no-repeat;color:#444;margin-top:10px;"},Cabulous.Language.notes),div({style:"padding-top:5px;"},c.notes_to_driver),input({type:"hidden",name:"hail[country_code]"}),input({type:"hidden",name:"hail[phone_number]"}),input({type:"hidden",name:"hail[password]"}),input({type:"hidden",name:"hail[pickup_location]"}),input({type:"hidden",name:"hail[notes_to_driver]"}),input({type:"hidden",name:"hail[cab_jid]"}),input({type:"hidden",name:"hail[latitude]"}),input({type:"hidden",name:"hail[longitude]"}),p({style:Cabulous.style("p")},input({type:"button","class":"noButton",value:"&laquo; "+Cabulous.Language.go_back}),input({type:"submit","class":"submit",value:Cabulous.Language.hail_a_cab}))))});Jaml.register("hailSuccessPartial",function(){var c=Cabulous.Status.HAILING_CAB_PHONE;div({style:Cabulous.style("infoContentStyle")},p({style:Cabulous.style("p")},"Accepted! Your driver will be there shortly.  If you need to contact them you can reach them at "+Cabulous.Status.HAILING_CAB_PHONE),input({type:"button","class":"_cabulousEndPickup",value:"End Pickup"}))});Jaml.register("hailFailPartial",function(){div({style:Cabulous.style("infoContentStyle")},p({style:Cabulous.style("p")},"The driver declined. Please choose another cab."))});Jaml.register("noResultsFoundPartial",function(c){if(c!="empty address"&&c!=""){div({style:Cabulous.style("infoContentStyle")},h2(Cabulous.Language.hold_on),p({style:Cabulous.style("p")},Cabulous.Language.no_results_found_for+': "'+c+'"'),p({style:Cabulous.style("p")},input({type:"button","class":"noButton",value:"&laquo; "+Cabulous.Language.go_back})))}else{div({style:Cabulous.style("infoContentStyle")},h2(Cabulous.Language.hold_on),p({style:Cabulous.style("p")},Cabulous.Language.please_enter_your_location),p({style:Cabulous.style("p")},input({type:"button","class":"noButton",value:"&laquo; "+Cabulous.Language.go_back})))}});Jaml.register("hailingScreenPartial",function(){p({style:Cabulous.style("p")},"Hailing...")});function b(d,e){var f=$(Jaml.render(d,e)).get(0);for(var c in e){$(f).find(":input[name='hail["+c+"]']").val(e[c])}return f}Cabulous.Partials.loadingUI=function(){return $(Jaml.render("loadingPartial")).get(0)};Cabulous.Partials.disconnectedUI=function(){return $(Jaml.render("disconnectedPartial")).get(0)};Cabulous.Partials.controlOverlayUI=function(){return $(Jaml.render("controlOverlayPartial")).get(0)};Cabulous.Partials.controlOverlaySearchUI=function(){return $(Jaml.render("controlOverlayContentsSearch")).get(0)};Cabulous.Partials.controlOverlayContentsLiveCabCitiesUI=function(){return $(Jaml.render("controlOverlayContentsLiveCabCities")).get(0)};Cabulous.Partials.spinner=function(){return $(Jaml.render("spinner")).get(0)};Cabulous.Partials.controlOverlayCompaniesUI=function(){return $(Jaml.render("controlOverlayContentsCompanies")).get(0)};Cabulous.Partials.initialHailingFormUI=function(c){var d=b("initialHailingFormPartial",c);$(d).find(":input[name='hail[cab_jid]']").val(c.cab.jid);return d};Cabulous.Partials.confirmationFormUI=function(c){return b("confirmationFormPartial",c)};Cabulous.Partials.noResultsFoundUI=function(c){return $(Jaml.render("noResultsFoundPartial",c)).get(0)};Cabulous.Partials.hailSuccessPartial=function(){return $(Jaml.render("hailSuccessPartial")).get(0)};Cabulous.Partials.hailFailPartial=function(){return $(Jaml.render("hailFailPartial")).get(0)};Cabulous.Partials.hailingScreen=function(){return $(Jaml.render("hailingScreenPartial")).get(0)}})();Cabulous.ConnectionFactory={createJidConnection:function createJidConnection(){return new Strophe.Connection("/http-bind/")},createConnection:function createConnection(){return new Strophe.Connection("/http-bind/")}};function EventDispatcher(a){this.element=a}EventDispatcher.prototype.triggerCabUpdatesForEachItem=function(c){Cabulous.Status.IS_REFRESHING=false;var b=this;var a=$(c).find("items item");var d="";a.each(function(){var e=$(this);var g=e.attr("type");if(g==="cabbie"){var f;f=Cabulous.CabFactory.stanzaItemToCab(e);$(b.element).trigger(Cabulous.Event.CAB_UPDATE,f);if(d!=""){d+=","}d+=f.jid}});$(b.element).trigger(Cabulous.Event.RECEIVED_JIDS,d);if($("._cabulousLoadingDiv").css("display")=="block"){$(b.element).trigger(Cabulous.Event.AUTO_ZOOM);$("._cabulousLoadingDiv").animate({opacity:"0.0"},300,function(){$("._cabulousLoadingDiv").css("display","none")})}if(Cabulous.Status.AUTO_ZOOM_REFRESH){$(b.element).trigger(Cabulous.Event.AUTO_ZOOM);Cabulous.Status.AUTO_ZOOM_REFRESH=false}return true};EventDispatcher.prototype.trigger=function(a,b){if(b){$(this.element).trigger(a,b)}else{$(this.element).trigger(a)}return true};EventDispatcher.prototype.triggerEntityGetResult=function(a){this.triggerCabUpdatesForEachItem(a);$(this.element).trigger(Cabulous.Event.AUTO_ZOOM);return true};EventDispatcher.prototype.triggerCabUpdateForPresence=function(a){var b={from_presence:true,jid:$(a).find("for").text(),latitude:$(a).find("latitude").text(),longitude:$(a).find("longitude").text(),accuracy:$(a).find("accuracy").text()};$(this.element).trigger(Cabulous.Event.CAB_UPDATE,b);return true};EventDispatcher.prototype.triggerItemUpdateForPresence=function(a){var b={jid:$(a).find("from").text(),latitude:$(a).find("location").find("latitude").text(),longitude:$(a).find("location").find("longitude").text(),accuracy:$(a).find("location").find("accuracy").text()};$(this.element).trigger(Cabulous.Event.CAB_UPDATE,b);return true};EventDispatcher.prototype.triggerCabRemovedForPresence=function(a){var b={jid:$(a).find("for").text()};$(this.element).trigger(Cabulous.Event.CAB_REMOVED,b);return true};EventDispatcher.prototype.triggerHailAccepted=function(a){if(Cabulous.Status.IS_DISPATCH){dispatchHailingUpdateReceived(a,"hail_accepted")}else{$(this.element).trigger(Cabulous.Event.HAIL_ACCEPTED)}return true};EventDispatcher.prototype.triggerHailDeclined=function(a){if(Cabulous.Status.IS_DISPATCH){dispatchHailingUpdateReceived(a,"hail_declined")}else{$(this.element).trigger(Cabulous.Event.HAIL_DECLINED)}return true};EventDispatcher.prototype.triggerHailTimeout=function(a){if(Cabulous.Status.IS_DISPATCH){dispatchHailingUpdateReceived(a,"hail_timeout")}else{$(this.element).trigger(Cabulous.Event.HAIL_TIMEOUT)}return true};EventDispatcher.prototype.triggerAttemptSession=function(b){var a=$(b).find("session");var c=$(a).attr("id");if(c=="not_available"){$(this.element).trigger(Cabulous.Event.NOT_AVAILABLE)}else{Cabulous.Status.SESSION_ID=c;$(this.element).trigger(Cabulous.Event.CLEAR_CABS_FOR_SESSION)}return true};EventDispatcher.prototype.triggerCabulousQueryCompanies=function(a){};EventDispatcher.prototype.triggerSessionEnded=function(a){if(Cabulous.Status.IS_DISPATCH){dispatchHailingUpdateReceived(a,"hail_end")}else{$(this.element).trigger(Cabulous.Event.SESSION_ENDED)}return true};Cabulous.CabFactory={stanzaItemToCab:function stanzaItemToCab(b){var c={};var a=["jid","title","subtitle","image","latitude","longitude","accuracy","present_status","is_private","is_fav","id","more_info","phone","name"];$.each(a,function(){var d=this.toString();var e=b.attr(d);if(d=="phone"){e=e.replace("+1-","");e=Cabulous.CabFactory.formatPhoneStr(e)}c[d]=e});return c},formatPhoneStr:function(a){var c=a.replace(/[^0-9xX]/g,"");c=c.replace(/[xX]/g,"x");var b="";if(c.indexOf("x")>-1){b=" "+c.substr(c.indexOf("x"));c=c.substr(0,c.indexOf("x"))}switch(c.length){case (10):return c.replace(/(...)(...)(....)/g,"($1) $2-$3")+b;case (11):if(c.substr(0,1)=="1"){return c.substr(1).replace(/(...)(...)(....)/g,"($1) $2-$3")+b}break;default:}return a}};