(function($) {

hizzou_core.loadCurrentUserData = function (forced) {
    
    if (!hizzou_core.isUserLoggedIn && !forced) {
        hizzou_core.current_user = null;
        return;
    }

    if (hizzou_core.debug) {
        hizzou_core.current_user = {"sitesettings":{},"trialCode":null,"userPassword":"111111","userPhoto":null,"blog":null,"userLogin":"anton@hizzou.com","userType":"System","id":12,"updated":"2010-01-13 09:12:58","features":[],"firstName":null,"activationId":"5ac5acc1-ec78-463e-a873-87e9d978e3f4","lastMlsUpdate":null,"lastName":null,"services":["basic"],"mlsInfo":null,"campaignMonitorClientId":"6d3baf8906053cbf92031b1221d11a79","status":"Active","website":null,"emailAddress":"anton@hizzou.com","audioProfile":{"id":12,"hizzouphonenumber":"7202562803","socialmediaprofileid":null,"updated":1263373891000,"ttsprofileid":null,"userid":12,"smsprofileid":null,"recordingspin":"1234","recordingsphonenumber":"9786310700"},"smsProviders":[{"keywords":"HIZZOU","messagesize":160,"name":"TextMarks","shortcode":"41411","provideralias":"textmarks"}],"dateRegistered":"2010-01-13 09:11:31","homeNumber":null,"userRoles":["Users"],"notifications":[],"officeNumber":null,"mobileNumber":null,"brokerageName":null};
        hizzou_core.current_user.favoriteListingsList = [{"acres":0.48,"greenFeatures":null,"greenCertification":null,"acresBottomland":null,"acresCultivated":null,"acresIrrigated":null,"acresPasture":null,"acresPrice":1560209,"agentList":"0561973","agentListFullname":"Jared English","agentSellFullname":null,"agExemption":null,"approvalNum":null,"area":20,"assocFee":20,"assocFeeIncludes":null,"assocFeePaid":"Annual","assumption":"Not Assumable","barn1Length":null,"barn1Width":null,"barn2Length":null,"barn2Width":null,"barn3Length":null,"barn3Width":null,"barnDesc":null,"bathsFull":3,"bathsFullBasement":null,"bathsFullLevel1":1,"bathsFullLevel2":2,"bathsFullLevel3":null,"bathsHalf":1,"bathsHalfBasement":null,"bathsHalfLevel1":1,"bathsHalfLevel2":null,"bathsHalfLevel3":null,"bathsTotal":3.10,"beds":5,"block":"25","building":null,"buildingNum":null,"bus1":null,"bus2":null,"bus3":null,"bus4":null,"carPortCap":1,"city":"Plano","commonFeatures":null,"complexName":null,"construction":"Fiber Cement, Rock/ Stone","county":"Collin","coveredSpacesTotal":3,"cropProgram":null,"crops":null,"directions":"Go east on 15th from I-75 to the first light which is Ave G.  Take a left and go north one block to the NE corner of 16th St and Ave G.","easements":null,"energy":"Ceiling Fans, Gas Water Heater, Insulated Doors, Thermo Windows","equipment":"Built-in Icemaker, Built-in Microwave, Built-in Refrigerator/Freezer, Convection Oven, Cooktop - Gas, Dishwasher, Disposal, Oven - Electric, Self Clean, Vent Mechanism, Water Line to Refrigerator","exterior":"Covered Porch(es), Patio Open, Sprinkler System, Workshop","fence":"Iron, Wood","fillArea":"*","fillBlock":"*","fillCity":"*","fillLotNum":"*","fillMap":null,"fillMapBook":"*","fillMapCoord":"*","fillMapPage":"*","fillSchoolDistrict":"*","fillSqftTotal":null,"fillStreetNumDisplay":null,"fillSubDivision":"*","fillTaxId":"*","fillTaxUnexempt":"*","fillUnitNum":null,"fillYearBuilt":"*","fillZipCode":"*","financeProposed":"Cash, Conventional, Other","fireplaceDesc":null,"fireplaces":2,"floors":"Carpet, Concrete, Wood Floor","forLease":"N","foundation":"Piered Beam Slab","garageCap":2,"garageDesc":"Detached, Opener, Outside Entry, Oversized, Porte-Cochere, Side","handicap":null,"handicapYN":"N","heatSystem":"Central Air-Elec, Central Heat-Gas","hoa":"Voluntary","housingType":"Historical/Conservation Dist.","interior":"Bay Windows, Cable TV Available, Decorative Lighting, Smart Home Features, Sound System Wiring, Vaulted Ceilings","internetDisplayYN":"Y","internetListAll":"Members IDX Websites, NTREIS Translator, REALTOR.com, Syndicate Listing","landLease":null,"legal":"Plano Original Donation, Block","listPrice":745000,"listPriceLow":0,"listPriceOrig":745000,"listPriceRange":"N","listStatus":"Active","listStatusFlag":null,"lotDesc":"Corner, Landscaped, Lrg. Backyard Grass, Some Trees","lotDim":null,"lotNum":"1","lotSize":"Less Than .5 Acre (not Zero)","mapBook":"DALLAS","mapCoord":"S","mapPage":"0659","miscellaneous":null,"mlsNum":11317202,"modified":1260812737000,"mudDistrict":"N","numbarn1Stalls":null,"numbarn2Stalls":null,"numbarn3Stalls":null,"numbarns":null,"numDiningAreas":2,"numLakes":null,"numLivingAreas":3,"numPonds":null,"numResidence":null,"numStockTanks":null,"numWells":null,"officeList":"CONG00TO","officeListOfficeNam1":"Congress Realty","officeSellOfficeNam2":null,"parcelsMultiple":"N","photoAerialAvail":null,"photoCount":6,"plannedDevelopment":null,"poolDesc":null,"poolYN":"N","possession":"Negotiable","presentUse":null,"proposedUse":null,"propSubType":"RES-Single Family","propSubTypeDisplay":"RES-S","propType":"Residential","ranchName":null,"ranchType":null,"remarks":"This is a one-of-a-kind home designed by award-winning architect, Tom Wilson. It has been featured in Southern Living Magazine, Plano Profile Magazine, Dallas Morning News, Holiday Tour of Homes, and on WFAA channel 8; and won Plano's Best New Heritage Construction award. It is located in downtown Plano's Haggard Heritage Park neighborhood.","restrictions":null,"roadFrontage":null,"roadFrontageDesc":null,"roof":"Composition","roomBed2Length":14,"roomBed2Level":"2","roomBed2Width":16,"roomBed3Length":13,"roomBed3Level":"2","roomBed3Width":12,"roomBed4Length":13,"roomBed4Level":"2","roomBed4Width":14,"roomBed5Length":12,"roomBed5Level":"2","roomBed5Width":13,"roomBedBathDesc":"Double Shower, Jack & Jill Bath, Linen Closet, Medicine Cabinet, Separate Shower, Separate Vanities, Walk-in Closets","roomBreakfastLength":null,"roomBreakfastLevel":null,"roomBreakfastWidth":null,"roomDiningLength":null,"roomDiningLevel":null,"roomDiningWidth":null,"roomGarageLength":23,"roomGarageWidth":23,"roomKitchenDesc":"Breakfast Bar, Eat-in Kitchen, Island","roomKitchenLength":17,"roomKitchenLevel":"1","roomKitchenWidth":19,"roomLiving1Length":23,"roomLiving1Level":"1","roomLiving1Width":28,"roomLiving2Length":11,"roomLiving2Level":"1","roomLiving2Width":13,"roomLiving3Length":17,"roomLiving3Level":"2","roomLiving3Width":23,"roomMasterBedLength":13,"roomMasterBedLevel":"1","roomMasterBedWidth":19,"roomOther":"Exercise Room, Game Room, Library/Study, Media Room, Mud Room, Music Room","roomOther1Length":16,"roomOther1Level":"1","roomOther1Width":14,"roomOther2Length":null,"roomOther2Level":null,"roomOther2Width":null,"roomStudyLength":7,"roomStudyLevel":"1","roomStudyWidth":10,"roomUtilDesc":"Dryer Hookup-Gas, Full Size W/D Area, Room for Freezer, Separate Room, Utility Closet","roomUtilityLength":6,"roomUtilityLevel":"1","roomUtilityWidth":11,"schoolDistrict":"Plano ISD","schoolName1":"MENDENHALL","schoolName2":"PLANOEAST","schoolName3":"WILLIAMS","schoolName4":"BOWMAN","schoolType1":"E","schoolType2":"S","schoolType3":"H","schoolType4":"M","securitySystem":"Y","securityDesc":null,"showing":"Agent Or Owner Present","soilType":null,"specialNotes":"Verify Tax Exemptions","sqftPrice":149.57,"sqftSource":"Tax","sqftTotal":4981,"stories":2,"storiesBldg":null,"streetDir":"E","streetName":"16th","streetNum":801,"streetNumDisplay":"801","streetType":"Street","styleDesign":"Other","subArea":"12","subDivide":"No","subDivision":"Plano Original Donation","surfaceRights":null,"taxId":"R034002500101","taxUnexempt":11567,"topography":null,"uid":3204442,"uidPrp":3204442,"unitFloorNum":null,"unitNum":null,"utilities":"Sidewalk","utilitiesOther":null,"yearBuilt":2001,"yearBuiltDesc":"Preowned","zipCode":"75074-5833","agentId":16,"hizzouId":163,"mlsProvider":"NTREIS","primaryPhotoPath":"http://ntreispictures.marketlinx.com/MediaDisplay/42/LR3204442-1.jpg","geoCode":"33.021474,-96.704831","state":"TX","ttsProfileId":null,"propertyFeatures":null,"userId":100,"bitlyUrl":"http://bit.ly/423qNJ","smsProfileId":null,"socialMediaProfileId":null,"useNaturalSpeech":null,"geoCodeLat":33.0214740000,"geoCodeLng":-96.7048310000,"featured":"agent","id":163,"updated":1266922081000,"listingMedia":{"$ref":"/resources/media?hizzouId=163"}}];
        hizzou_core.current_user.favoriteListingsListIDs = [23,3,4,5,6,7,8,34,163,12,34,2];
    } else {
        $.ajax({url:hizzou_core.ajax_url+'resources/userProfile/currentuser',type:'GET',async:false,
                complete: function (data) {
                                if (parseInt(data.status) == 200) {
                                    hizzou_core.current_user = JSON.parse(data.responseText);
                                } else {
                                    hizzou_core.current_user = null;
                                }
                        }
                });
        if (hizzou_core.current_user) {
            $.ajax({url:hizzou_core.ajax_url+'resources/favoriteListing', type: 'GET', async: false,
                    complete: function(data) {
                        hizzou_core.current_user.favoriteListingsList = JSON.parse(data.responseText)
                        if (hizzou_core.current_user.favoriteListingsList.length) {
                            hizzou_core.current_user.favoriteListingsListIDs = 
                                $.makeArray($(hizzou_core.current_user.favoriteListingsList).map(function(i,item){return item.id}));
                        } else {
                            hizzou_core.current_user.favoriteListingsListIDs = [];
                        }
                    }
                });
        }
    }
}
$(document).ready(function(){
    // onload we get info about current logged in user
    hizzou_core.loadCurrentUserData();
    
    // init list of properties widget
    if ( $('.property-search-results').get(0) ) {
        hizzou_core.PropertySearchObject = new hizzou_core.PropertySearch($('.property-search-results').get(0));
    }
    if ( $('.property-favorite-listings').get(0) ) {
        hizzou_core.PropertyFavoritesObject = new hizzou_core.PropertyFavorites($('.property-favorite-listings').get(0));
    }
    
});


})(jQuery)
