$(document).ready(function() {
    $('.flight-search-button').click(function() {
        FlightSearchOverlay();
        return false;
    });

    $('.email-page-button').click(function() {
        EmailPageOverlay();
        return false;
    });
})

//NOTE: the dialogs use jQuery 1.4.3 (using noConflict())
var emailPageOverlay = null;
var flightSearchOverlay = null;
(function($) {
    EmailPageOverlay = function() {
        emailPageOverlay = $('body').gtaaOverlay({ type: "iframe", src: "dialog_emailpage.aspx", width: 620, height: 530 });
        emailPageOverlay.openDialog();
    }
    FlightSearchOverlay = function() {
        flightSearchOverlay = $('.flight-search-dialog').gtaaOverlay();
        flightSearchOverlay.openDialog();
    }
})(jQuery143);


(function($) {
    // constructor
    function GTAAOverlay(root, conf) {
        // Private fields ------------------------------------------------------------------

        var $root = $(root),
			$domElem = $root[0],
			_self = this,
			$opts = {};

        $.extend($opts, conf);

        // Public methods ------------------------------------------------------------------

        $.extend(_self, {
            openDialog: function() {
                $root.dialog("open");
                return false;
            },
            closeDialog: function() {
                $root.dialog("destroy");
                return false;
            }
        });

        // Private methods -----------------------------------------------------------------

        function init() {
            if ($opts.type == 'iframe' && typeof ($opts.src) != "undefined") {
                $root = $('<div class="ui-dialog-iframe" style=""><iframe src="' + $opts.src + '" frameborder="0" width="' + ($opts.width - 12) + '" height="' + ($opts.height - 12) + '" /></div>', document);
                //ie8 is adding 36px to the "non content" height of the dialogs for margins and padding
                //we need to take add it to the dialog height in order to keep scroll bars from appearing
                if (isIE) {
                    $opts.height += 36;
                }
            }

            $root.addClass("ui-dialog-wrapper").children().wrapAll('<div class="dialog-content-wrapper"></div>');
            $root.prepend('<div class="dialog-controls-top"><a class="ui-dialog-close tabs-text sec-none-off" href="#">X CLOSE</a></div>');
            $root.dialog($opts).find(".ui-dialog-close").click(_self.closeDialog);

        };

        // Initialization ------------------------------------------------------------------

        init();
    };

    // jQuery plugin implementation
    $.fn.gtaaOverlay = function(conf) {
        //defaults
        var opts = {
            modal: true,
            height: 'auto',
            width: 'auto',
            closeOnEscape: true,
            autoOpen: false,
            draggable: false,
            resizable: false
        };

        $.extend(opts, conf);

        var $instance;

        this.each(function() {
            $instance = new GTAAOverlay(this, opts);
        });

        return $instance;
    };
})(jQuery143);

