﻿if (typeof Vietgeek === 'undefined')
    var Vietgeek = {};

Vietgeek.MessageBox = function (options) {
    var defaults = {
        boxID: '#msgBox',
        contentID: '#msgBox-content',
        timeout: 5000,
        anchor: ['bl', 'tr'],
        offset: [0, 0]
    };

    var timerID,
    opts = $.extend({}, defaults, options);
    window.vgBoxID = opts.boxID;

    if ($(opts.boxID).length == 0) {
        $(document.body).append('<div id="' + opts.boxID.replace('#', '') + '" ><div id="msgBox-content" /></div>');
    }

    $(opts.boxID).bind('click', function () {
        if (timerID)
            clearTimeout(timerID);

        $(this).fadeOut();
    });

    var showMsgBox = function (obj, message) {
        $(opts.contentID).empty().html(message);
        $(opts.boxID).position(obj, {
            anchor: ['bl', 'tr'],
            offset: [0, 0]
        });

        if (timerID)
            clearTimeout(timerID);

        timerID = setTimeout('$(window.vgBoxID).fadeOut()', opts.timeout);
    };

    return {
        show: function (obj, message) {
            showMsgBox(obj, message);
        }
    };
};


