/* for the BUILDING page */


var FCESlideShow = {

    currOverlay: null,

    bigsrcs: [],

    clearOverlay: function() {
        $('#ssOverlayW').fadeOut('fast');
    },

    showContent: function() {
        if (this.rel) {

            $('#ssFocal').css('background-image', this.rel);
            $('#ssFocal p').empty().append($(this).siblings('p.capt').text());
        }
    },

    init: function() {
        if (this.didinit) { return true; }

        $('#ssOverlay .inset').append('<h2></h2><p></p><div class="closewin">CLOSE</div><div class="scroll"><a class="prev">&lt;</a><a class="next">&gt;</a></div>');

        $('#ssOverlay .inset .closewin').bind('click', FCESlideShow.clearOverlay);
        $('#ssOverlay .inset .scroll .next').bind('click', FCESlideShow.moveNext);
        $('#ssOverlay .inset .scroll .prev').bind('click', FCESlideShow.movePrev);

        $('#buildingSSContentView div:first a').trigger('mouseover'); // make sure first caption shows up
        this.didinit = true;
    },


    popOverlay: function() {
        $('#ssOverlayW').show();
        $('#ssOverlay').hide();
        var url = this.rel.replace(/_[^.]+./, '_w1024_h574.');
        $('#ssOverlay').css('background-image', url).fadeIn('fast');
        $('#ssOverlay .inset h2').text($(this).text());
        var caption2 = $(this).parent().find('p.desc').text();
        $('#ssOverlay .inset p').text(caption2);
        FCESlideShow.currSelected = this;
        return false;
    },

    moveNext: function() {
        var next = $(FCESlideShow.currSelected).parent().next();
        if (next.length == 0) {
            next = $('#buildingSSContentView div:first');
        }
        next.find('a').click();
        return false;
    },

    movePrev: function() {
        var prev = $(FCESlideShow.currSelected).parent().prev();
        if (prev.length == 0) {
            prev = $('#buildingSSContentView div:last');
        }
        prev.find('a').click();
        return false;
    }

    /*
    * detectedMacFF : function () { 
    *   return (jQuery.browser.mozilla && navigator.userAgent.toLowerCase().indexOf('macintosh') != -1); 
    * }
    */

};



$(document).ready(function() {

    $('#buildingSSContentW div.ssThumbW div a').each(function() {
        // preload 546x images and attach to this <a>
    var medsrc = $(this).css('background-image').replace(/_[^.]+./, '_w546_h423.');
        // strip the url("") from url("http://server/path/to/image/pic.jpg")
        var imgurl = medsrc.replace(/^url\(\"|\"\)$/g, '');
        $.preloadImages(imgurl);
        $(this).attr('rel', medsrc);

        // show 546x image in focal area
        $(this).bind('mouseover', FCESlideShow.showContent);
        /* IE6 doesn't like my styles */
        $(this).bind('mouseenter', function() { $(this).find("span.thumbOut").css("visibility", "visible") })
        $(this).bind('mouseleave', function() { $(this).find("span.thumbOut").css("visibility", "hidden") })
        // show 1024x in a custom overlay
        $(this).bind('click', FCESlideShow.popOverlay);

        // save url of the big img
        FCESlideShow.bigsrcs.push(imgurl.replace(/_[^.]+./, '_w1024_h574.'));
        //FIXME
    });

    FCESlideShow.init();

    // preload all 1024x images 
    for (var i in FCESlideShow.bigsrcs) {
        $.preloadImages(FCESlideShow.bigsrcs[i]);
    }

});

