var Dialog = function() {
    //### private section ###

    var _width = 10;
    var _height = 10;
    var _show_loader = true;

    return {
        //### public section ###


        //preload data
        Preload: function() {
            // preload image
            // insert code here
        },

        //CREATES a dialog box of the DEFAULT size and is NOT VISIBLE. the content page must request a resize via parent.window.Dialog.Resize(w,h, visibility);
        Show: function(url) {
            try {
                //get form

                jQuery("form").append('<div id="dialog_container"><div id="dialog_overlay"></div><div id="dialog_image"></div><div style="display:none;" id="dialog"><iframe id="dialog_iframe" src="' + url + '" frameborder="0" scrolling="no"></iframe></div></div>');
                Dialog.Resize(_width, _height, false);
                


            }
            catch (e) {
                alert(e);
            }
        },

        //not currently used
        Redirect: function(url, width, height) {
            jQuery("#dialog_iframe").attr("src", url);
            Dialog.Resize(width, height, false);
        },

        //REMOVES the dialog box but does not cause a page refresh
        Hide: function() {
            try {
                jQuery("#dialog_container").remove();
                jQuery('embed, object, select').css({ 'visibility' : 'visible' });
            }
            catch (e) {
                alert(e);
            }
        },
        //REMOVES the dialog box and reloads the url
        Close: function() {
            try {

                //jQuery("#dialog_container").remove();
                //jQuery('embed, object, select').css({ 'visibility' : 'visible' });
                location.reload(true);
            }
            catch (e) {
                alert(e);
            }
        },
        PreventNextShowLoad: function()
        {
            _show_loader = false;
        },
        ShowLoad: function() {
            if (_show_loader == true) {
                jQuery("#dialog").css({
                    'display': 'none'
                });
                jQuery("#dialog_image").css({ 'z-index': 120 });
            }
            else {
                _show_loader = true;
            }
        },

        //resize dialog box
        Resize: function(width, height, visible) {
            
            if (!visible) {
                jQuery("#dialog").css({
                    'display': 'none'
                });
                jQuery("#dialog_image").css({ 'z-index': 120 });
            }
            jQuery("#dialog").width(width);
            jQuery("#dialog").height(height);
            jQuery("#dialog").css({
                'left': parseInt((document.viewport.getWidth() - width) / 2),
                'right': parseInt((document.viewport.getWidth() - width) / 2),
                'top': parseInt((document.viewport.getHeight() - height) / 2),
                'bottom': parseInt((document.viewport.getHeight() - height) / 2)
            });

            var image_width = jQuery("#dialog_image").width();
            var image_height = jQuery("#dialog_image").height();
            jQuery("#dialog_image").css({
                'left': parseInt((document.viewport.getWidth() - image_width) / 2),
                'right': parseInt((document.viewport.getWidth() - image_width) / 2),
                'top': parseInt((document.viewport.getHeight() - image_height) / 2),
                'bottom': parseInt((document.viewport.getHeight() - image_height) / 2)
            });

            if (visible) {
                jQuery("#dialog").css({
                    'display': 'block'
                });
                jQuery("#dialog_image").css({ 'z-index': 105 });
            }
            jQuery('embed, object, select').css({ 'visibility' : 'hidden' });
            //capture the focus (useful for when dialog box is created from fckeditor)
            jQuery('#dialog_iframe').focus();
        }

    }; //end return

    //### on load code ###
    //on page load call tb_init
    jQuery(document).ready(function() {
        Preload();

    });


} ();


