if(!($.chug)){$.chug={};$.ajaxSetup({cache:false,type:"GET",url:"/proxy.php",dataType:"json",contentType:"application/json; charset=utf-8"})}$.chug.fb={_statusChangeListeners:[],_currentStatus:false,_currentMe:false,_nextHash:false,_initialized:false,init:function(){FB.init({appId:"140474059340080",status:true,cookie:true,xfbml:true,oauth:true});FB.Event.subscribe("auth.authResponseChange",$.chug.fb._sessionChange);FB.getLoginStatus(function(a){$.chug.fb._initialized=true;$.chug.fb._currentStatus=a;if(a.authResponse){$.chug.fb._resolveAccount(a.authResponse);$.chug.fb._flagFBUser();$.chug.fb._fireStatusChange(a)}if($.chug.fb._nextHash){window.location.hash=$.chug.fb._nextHash}})},_sessionChange:function(a){$.chug.fb._currentStatus=a;if(a.authResponse){$.chug.fb._resolveAccount(a.authResponse);$.chug.fb._flagFBUser();FB.api("/me",function(b){$.chug.fb._gotAccountDetails(b)})}$.chug.fb._fireStatusChange(a)},_authResponseChange:function(a){$.chug.fb._currentStatus=a;if(a.authResponse){$.chug.fb._resolveAccount(a.authResponse);$.chug.fb._flagFBUser();FB.api("/me",function(b){$.chug.fb._gotAccountDetails(b)})}$.chug.fb._fireStatusChange(a)},loginStatus:function(a){if($.chug.fb._currentStatus){a($.chug.fb._currentStatus)}else{$.chug.fb._forceGetLoginStatus(a)}},_forceGetLoginStatus:function(b){try{FB.getLoginStatus(function(c){if(c.authResponse){$.chug.fb._flagFBUser()}$.chug.fb._currentStatus=c;b(c)},true)}catch(a){b({})}},accountDetails:function(a){if($.chug.fb._currentMe){a($.chug.fb._currentMe)}else{FB.api("/me",function(b){$.chug.fb._gotAccountDetails(b);a(b)})}},shareCar:function(a,b,c){$.chug.fb._loadCarDetails(a,b,function(){if(b=="dealer"){var e=$.chug.json.carDetails;var h=e.getYear()+" "+e.getMake()+" "+e.getModel();var f=e.getDesign();if(f&&f!=""){h+=" "+f}var g="Seller: "+e.getDealerName()+", "+e.getDealerCity()+", "+e.getDealerState();var j=document.location.protocol+"//"+document.location.host+e.getDetailsURL();var i=e.getMainPhotoURL();var d="chug.net";FB.ui({method:"feed",name:h,link:j,picture:i,caption:d,description:g},function(k){if(!$.chug.fb._currentMe||!$.chug.fb._currentMe.email){$.chug.fb._forceGetLoginStatus(function(){})}if(c){c(k)}})}else{if(b=="private"){}}})},onStatusChange:function(a){$.chug.fb._statusChangeListeners.push(a)},setLocationHash:function(a){if($.chug.fb._initialized){window.location.hash=a}else{$.chug.fb._nextHash=a}},login:function(a){FB.login(a,{scope:"email"})},_fireStatusChange:function(b){for(var a=0;a<$.chug.fb._statusChangeListeners.length;a++){var c=$.chug.fb._statusChangeListeners[a];c(b)}if($.chug.events){if(b.authResponse){$.chug.fb.accountDetails(function(d){$.chug.events.fire("user","fb",{user:d})})}else{$.chug.events.fire("user","fb",{user:{}})}}},_gotAccountDetails:function(a){if(a.name&&a.name!=""){var b=a.name.split(" ");a.firstName=b.shift();a.lastName=b.join(" ");$.chug.json.saveUserEmail($.chug.util.currentUserId(),a.email,a.firstName,a.lastName)}else{if(a.email&&a.email!=""){$.chug.json.saveUserEmail($.chug.util.currentUserId(),a.email,"","")}}$.chug.fb._currentMe=a},_flagFBUser:function(){$.chug.util.getUserPrefs();$.chug.util.setUserPref("useFacebookSession",true)},_resolveAccount:function(b){if((!b)||(!b.userID)){return}var a=$.chug.util.currentUserId();$.chug.json.getUserAccountByFBId(b.userID,function(c){if(c&&c.userAccount&&c.userAccount.user){var d=c.userAccount.user;if(d!=a){document.cookie="user="+d}}else{$.chug.json.saveUserFBId(a,b.userID)}})},_loadCarDetails:function(h,e,g){var b=$.chug.json.carDetailsResponse.carInfo;if(b&&$.chug.json.carDetails.getCarID()==h&&$.chug.json.carDetails.getListingType()){g();$.chug.json.carDetailsResponse.carInfo=b}else{var d=$.chug.json.relativeSearchResponse;if(d&&d.data&&d.data.length){for(var c=0;c<d.data.length;c++){var a=d.data[c];var f=a.source?a.source.toLowerCase():"";if(a.id==h&&(e=="dealer"||(f=="private"||f=="craigslist"))){$.chug.json.setCarDetailsResponse(a);g();$.chug.json.carDetailsResponse.carInfo=b;return}}}$.chug.json.getCarDetailsBySellerType(null,h,e,function(i){g();$.chug.json.carDetailsResponse.carInfo=b})}},_updateFBId:function(b,a,c){$.chug.json.setFaceBookOwnerForFSBO(b,a,c)}};window.fbAsyncInit=$.chug.fb.init;$(function(){var a=document.createElement("script");a.type="text/javascript";a.src=document.location.protocol+"//connect.facebook.net/en_US/all.js";a.async=true;$("#fb-root").append(a)});
