/**
 * stub dataAccessor object that knows how to get the various types of data
 * needed for FCE Apartment browse and search functionality. Each method
 * returns a subset of data organized as arrays and/or custom Objects.
 *
 *
 * @todo replace all static JSON with in-line JSON objects or XMLHttpRequests
 * as needed to acces live data.
 *
 * @author sbeam
 * @date Wed Nov  7 14:19:50 EST 2007
 */
var FCEAptDataRetriever = {
    aptCategoryLists: null,
    FloorplanDetails: null,
    FCE_Data: null,
    /**
    * get all apartment listings, indexed by bedrooms. This is called from
    * apartment_search.html when the user clicks on the '1 bed', '2 bed'
    * buttons, etc. The data will be consumed in FCEAptSearch object which
    * will dynamically create a DOM table to display the results as needed.
    *
    * @param beds str, ie "1" "2" or "penthouse"
    * @param avail_only bool limit results to available apartments only.
    * @return Object arrayListObject - Array of simple generic Objects, each with the following properties:
    *           { "aptkey":string, // apartment ID
    *             "plan":string,   // plan name
    *             "bath":string,   // #baths
    *             "bed":string,    // #beds
    *             "sqft":string,   // square footage
    *             "floor":string,  // floor#
    *             "rent":string,   // rent
    *             "avail":boolean  // if true, apt is available for rent.
    *           }
    *
    * @todo replace with whatever is needed to access live data.
    */
    setup: function(data) {
        this.FCE_DATA = data.ApartmentDetailsByUnitNumber;
        this.aptCategoryLists = data.ApartmentsByCategory;
        this.FloorplanDetails = data.FloorplanDetailsByFloorplanID;
    },
    fetchAptListings: function(beds, avail_only) {
        var aptList;
        var BedsS = beds.toUpperCase();
        var x = this.aptCategoryLists["k" + BedsS];
        if (x != null) {
            aptList = this.aptCategoryLists["k" + BedsS].Apartments;
        } else {
            aptList = new Array();
        }
        var clonelist = new Array();
        var clonelistIndex = 0;
        for (var i = aptList.length - 1; i >= 0; i--) {
            if (avail_only && !aptList[i].avail) continue;
            clonelist[clonelistIndex++] = aptList[i];
        }
        return clonelist;
    },



    /** 
    * content for aptInfoDialogs in apt-browse - this is the small
    * pointer/popup that shows when user hovers over the apartment on the
    * floor plate. We pass the current floor# and the current apartment# as
    * arguments.
    *
    * @param floor str floor to get info for, ie "11"
    * @param apt str apt# on that floor, ie "24"
    * @return false if not found or Object: { aptkey:101, 
    *                                         floor:3, 
    *                                         aptnum:27, 
    *                                         hdr:"327 Debussy", 
    *                                         lines:["1 Bedroom", "1 Bath", "$1400/month"] }
    *
    * @todo replace with whatever is needed to access live data.
    */
    fetchAptInfoByFloor: function(floor, aptnum) {
        var isLeased = false;
        for (var aptkey in this.FCE_DATA) {
            var apt = this.FCE_DATA[aptkey];
            if (apt.floor == floor && apt.aptnum == aptnum) {
                return { "aptkey": aptkey,
                    "aptnum": this.FCE_DATA[aptkey].aptnum,
                    "floor": this.FCE_DATA[aptkey].floor,
                    "hdr": this.FCE_DATA[aptkey].shortHeader,
                    "lines": this.FCE_DATA[aptkey].infoLines,
                    "avail": this.FCE_DATA[aptkey].isLeased
                };
            }
        }
    },


    /**
    * get info object corresponding to the identified apartment, using only
    * the "aptkey" - since this is the same as floor+aptnum, then it should
    * return the same as the above function, given the same floor/apt#. For
    * instance, this may be passed just "1124".
    *
    * @param aptkey string, ie "1124"
    * @return false if not found or Object: { aptkey:101, 
    *                                         floor:3, 
    *                                         aptnum:27, 
    *                                         hdr:"327 Debussy", 
    *                                         lines:["1 Bedroom", "1 Bath", "$1400/month"] }
    *
    * @todo replace with whatever is needed to access live data.
    */
    fetchAptInfo: function(aptkey) {
        if (this.FCE_DATA[aptkey])
            return { "aptkey": aptkey,
                "aptnum": this.FCE_DATA[aptkey].aptnum,
                "floor": this.FCE_DATA[aptkey].floor,
                "hdr": this.FCE_DATA[aptkey].shortHeader,
                "lines": this.FCE_DATA[aptkey].infoLines
            };
    },

    fetchFloorplanDetails: function(fpidkey) {
        if (this.FloorplanDetails[fpidkey]) return this.FloorplanDetails[fpidkey];
    },
    /** 
    * description and listing, by aptkey (id). This should return the full
    * details on the apartment identified by aptkey
    *
    * @param apt str apartment id (aptkey)
    * @return object {
    *                  "aptnum":int,        // the apartment number (without the floor), ie "27"
    *                  "floor":int,         // the floor this apt is on, ie "11"
    *                  "shortHeader":string // the 'header' for the display, ie "1127 Debussy - 3 bedroom"
    *                  "infoLines":Array    // list of strings, for the popup/pointer widget, ie ["1 bed", "2 bath", "$2300"]
    *                  "description":string // the long description
    *                  "detailedList":Array // list of strings, for the apt detail display, ie ["1 bed", "2 bath", "1155 SQft.", "$2300/month", "Available"]
    *                }
    *
    * @todo replace with whatever is needed to access live data.
    */
    fetchAptDetails: function(apt) {
        if (this.FCE_DATA[apt]) {
            var theAptData = this.FCE_DATA[apt]
            var floorplanData = this.fetchFloorplanDetails(theAptData.FloorplanIDKey);
            return {
                "aptnum": theAptData.aptnum,
                "floor": theAptData.floor,
                "shortHeader": theAptData.shortHeader,
                "infoLines": theAptData.infoLines,
                "description": floorplanData.description,
                "detailedList": theAptData.detailedList,
                "normalFPImage": floorplanData.normalFPImage,
                "largeFPImage": floorplanData.largeFPImage
            };
        }
    },

    /**
    * get the number of the first available aparment on the identified floor.
    * This is so that when the search/browse page first loads, we can begin
    * by showing the details of some apartment
    *
    * @param floor int the floor #, ie "11"
    * @return int the number of the first apartment we have on it, ie, "27"
    *
    * @todo replace with whatever is needed to access live data.
    */
    fetchFirstAptNum: function(floor) {
        for (var i in this.FCE_DATA) {
            if (this.FCE_DATA[i].floor == floor) return this.FCE_DATA[i].aptnum;
        }
    },


    /**
    * get the name and path to the apartment Plan image for the apartment
    * identified by aptkey
    *
    * @param aptkey str the apartment key/number, ie "1127"
    * @param large bool if true, get the zoom version
    * @return string url/path to image
    *
    * @todo replace with whatever is needed to access live data.
    */
    fetchAptPlanImg: function(aptkey, large) {
        var theAptData = this.FCE_DATA[aptkey]
        var floorplanData = this.fetchFloorplanDetails(theAptData.FloorplanIDKey);
        return (large) ? floorplanData.largeFPImage : floorplanData.normalFPImage;
        
    }



};















/**
 * this is a bunch of dummy data in a convenient format. To be replaced with live data in JSON or XML as needed 

var FCE_DATA_DUMMY = {
           "309": {"aptnum":"9", "floor":"3", "shortHeader":"309 The Bonifant", "infoLines":["2 bed/2.5 bath"],
                    "description":"Two master suites with separate baths and expansive views make this two bedroom design a favorite. A large living room and separate formal dining room divide the bedrooms so privacy is never an issue. The fully applianced kitchen is big enough to handle Thanksgiving with all the fixin's.",
                    "detailedList":["2 Bed/2.5 bath","1224 Sq. Ft.","$2,000","13th Floor","Leased"]},

           "1159": {"aptnum":"59", "floor":"11", "shortHeader":"The Bonifant - 1159", "infoLines":["2 bed","2&frac12; bath","2500"],
                    "description":"Two master suites with separate baths and expansive views make this two bedroom design a favorite. A large living room and separate formal dining room divide the bedrooms so privacy is never an issue.  The fully applianced kitchen is big enough to handle Thanksgiving with all the fixin’s.",
                    "detailedList":["2 Bed","2&frac12; Bath","1224 Sq. Ft","11th Floor","2500/mo","Accessible"]},

           "952": {"aptnum":"52", "floor":"9", "shortHeader":"The Ellsworth - 952", "infoLines":["2 bed","2 bath","$2500"],
                    "description":"Yet another unique 2 bedroom, this particular floor plan offers two master suites separated by a wide dining and living room. A  private balcony off the living area lets you bring the outdoors inside during nice weather (and vice versa..) And, of course, it features an in-suite washer and dryer, fully applianced kitchen, designer finishes and plenty of closet and storage space.",
                    "detailedList":["2 Bed", "2 Bath","1088 Sq. Ft","9th Floor","$2500/month","Available"]},


           "356": {"aptnum":"56", "floor":"3", "shortHeader":"The Fenton - 356", "infoLines":["1 bed","1 bath","$2095"],
                    "description":"The perfect apartment for the social butterfly, this expansive one bedroom features a large walk-in closet, a linen closet and washer & dryer conveniently located in the over-sized bath, and a private balcony off the bedroom. ",
                    "detailedList":["1 Bed","1 Bath","800 Sq. Ft","$2095","3rd Floor","Great for cats"]},

           "351": {"aptnum":"51", "floor":"3", "shortHeader":"The Blair - 351", "infoLines":["2 Bed","1 Bath","Leased"],
                    "description":"From the moment you step into the foyer and sense the space beyond, you know this apartment is not your typical two bedroom unit.  A large master bedroom features a walk-in closet.  The second bedroom easily doubles as a den or home office or both.  A formal-sized dining room off the kitchen opens to a large living room with a walk-out balcony. If you love to entertain, this floor plan has it all.  You never have to feel separated from your guests, and the open design allows them to move freely from room to room.",
                    "detailedList":["2 Bed","1 Bath","1037 Sq. Ft","$1000/mo"]},

           "1460": {"aptnum":"60", "floor":"14", "shortHeader":"The Georgian - 1460", "infoLines":["1 Bed","1 Bath","$1795"],
                    "description":"If you need a home office or just want a little more space, this one bedroom will fit you to a T.  Two walk-in closets, a kitchen with plenty of storage and an enormous living/dining room complete this intelligently designed layout.",
                    "detailedList":["1 Bed","1 Bath","984 Sq. Ft","$1795","14th Floor","No Dogs"]},


           "319": {"aptnum":"19", "floor":"3", "shortHeader":"Debussy 319", "infoLines":["3 Bed","2 Bath","$3100"],
                    "description":"Kaj lingvaj konfliktoj Ni asertas ke la vastaj potencodiferencoj inter la lingvoj. Kaj neoficialaj kunvenas sur neuxtrala tereno dank' al la reciproka volo kompromisi Tia ekvilibro inter!",
                    "detailedList":["3 Bed","2 Bath","1905 Sq. Ft","$3100","3rd Floor",]},

           "318": {"aptnum":"18", "floor":"3", "shortHeader":"Debussy 318", "infoLines":["3 Bed","1&frac34; Bath","Leased"],
                    "description":"Te feugait nulla facilisi Nam liber tempor cum soluta nobis eleifend option congue? Nobis videntur parum futurum; decima Eodem modo typi qui nunc nobis videntur.",
                    "detailedList":["3 Bed","1&frac34; Bath","2010 Sq. Ft","11th Floor","Leased"]},


           "558": {"aptnum":"58", "floor":"5", "shortHeader":"The Georgian - 558", "infoLines":["1 Bed","Den","$3795"],
                    "description":"If you need a home office or just want a little more space, this one bedroom will fit you to a T.  Two walk-in closets, a kitchen with plenty of storage and an enormous living/dining room complete this intelligently designed layout.",
                    "detailedList":["1 Bed/1 Bath/Den","984 Sq. Ft","$3795","5th Floor","Accessible"]},

           "312": {"aptnum":"12", "floor":"3", "shortHeader":"Plan Name - 312", "infoLines":["2 Bed","2 Bath","Leased"],
                    "description":"Anteposuerit litterarum formas humanitatis per. Modo typi qui nunc nobis videntur parum clari fiant, claritatem insitam est usus legentis in iis qui facit eorum claritatem Investigationes demonstraverunt lectores legere!",
                    "detailedList":["1 Bed","1 Bath","455 Sq. Ft","Leased","Balcony"]},

           "301": {"aptnum":"1", "floor":"3", "shortHeader":"Debussy 301", "infoLines":["2 Bed","2 Bath","Leased"],
                    "description":"Anteposuerit litterarum formas humanitatis per. Modo typi qui nunc nobis videntur parum clari fiant, claritatem insitam est usus legentis in iis qui facit eorum claritatem Investigationes demonstraverunt lectores legere!",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "221": {"aptnum":"1", "floor":"2", "shortHeader":"Plan Name 201", "infoLines":["2 Bed / 2 bath","Leased"],
                    "description":"Anteposuerit litterarum formas humanitatis per. Modo typi qui nunc nobis videntur parum clari fiant, claritatem insitam est usus legentis in iis qui facit eorum claritatem Investigationes demonstraverunt lectores legere!",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "101": {"aptnum":"1", "floor":"1", "shortHeader":"Plan Name - 101", "infoLines":["1 Bed / 1 bath","Leased"],
                    "description":"Anteposuerit litterarum formas humanitatis per. Modo typi qui nunc nobis videntur parum clari fiant, claritatem insitam est usus legentis in iis qui facit eorum claritatem Investigationes demonstraverunt lectores legere!",
                    "detailedList":["1 Bed","1 Bath","555 Sq. Ft","Leased","Great for cats"]},

           "259": {"aptnum":"59", "floor":"2", "shortHeader":"The Schooner - 259", "infoLines":["1 Bed","Den","$3795"],
                    "description":"Quam littera gothica quam nunc putamus parum claram anteposuerit; imperdiet doming id quod mazim placerat facer possim assum Typi non habent claritatem insitam, non habent claritatem insitam est usus legentis in iis qui facit eorum claritatem Investigationes?",
                    "detailedList":["2 Bed/1 Bath/Den","984 Sq. Ft","$3795","5th Floor","Accessible"]},

           "901": {"aptnum":"1", "floor":"9", "shortHeader":"Penthouse - Debussy 901", "infoLines":["2 Bed","2 Bath","Leased"],
                    "description":"claritatem Investigationes demonstraverunt lectores legere me lius quod ii legunt; gothica quam nunc putamus parum claram anteposuerit litterarum formas humanitatis? Te feugait nulla facilisi Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet. ",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "929": {"aptnum":"29", "floor":"9", "shortHeader":"The Draper - 929", "infoLines":["2 Bed / 2 bath","4600"],
                    "description":"Est notare quam littera gothica quam nunc putamus parum? Qui facit eorum claritatem Investigationes demonstraverunt lectores legere! Parum claram anteposuerit litterarum formas! Iis qui facit eorum claritatem Investigationes demonstraverunt lectores legere me. Putamus parum claram anteposuerit litterarum formas humanitatis per seacula quarta, seacula quarta decima et quinta decima Eodem modo. In futurum. Legunt saepius Claritas est etiam processus dynamicus qui sequitur mutationem consuetudium; Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod.",
                    "detailedList":["2 Bed","2 Bath","2200 Sq. Ft","$4600/mo","Great for cats"]},

           "328": {"aptnum":"28", "floor":"3", "shortHeader":"Plan Name 328", "infoLines":["2 Bed / 2 bath","Leased"],
                    "description":"In futurum. Legunt saepius Claritas est etiam processus dynamicus qui sequitur mutationem consuetudium; Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod. ",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "255": {"aptnum":"55", "floor":"2", "shortHeader":"The Sloop 255", "infoLines":["Studio / 1 bath","Available"],
                    "description":"Traktado sendistinge pri la lingvo Ni estas movado por lingvaj rajtoj Lingva diverseco La? La politiko de komunikado kaj evoluigo se gxi ne estas bazita sur respekto. Al formorto la plimulton de la lingvoj de la mondo Ni estas movado por. Etna lingvo estas ligita al difinita perspektivo pri la mondo Ni estas movado por transnacia. ",
                    "detailedList":["1 Bed","1 Bath","55 Sq. Ft","Leased","Great for cats"]},

           "902": {"aptnum":"2", "floor":"9", "shortHeader":"Plan Name 902", "infoLines":["2 Bed / 1&frac12; bath","Leased"],
                    "description":"Putamus parum claram anteposuerit litterarum formas humanitatis per seacula quarta, seacula quarta decima et quinta decima Eodem modo.",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "329": {"aptnum":"29", "floor":"3", "shortHeader":"Chopin 329", "infoLines":["2 Bed / 1&frac12; bath","Leased"],
                    "description":"Efikeco Nur malgranda procentajxo el tiuj kiuj studas fremdan lingvon ekmastras gxin Plena. Komunumo kun firmaj radikoj cxe sia loka kultura kaj lingva identeco sed ne limigite de, la Esperantokomunumo la anoj de lingvoj grandaj kaj malgrandaj. ",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "1711": {"aptnum":"11", "floor":"17", "shortHeader":"Chopin 1711", "infoLines":["2 Bed / 1&frac12; bath","Leased"],
                    "description":"Efikeco Nur malgranda procentajxo el tiuj kiuj studas fremdan lingvon ekmastras gxin Plena. Komunumo kun firmaj radikoj cxe sia loka kultura kaj lingva identeco sed ne limigite de, la Esperantokomunumo la anoj de lingvoj grandaj kaj malgrandaj. ",
                    "detailedList":["2 Bed","2 Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "PH05": {"aptnum":"50", "floor":"15", "shortHeader":"Penthouse 1550", "infoLines":["3 Bed / 2&frac12; bath","2400"],
                    "description":"Te feugait nulla facilisi Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet. Est notare quam littera gothica ",
                    "detailedList":["2 Bed","2&frac12; Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "PH07": {"aptnum":"51", "floor":"15", "shortHeader":"Penthouse 1551", "infoLines":["3 Bed / 2&frac12; bath","2400"],
                    "description":"Efikeco Nur malgranda procentajxo el tiuj kiuj studas fremdan lingvon ekmastras gxin Plena. Komunumo kun firmaj radikoj cxe sia loka kultura kaj lingva identeco sed ne limigite de, la Esperantokomunumo la anoj de lingvoj grandaj kaj malgrandaj. ",
                    "detailedList":["2 Bed","2&frac12; Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "PH09": {"aptnum":"52", "floor":"15", "shortHeader":"Penthouse 1552", "infoLines":["3 Bed / 2&frac12; bath","2400"],
                    "description":"But epochs sometimes language occur, in the course of the existence engine of a nation, understood theory at which the ancient customs ",
                    "detailedList":["2 Bed","2&frac12; Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "PH11": {"aptnum":"53", "floor":"15", "shortHeader":"Penthouse 1553", "infoLines":["3 Bed / 2&frac12; bath","2400"],
                    "description":"Plurlingvaj Cxiu komunumano akceptis la taskon lerni almenaux unu fremdan lingvon gxis parola, la garantiojn esprimitajn en tiom da internaciaj dokumentoj de. Registaroj emas konsideri la grandan diversecon de lingvoj!  ",
                    "detailedList":["2 Bed","2&frac12; Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "PH13": {"aptnum":"58", "floor":"15", "shortHeader":"Penthouse 1558", "infoLines":["3 Bed / 2&frac12; bath","2400"],
                    "description":"Konsideri la grandan diversecon de lingvoj en la mondo kiel baron al komunikado kaj evoluigo. Ankaux rekomendas Esperanton kiel kernan eron en kursoj. Efikeco Nur malgranda procentajxo el tiuj kiuj studas fremdan lingvon ekmastras gxin Plena.  ",
                    "detailedList":["2 Bed","2&frac12; Bath","2055 Sq. Ft","Leased","Great for cats"]},

           "PH15": {"aptnum":"59", "floor":"15", "shortHeader":"Penthouse 1559", "infoLines":["3 Bed / 2&frac12; bath","2400"],
                    "description":"Ankaux rekomendas Esperanton kiel kernan eron en kursoj. Efikeco Nur malgranda procentajxo el tiuj kiuj studas fremdan lingvon ekmastras gxin Plena. Komunumo kun firmaj radikoj cxe sia loka kultura kaj lingva identeco sed ne limigite de, la Esperantokomunumo la anoj de lingvoj grandaj kaj malgrandaj.",
                    "detailedList":["2 Bed","2&frac12; Bath","2055 Sq. Ft","Leased","Great for cats"]}
};
 */

