var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    background: '#000',
    opacity: '.6',
    contentType: 'image',
    close: function() {
        //$(modal).animate({ 'opacity': 0 }, 500);
        $("#modal-window").animate({ 'opacity': 0 }, 500, function() {
            $(this).remove();

            $("#modalWrap").animate({ 'opacity' : 0 }, 500, function(){
                $(this).remove();
                $("#overlay").remove();
            });
        });

    },
    open: function() {

        if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
            $("body", "html").css({ 'height': '100%', 'width': '100%' });
        }

        // create overlay
        $('<div>').attr('id', 'modalWrap').appendTo(this.parent);
        var overlay = $('<div>').attr('id', 'overlay').appendTo('#modalWrap');

        // create modal wrapper
        var modal = $('<div>').attr('id', 'modal-window').appendTo('#modalWrap');
        var modalContent;

        switch (this.contentType) {
            case 'image':
                modalContent = "<img src='" + this.content + "&w=" + this.width + "' />";
                break;
            case 'flash':
                modalContent = "<object width='" + this.width + "' height='" + this.height + "'><param name='movie' value='" + this.content + "?autoplay=1&fs=0&color1=0x999999'&color2=0xcccccc&border=1&showsearch=0&hd=1></param><embed src='" + this.content + "?autoplay=1&fs=0&color1=0x999999&color2=0xcccccc&border=1&showsearch=0&hd=1' type='application/x-shockwave-flash' width='" + this.width + "' height='" + this.height + "'></embed></object>";
        }

        // create modal content
        $(modal).html("<div id='modal_content'><a href='#close'>Close</a>" + modalContent + "</div>").css({
            'opacity': 0,
            'width': 6 + this.width + 'px',
            'height': 38 + this.height + 'px',
            'margin-top': -(300) + 'px',
            'margin-left': -(this.width / 2) + 'px'
        });

        //        if (!(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
        //            $(modal).css({
        //                "margin-top": -(this.height / 2) + 'px'
        //            });
        //        }

        $('#modal_content a').click(function() {
            modalWindow.close();
            return false;
        });

        $(overlay).css({ 'opacity': 0, 'background': this.background }).animate({ 'opacity': this.opacity }, 1000, function() {

            $(modal).animate({ 'opacity': 1 }, 500);
        });

        $(".close-window").click(function() { modalWindow.close(); });
        $("#overlay").click(function() { modalWindow.close(); });
    }
};

