(function($) {
    BigDoggie = function() { };

    BigDoggie.Dialog = function(node) {
        var self = this;
        this.node     = node;
        this.width    = 460;
        this.hpadding = 40;
        this.vpadding = 100;
        this.title    = 'BigDoggie News';
    };

    BigDoggie.Dialog.prototype = {
        calcHeight: function() {
            /* Get a handle to the first <div> inside the <iframe> */
            var iFrame   = $(this.node).find('iframe')[0];
            var innerDiv = $(iFrame).contents().find('body div:first')[0];

            /* Force the width of the <div> (so the height recalculates) */
            innerDiv.style.width = this.width + 'px';

            /* Grab the height of the <div> */
            this.height = innerDiv.scrollHeight;
        }

        ,show: function() {
            this.calcHeight();
            var dialog = $(this.node).dialog( {
                modal:     true,
                height:    this.height + this.vpadding,
                width:     this.width  + this.hpadding,
                resizable: true,
                title:     this.title,
                buttons:   {
                    Ok: function() { $(this).dialog('close'); }
                }
            } );

            if ($.browser.msie) {
                /* jQuery.UI Dialog sets wrong height in IE, so set again */
                dialog.height(this.height + this.vpadding);
            }
        }

        ,autoShow: function() {
            var iFrame = $(this.node).find('iframe').contents()[0];

            if ((iFrame != undefined) && (iFrame.readyState == 'complete')) {
                this.show();
                return;
            }

            var self = this;
            setTimeout(function() { self.autoShow() }, 100);
        }
    };
})(jQuery);

