/*
 * Base modal class that internally selects a library for implementing a few basic modal functions.
 *
 * Gives access to:
 *      Show text
 *      Show HTML
 *      Show URL
 *
 * Various options also available.
 *
 * Version: 0.1
 *      Uses jqModal internally which also requires jQuery.
 */

Namespace.Manager.Register( "Modal" );

Modal = {
    m_target_div: null,

    Show_text: function( text, options )
        {
            Modal.m_target_div.jqm( Modal.Create_jqm_options( options ) );
            Modal.m_target_div.text( text );
            Modal.m_target_div.jqmShow();
        },
    Show_html: function( html, options )
        {
            Modal.m_target_div.jqm( Modal.Create_jqm_options( options ) );
            Modal.m_target_div.html( html );
            Modal.m_target_div.jqmShow();
        },
    Show_url: function( url, options )
        {
            var height = options.height;
            var height_str = "";
            var iframe_str = "";

            if( height !== undefined && height !== null ) {
                height_str = " height=\"" + height + "px\"";
            }

            iframe_str = "<iframe src=\"" + url + "\" width=\"100%\"" + height_str + "></iframe>";

            return Modal.Show_html( iframe_str, options );
        },
    Create_jqm_options: function( options )
        {
            var jqm_options = {};

            if( options !== undefined ) {
                if( options.modal === true ) {
                    jqm_options.modal = true;
                }
            }

            return jqm_options;
        }
};

$( function()
    {
        Modal.m_target_div = $( "<div class=\"jqmWindow\"></div>" );

        $( "body" ).append( Modal.m_target_div );
    }
);

