function msg(text, type) {
	
    removeCloud();
	
    var id = 'msg-' +  Math.floor(Math.random()*1000);
    var document_width = $('body').width();
    var correction_x = -12;
    var min_margin_right = 385;
    
    var GRID_X = 15;
    var GRID_Y = 15;
   
    POSITION_X = Math.round(POSITION_X / GRID_X) * GRID_X;
    POSITION_Y = Math.round(POSITION_Y / GRID_Y) * GRID_Y;
    
    if (document_width-POSITION_X < min_margin_right)
    {
        correction_x -= min_margin_right-(document_width-POSITION_X);
    }
       
    var msg = $('<div class="msg info" style="display: block; z-index: 99999; position: absolute; left:' + (POSITION_X+correction_x) + 'px; top:' + (POSITION_Y + 10) + 'px; background-color:#000000;">' +
    '<a href="javascript: removeCloud();" title="zamknij" class="msg-close" style="float: right;">[x]</a>' + 
    '<div class="msg-head"></div>' +
    '<div class="msg-content">'
    + text +
    '</div>' +
    '<div class="msg-foot"></div>' + 
    '</div>');
    $('body').prepend(msg);
    return msg;
}

function msginfo(text)
{
    msg(text, 'info');
    return false;
}

function msgerror(text)
{
    msg(text, 'error');
    return false;
}

function msgflash(text, timeout)
{
    if(!timeout)
        timeout = 2000;
    var message = msg(text, 'error');
    message.find('.msg-close').remove();
    setTimeout(function(){$(message).fadeOut('slow')}, timeout);
}

function msgwarning(text)
{
    return msg(text, 'warning');
    return false;
}

function removeCloud()
{
    $('div.msg.info').each(
        function() {
            $(this).remove();
        }
        );
}
