if (window.ubcurtain == null) {
    ubcurtain = {};

    ubcurtain.scrollCurtain = function() {
        var win = $(window);
        var sElement = $(".ubCurtain").attr("tarElement");
        var oElement = $(sElement);
        oElement.css(
	{
	    top: win.scrollTop() + (win.height() / 2 - oElement.height() / 2),
	    left: win.scrollLeft() + (win.width() / 2 - oElement.width() / 2)
	});
        $(".ubCurtain").css(
			{ top: win.scrollTop(),
			    left: win.scrollLeft(),
			    width: win.width(),
			    height: win.height()
			}
				);
    };

    ubcurtain.hide = function() {
        $(".ubCurtain").hide();
        //set pic to blank so load event will fire if same pic clicked
        var sElement = $(".ubCurtain").attr("tarElement");
        $(sElement).hide();

        $(window).unbind('scroll', this.scrollCurtain);
        $(window).unbind('resize', this.scrollCurtain);
        //unbind so clicking background while loading doesn't hide
    };
    ubcurtain.initCurtain = function() {
        $("body").append('<div class="ubCurtain" style="z-index:900;cursor:hand;display:none;position:absolute;background-color:black"></div>')
        $(".ubCurtain").fadeTo(1, 0.8);
        //$(".ubCurtain").click(this.hideCurtain);
        this.curtainReady = true;
    };

    ubcurtain.show = function(tarElement, closeOnBGClick, animFunc) {
        if (this.curtainReady != true) {
            this.initCurtain();
        }

        if (closeOnBGClick == true) {
            $(".ubCurtain").click(this.hide);
        }
        else {
            $(".ubCurtain").unbind('click', this.hide);
        }
        var win = $(window);
        //position background
        $(".ubCurtain").css(
			{ top: win.scrollTop(),
			    left: win.scrollLeft(),
			    width: win.width(),
			    height: win.height(),
			    display: 'block'
			}
				).show();
        $(".ubCurtain").attr("tarElement", tarElement);
        win.scroll(this.scrollCurtain);
        win.resize(this.scrollCurtain);
        //position element

        var oElement = $(tarElement);
        if (animFunc == null) {
            //no extra function specified just show
            oElement.css(
	                {
	                    position: 'absolute',
	                    'z-index': 1000,
	                    top: win.scrollTop() + (win.height() / 2) - (oElement.height() / 2),
	                    left: win.scrollLeft() + (win.width() / 2) - (oElement.width() / 2),
	                    display: 'block'
	                }).show();
        }
        else {
            //custom anim specified, position by hide element
            oElement.css(
	                {
	                    position: 'absolute',
	                    'z-index': 1000,
	                    top: win.scrollTop() + (win.height() / 2) - (oElement.height() / 2),
	                    left: win.scrollLeft() + (win.width() / 2) - (oElement.width() / 2),
	                    display: 'none'
	                });
            animFunc();
        }


    }



}
