var notificationHTML = '<div id="notificationContainer" style="display:none; padding:5px 10px; position: fixed; top: 10px; color:#492D78; ' +
                            ' background-color: #fcf67e; font-weight: bold; display: none;"><div id="notificationMessage">&nbsp;</div></div>';

$.fn.center = function ()
{

    var marginLeft = (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft();
    marginLeft = marginLeft > 0 ? marginLeft : 0;

    this.css("margin-left", marginLeft + "px");
    return this;
}

var notificationContainer = null;
var notificationMessage = null;

var DEFAULT_HANGTIME = 5000;  // 5 seconds default time for notification visibility

function showNotification(message, hangtime)
{
    removeNotification();
    addNotification();
    notificationMessage.html(message);

    repositionNotification();

    // Default load hangtime? not a good idea, but just in case we want to, use the following feature
    //if (hangtime == undefined || hangtime == 0)
    //    hangtime = DEFAULT_HANGTIME;

    if (hangtime > 0)
        notificationContainer.stop(true, true).fadeIn("fast").delay(hangtime).fadeOut("slow");
    else
        notificationContainer.stop(true, true).fadeIn("fast");          // do not remove from screen

}

function hideNotification()
{
    if (notificationExists())
    {
        notificationContainer.stop(true, true).hide();
    }
}

function addNotificationIfNotExit()
{
    if (!notificationExists())
    {
        addNotification();
    }
}

function addNotification()
{
    if (!notificationExists())
    {
        $(document.body).append(notificationHTML);
        notificationContainer = $("#notificationContainer");
        notificationMessage = $("#notificationMessage");
    }
}

function removeNotification()
{
    if (notificationExists())
    {
        notificationContainer.remove();
    }
}

function repositionNotification()
{
    notificationContainer.center();
}

function notificationExists()
{
    notificationContainer = $("#notificationContainer");
    if (notificationContainer.length > 0)
        return true;
    return false;
}

