/* manage gallery images for 'work' page. */
var imageCtrH;

$(document).ready( function() { 

        $('#workImageNav a').bind('click', showPic);

        // enough vert space for tallest img
        /* "cannot have things shifting around" anymore, by req.
         * var maxH = 0;
         * $('.galleryItem img').each( function() {
         *    var h = $(this).attr('height');
         *    if (maxH < h) maxH = h;
         * });
         * $('#workGalleryItemsW').height(maxH + 10);
         */

         /* vertically center all images, by req */
         imageCtrH = parseInt($('#workGalleryItemsW').css('height'));
         $('.galleryItem img').each( function() {
             var marg = parseInt((imageCtrH - $(this).attr('height')) /2);
             $(this).css('margin-top', marg + 'px');
         });


});

var showPic = function() {
    if ($(this).hasClass('activeImage')) {
        $(this).blur();
    } else {
        if (m = $(this).attr('href').match(/(\d+)/)) {
            var num = m[1];
            $('.galleryItem').hide().removeClass('sel');
            var imgCtr = '#galleryItem_'+num;
            $(imgCtr).fadeIn('fast');

            if ($.browser.msie) { // MSIE7 can't give the height of an image that is display:none it seems. So vert center now -
                var ht = $(imgCtr + '> img').height();
                var marg = parseInt((imageCtrH - ht) /2);
                $(imgCtr + '>img').css('margin-top', marg + 'px');
            }

            $('#workImageNav a').removeClass('activeImage');
            $(this).addClass('activeImage').blur();
        }
    }

};

