/* for the BUILDING page */


var FCESlideShow = {
    currPos : 1,

    next: function() {
        this.currPos = 1 + parseInt(this.currPos);
        if ($('#buildingSSContent_'+this.currPos).size() == 0) {
            this.currPos = 1;
        }
        $('#buildingSSContent_'+this.currPos).click();
    },

    previous: function() {
        this.currPos = parseInt(this.currPos) - 1;
        if (this.currPos == 0) {
            this.currPos = $('#buildingSSContentView').children('.slide').size();
        }
        $('#buildingSSContent_'+this.currPos).click();
    },


    popOverlay : function(slide) {
        var sid = $(slide).attr('id');
        if (sid) {
            this.currPos = sid.split('_')[1];
            //var url = $(slide).find('img').attr('src').replace(/\.thumb/, '');
            var url = $(slide).find('img.largeHidden').attr('src');
            var caption = $(slide).find('h3').text();
            var caption2 = $(slide).find('p').text();
            tb_show(caption, url, null, caption2);
        }
    }

};


var FCEVirtualTour = {/*{{{*/
    enabled : false,
    did_init : false,

    init : function() {
        this.btnDefaultBG = $('#buildingBtnVT1').css('background-image');
        this.btnEnabledBG = this.btnDefaultBG.replace(/\.(\w+["')]+?)$/, '.enabled.$1');

        $('#buildingBtnVT1').bind('click', function(e){
                                              FCEVirtualTour.enable(); 
                                              preventDefault();
                                              return true;
                                           });
        this.did_init = true;
    },

    enable : function() {
        if (!this.did_init) this.init();

        if (this.enabled) {
            this.disable();
        }
        else {
            $('#buildingBtnVT1').css('background-image', this.btnEnabledBG);
            $('#buildingVTContentW').show();
            FCESlideShow.stop();
            FCESlideShow.hideContent();
            this.enabled = true;
            $('#btnViewSlideShowShadow').blur();
        }

    },

    disable : function() {
        $('#buildingBtnVT1').css('background-image', this.btnDefaultBG);
        $('#buildingVTContentW').hide();
        FCESlideShow.showContent();
        this.enabled = false;
    }
};/*}}}*/


$(document).ready(function(){
     /* trigger the overlay on click of the selected item in the carousel */
     $('#buildingSSContentView > div.slide').bind('click', function(e){ 
         FCESlideShow.popOverlay(this);
         e.stopPropagation();
     });

     $('#buildingSSContentView > div.slide').hover( function() { $(this).find('p').show(); },
                                                    function() { $(this).find('p').hide(); } );

     /* for Lofts, the little P overlays should be 1/2 the height of the
      * picture, unless they need more room, then they should expand up
      * vertically to fill the space. Of course this is not possible in plain CSS */
     $('#buildingSSContentView > div.slide').each( function() {
         var myP = $(this).find('p');
         var myImg = $(this).find('img');
         var tot = myImg.height() + parseInt(myImg.css('borderTopWidth'));
         if (myP.height() > tot/2) {
             myP.css('top', tot - myP.height());
         }
         else {
             myP.css('height', tot/2 - parseInt(myImg.css('borderBottomWidth')));
         }
     });
});


