﻿/* ******************************************** *\
|*                                              *|
|*        Auto Modal Dialog javascript          *|
|*                                              *|
\* ******************************************** */

AutoModalDialog = function(cookieExpiration) {
    this.initialize(cookieExpiration);
}

AutoModalDialog.prototype = {
    _cookieExpiration: 0,

    initialize: function(cookieExpiration) {
        this._cookieExpiration = cookieExpiration;
        jQuery(document).ready(this.onReady);
    },

    onReady: function() {
        autoModalDialog.open();

        jQuery("#auto-modal-content a[href]").bind("click", autoModalDialog.onLinkClick);
    },

    open: function() {
        jQuery("#auto-modal-content").overlay({
            mask: {
                color: "#000",
                loadSpeed: 200,
                opacity: 0.5
            },

            onClose: function() {
                autoModalDialog.close();
            },

            top: "30%",
            left: "center",

            closeOnClick: true,
            closeOnEsc: false,

            load: true
        });
    },

    close: function() {
        // Force to remove for IE problem... hide is not sufficient...
        jQuery("#auto-modal-content").remove();
        jQuery("#exposeMask").remove();
    },

    createCookie: function() {
        var date = new Date();
        date.setTime(date.getTime() + (autoModalDialog._cookieExpiration * 60 * 1000));
        jQuery.cookie('overlay', 'test', { path: '/', expires: date });
    },

    onLinkClick: function(e) {
        autoModalDialog.createCookie();
        autoModalDialog.close();
        return true;
    }
}
