﻿


var Notify =
{
    tableSelector: "#notifyTable",
    containerSelector: "#notifyContainer",
    sampleHtml: '<tr class="notify" ><td class="notify--1">First time here? Check out the <a onclick="notify.closeFirstTime()">FAQ</a>!</td></tr></tbody></table> ',
    closeHtml: '<td class="notifyClose"><a onclick="Notify.hide()" title="dismiss this notification">×</a></td>',
    messageCookieName: 'notifyMessage',

    init: function() {

        $(Notify.containerSelector).append('<table id="notifyTable"></table>');

        // load messsages from cookie
        var msg = $.cookie(Notify.messageCookieName);
        if (msg) {

            msg = $.evalJSON(msg);
            Notify.show(msg);

            // wipe the once off cookie
            if (msg.IsOnceOff == true) {
                $.get('/ClearNotifyCookie');
            }
        }
    }
    ,

    show: function(message) {

        if (!message) {
            return;
        }

        var messages = $.makeArray(message);

        for (var m in messages) {
            $(Notify.tableSelector).append('<tr class="notify"><td>' + messages[m].Message + '</td>' + Notify.closeHtml + '</tr>')
        }
    },

    hide: function(index) {
        $(Notify.tableSelector).fadeOut();
    }

};