LIGHTBOX = function(){
    var IE6 = false;
    if($.browser.version < 7.0 && $.browser.msie){
        IE6 = true;
    }
    return {
        show:function(content, callbacks){
            var bg = $("#lightbox_bg");
            if (bg.length == 0){
                buildBg();
            }
            else {
                bg.show()
                bg.fadeTo(200, 0.5);
            }
            buildLightBox(content, callbacks);
            if(IE6){
                $('body').find('select').css('visibility','hidden');
            }
        },
        hide:hideBg,
        update:updateContent
    };
    function hideBg(){
        $('#lightbox_container').remove();
        $('#lightbox_bg').hide();
        //have no choice but to test for IE6 
        //to fix select box z-index problems
        if(IE6){
            $('body').find('select').css('visibility','visible');
        }
    }
    function buildBg(){
        var body = $('body');
        body.append('<div id="lightbox_bg"></div>');
        var bg = $('#lightbox_bg')
        bg.css({
            height:$(document).height(),
            opacity:0,
            position:'absolute',
            left:0,
            top:0,
            width:'100%',
            backgroundColor:'black',
            zIndex:3
            })
        bg.bind('click', hideBg); 
        bg.fadeTo(200, 0.5);
    }
    function updateContent(content){
        var lightbox = $('#lightbox_content');
        lightbox.html(content);
    }
    function buildLightBox(content, callbacks){
        var body = $('body');
        body.append('<div id="lightbox_container"><div id="lightbox_content"></div></div>');
        var lightbox = $('#lightbox_container');
        var lightboxContent = $('#lightbox_content');
        lightboxContent.append(content);
        window.scrollTo(0,0);
        var docTop = $(document).scrollTop();
        var winHeight = $(window).height();
        var winWidth = $(window).width();
        var lbHeight = lightbox.height();
        lightbox.css({
            top:docTop+(winHeight-lbHeight)/2,
            position:'absolute',
            zIndex:4
        })
        var lbWidth = lightbox.width();
	    if (lbWidth > 754) { 
	    	lbWidth = 754;
	    } 
	    if (lbHeight > 584) { 
	    	lbHeight = 584;
	    }

        lightbox.css("left",Math.ceil((winWidth - lbWidth)/2));
        $('#lightbox_content, #lightbox_content input, #lightbox_content textarea').focus();
        if(typeof(callbacks)!= undefined){
            for(c in callbacks){
                $("#"+c).bind('click',callbacks[c])
            }
        }
    }
}();

LIGHTBOX2 = function(){
    var IE6 = false;
    if($.browser.version < 7.0 && $.browser.msie){
        IE6 = true;
    }
    return {
        show:function(content, callbacks){
            var bg = $("#lightbox_bg");
            if (bg.length == 0){
                buildBg();
            }
            else {
                bg.show()
                bg.fadeTo(200, 0.5);
            }
            buildLightBox(content, callbacks);
            if(IE6){
                $('body').find('select').css('visibility','hidden');
            }
        },
        restrict:restrictImg,
        hide:hideBg,
        update:updateContent
    };
    function restrictImg() {
	    //if (document.getElementById('mainimg').width > 754) { 
	    	//document.getElementById('mainimg').width = 754;
	    //} 
	    //if (document.getElementById('mainimg').height > 584) {
	    	//document.getElementById('mainimg').height = 584;
	    //}
    }
    function hideBg(){
        $('#lightbox_container').remove();
        $('#lightbox_bg').hide();
        //have no choice but to test for IE6 
        //to fix select box z-index problems
        if(IE6){
            $('body').find('select').css('visibility','visible');
        }
    }
    function buildBg(){
        var body = $('body');
        body.append('<div id="lightbox_bg"></div>');
        var bg = $('#lightbox_bg')
        bg.css({
            height:$(document).height(),
            opacity:0,
            position:'absolute',
            left:0,
            top:0,
            width:'100%',
            backgroundColor:'black',
            zIndex:3
            })
        bg.bind('click', hideBg); 
        bg.fadeTo(200, 0.5);
    }
    function updateContent(content){
        var lightbox = $('#lightbox2_content');
        lightbox.html(content);
    }
    function buildLightBox(content, callbacks){
        var body = $('body');
        body.append('<div id="lightbox_container"><div id="lightbox2_content"></div></div>');
        var lightbox = $('#lightbox_container');
        var lightboxContent = $('#lightbox2_content');
        lightboxContent.append(content);
        window.scrollTo(0,0);
        var docTop = $(document).scrollTop();
        var winHeight = $(window).height();
        var winWidth = $(window).width();
        var lbHeight = lightbox.height();
        lightbox.css({
            top:docTop+(winHeight-lbHeight)/2,
            position:'absolute',
            zIndex:4
        })
        var lbWidth = lightbox.width();
	    if (lbWidth > 754) { 
	    	lbWidth = 754;
	    } 

        lightbox.css("left",Math.ceil((winWidth - lbWidth)/2));
        $('#lightbox2_content, #lightbox2_content input, #lightbox2_content textarea').focus();
        if(typeof(callbacks)!= undefined){
            for(c in callbacks){
                $("#"+c).bind('click',callbacks[c])
            }
        }
    }
}();
