var lightBoxController = (function(){
    var utils = {
        maxWidth : function () {
            return $(window).width()+'px';
        },
        maxHeight : function () {
            return window.opera
                ? document.body.scrollHeight + "px"
                : $( document.body ).height() + "px" ;
        },
        scrlTop : function () {
            return $.browser.msie
                ? ( document.body.scrollTop || document.documentElement.scrollTop )
                : 0 ;
        },
        dispTop : function (elm) {
            return ( ( window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight ) / 2 )
                - ( $(elm).height() / 2 )
                + ( document.documentElement.scrollTop || document.body.scrollTop || 0 )
                + 'px';
        },
        dispLeft : function (elm) {
            return ( $( window ).width() / 2 ) - ( $(elm).width() / 2 ) + "px";
        }
    };

    var self = {
        show : function (dispElm, fn, noBackgroudClose) {
            // background
            var lbObj = $('div#lightbox-display').css({
                position : 'absolute',
                width    : utils.maxWidth(),
                height   : utils.maxHeight(),
                top      : utils.scrlTop(),
                'background-color': '#000',
                filter   :'alpha(opacity=80)',
                '-moz-opacity': 0.8,
                opacity  : 0.8
            }).show()
            
            if (!noBackgroudClose) {
                lbObj.click(function(){
                    self.hide();
                });
            }

            // box content
            dispElm.appendTo($('body')).css({
                position : 'absolute',
                top      : utils.dispTop(dispElm),
                left     : utils.dispLeft(dispElm),
                zIndex   : 1000
            });

            if (fn) fn();
            
            // set active box
            self.openedElm = dispElm;
        },
        hide : function (fn) {
            self.openedElm.remove();
            $('div#lightbox-display').hide();
            if (fn) fn();
        }
    };
    return self;
})();

