/* FCE_FLOORS_PLATES: for each floor, the name of the floorplate to use. Should ocrrespond to
 * names of GIF images in the resources/ directory, and also the imagemaps
 * names to be used with the floorplate */
var FCE_FLOORS_PLATES = {
        '01' : ['hml_floorplate_t'],
        '02': ['hml_floorplate_e'],
        '04' : ['hml_floorplate_p'],
        '03': ['hml_floorplate_ph']
    };


/* make an Image object to pre-load each of the floor plates, and tack the obj
 * onto the end of the array for further use. This has to be done here and not
 * in document.ready() func because surprisingly that fires before the rest of
 * the javascript is parsed. */
for (f in FCE_FLOORS_PLATES) {
    var preloader = new Image();
    preloader.src = 'resources/'+FCE_FLOORS_PLATES[f][0]+'.gif';
    FCE_FLOORS_PLATES[f].push(preloader);
}

/* x/y coords for the center of each apartment in the floorplates */
var FCEAptPointers_T = {
            "20" : {"x":9, "y":27, "ord":"down"},
            "21" : {"x":5, "y":31, "ord":"right"},
            "22" : {"x":20, "y":36, "ord":"down"},
            "23" : {"x":15, "y":40, "ord":"up"},
            "24" : {"x":36, "y":43, "ord":"down"},
            "25" : {"x":21, "y":46, "ord":"up"},
            "26" : {"x":44, "y":45, "ord":"down"},
            "27" : {"x":36, "y":50, "ord":"up"},
            "28" : {"x":43, "y":51, "ord":"down"},
            "29" : {"x":43, "y":51, "ord":"up"}
          };
var FCEAptPointers_P = { 
            "1" : {"x":134, "y":55, "ord":"down"},
            "2" : {"x":137, "y":60, "ord":"up"},
            "3" : {"x":146, "y":52, "ord":"down"},
            "4" : {"x":150, "y":56, "ord":"up"},
            "5" : {"x":157, "y":48, "ord":"down"},
            "6" : {"x":161, "y":53, "ord":"up"},
            "7" : {"x":171, "y":44, "ord":"down"},
            "8" : {"x":170, "y":50, "ord":"up"}
    };
var FCEAptPointers_E = {
            "1" : {"x":105, "y":22, "ord":"down"},
            "2" : {"x":100, "y":28, "ord":"up"},
            "3" : {"x":92, "y":21, "ord":"down"},
            "4" : {"x":82, "y":27, "ord":"up"},
            "5" : {"x":84, "y":20, "ord":"down"},
            "6" : {"x":75, "y":25, "ord":"up"},
            "7" : {"x":70, "y":18, "ord":"down"},
            "8" : {"x":66, "y":25, "ord":"up"},
            "9" : {"x":63, "y":18, "ord":"down"},
            "10" : {"x":55, "y":24, "ord":"up"},
            "11" : {"x":55, "y":17, "ord":"down"},
            "12" : {"x":45, "y":23, "ord":"up"},
            "13" : {"x":41, "y":16, "ord":"down"},
            "14" : {"x":41, "y":23, "ord":"up"},
            "15" : {"x":32, "y":16, "ord":"down"},
            "16" : {"x":29, "y":21, "ord":"up"},
            "17" : {"x":22, "y":14, "ord":"down"},
            "18" : {"x":20, "y":21, "ord":"up"},
            "19" : {"x":16, "y":19, "ord":"down"}
     };
var FCEAptPointers_PH = {
            "30" : {"x":96, "y":35, "ord":"down"},
            "31" : {"x":119, "y":43, "ord":"left"},
            "32" : {"x":96, "y":41, "ord":"right"},
            "33" : {"x":112, "y":51, "ord":"left"},
            "34" : {"x":96, "y":50, "ord":"right"},
            "35" : {"x":112, "y":57, "ord":"left"},
            "36" : {"x":96, "y":58, "ord":"right"},
            "37" : {"x":112, "y":62, "ord":"left"},
            "38" : {"x":95, "y":63, "ord":"up"},
            "39" : {"x":101, "y":64, "ord":"up"},
            "40" : {"x":114, "y":66, "ord":"up"}
    
     };

/*
Here's the information you need:
•	Bldg #1 - (E) Essex
•	Bldg #2 = (T) Tilton
•	Bldg #3 = (PH) The Powerhouse
•	Bldg #4 = (P) Pentucket


*/
     var FCEAptPointerPositioning = {

         pointsByFloor: {
             "02": FCEAptPointers_T,
             "04": FCEAptPointers_P,
             "01": FCEAptPointers_E,
             "03": FCEAptPointers_PH
         },

         /* get the position for the given apartment */
         getPosByApt: function(building, aptNum) {
             var points = this.pointsByFloor[building] || this.pointsByFloor['default'];
             var aptNum2 = aptNum.replace(/^0+/, '');
             return points[aptNum2];
         },

         /* get all points for the whole floor */
         getPosByBuilding: function(building) {
             var points = this.pointsByFloor[building] || this.pointsByFloor['default'];
             return points;
         },

         positionDialog: function(elem, floor, aptnum) {
             var pos = this.getPosByApt(floor, aptnum);
             if (!pos) {
                 $(elem).hide();
             }
             else {
                 $(elem).show();

                 // position the dialog according to the x and y given + any offset
                 // given in css for aptInfoDialogOffset
                 var offsetX = parseInt($(elem + 'Offset').css('left'));

                 var imageWidth = FCE_FLOORS_PLATES[floor][1].width;

                 /* since floor plate <img> is centered, try to find the offset
                 * from the left edge of the thing we are actually relative to. */

                 var dWidth = 0;
                 /* not needed for HML
                 * var dWidth = (parseInt($('#aptFloorPlateW').css('width')) - imageWidth) / 2;
                 *
                 * if (jQuery.browser.msie && jQuery.browser.version < 7) { // msie6 is buggy but this is actually much easier.
                 *   dWidth = 0;
                 * }
                 */

                 // console.log('W %s - img %s', $('#aptFloorPlateW').css('width'), imageWidth);
                 // console.log('posX: %s, posY: %s, dWidth: %s, offsetX: %s', pos.x, pos.y, dWidth, offsetX);

                 // msie6 needs to have the css property directly to trigger the onpropertychange handler to re-load the PNG component
                 if (jQuery.browser.msie && jQuery.browser.version < 7) {
                     $(elem).css('background-image', 'url(/img/bg.aptPointer.' + pos.ord + '.png)');
                 }

                 $(elem).parent().css('left', pos.x + dWidth + offsetX)
                                  .css('top', pos.y + parseInt($(elem + 'Offset').css('top')))
                                  .show()
                                  .attr('class', pos.ord);

             }

         }

         /*// puts little black dots at the coordinates on top of the floorplate
         debug : function(floor) {
         var points = this.getPosByFloor(floor);
         for (p in points) { 
         $('#aptFloorPlate').append('<div class="debug" rel="'+p+'" style="height: 2px; width: 2px; background: #000; position: absolute; left: '+points[p].x+'px; top: ' +points[p].y+ 'px;"></div>'); 
         }
         //$('#aptFloorPlate div.debug').bind('mouseover', function () { console.log($(this).attr('rel') +':'+$(this).css('left')+','+$(this).css('top')); });
         }*/

     };

