function mAlert (message) {
    var bigBackground = $('<div/>');
    $(bigBackground).attr('id', 'bigBackground');
    $('body').append(bigBackground);

    var newalert = $('<div/>');
    var scrolltop = $(window).scrollTop();
    var bodywidth    = $(window).width();
    var windowheight = $(window).height();
    var padding = 20;
    var modalwidth  = 510;
    var modalheight = 400;
    var modalheight_max = 500;
    var modaluppertdheight = modalheight - 100;
    var leftpos = bodywidth/2 - modalwidth/2;
    var toppos  = windowheight/2 - modalheight/2 + scrolltop;
    $(newalert).attr('id', 'newAlert').css({'opacity':'1', 'top':toppos+'px', 'left':leftpos+"px", 'backgroundColor':'white', 'textAlign':'left', 'fontSize':'14px', 'fontWeight':'normal', 'padding':'0px', 'height':modalheight+'px', 'width':modalwidth+'px', 'position':'absolute', 'overflow':'auto'});

    html = '<table width="100%" height="100%">';
    html+= '<tr><td class="modal" style="padding:'+padding+'px '+padding+'px 0 '+padding+'px;vertical-align:top;height:'+modaluppertdheight+'px;"><div id="message">'+message+'</div></td></tr>';
    html+= '<tr><td class="modal" style="padding:0 '+padding+'px '+padding+'px '+padding+'px;text-align:right;"><img src="gfx/logo_slogan.png" alt="" /></td></tr>';
    html+= '</table>';
    $(newalert).html(html);

    var background = $('<div/>');
    $(background).css({"opacity":"0","filter":"alpha(opacity=0)","-moz-opacity":"0"});
    $(background).attr('id', 'overlayBackground').attr("onclick","mAlertFadeOut();").css({'width':$(document).width(),'height':$(document).height()}).animate({'opacity':'.8'},1000,function() {
        $("#bigBackground").append(newalert);
    }).animate({'opacity':'.8'},100,function(){
        message_height = $("#message").height();
        message_height_padding = message_height - 2*padding;
        if ((message_height_padding) > modalheight) {
            if (message_height_padding > modalheight_max) {
                message_height_padding = modalheight_max;
            }
            diff = message_height_padding - modalheight;
            $(newalert).animate({height: message_height_padding+'px',top:toppos-diff/2+'px'},500);
        }
    });

    $("#bigBackground").append(background);

    $(window).resize(function(){
        var scrolltop = $(window).scrollTop();
        var bodywidth    = $(window).width();
        var windowheight = $(window).height();
        var modalheight = $("#newAlert").height();
        var leftpos = bodywidth/2 - modalwidth/2;
        var toppos  = windowheight/2 - modalheight/2 + scrolltop;
        $("#newAlert").animate({top:toppos+'px',left:leftpos+'px'},500);
        $("#overlayBackground").css({'width':$(document).width(),'height':$(document).height()});
    });
    $(window).scroll(function(){
        var scrolltop = $(window).scrollTop();
        var bodywidth    = $(window).width();
        var windowheight = $(window).height();
        var modalheight = $("#newAlert").height();
        var toppos  = windowheight/2 - modalheight/2 + scrolltop;

        $("#newAlert").animate({top:toppos+'px'},100);
    });
}

function mAlertFadeOut () {
    $("#bigBackround,#newAlert,#overlayBackground").animate({'opacity':'0'},1000,function() {
        $("#bigBackround,#newAlert,#overlayBackground").remove();
    });
}

$(document).ready(function () {
    if (artfvcookie==0) {
        $.ajax({
            url: 'x_modaltext.php',
            dataType: 'html',
            success: function (resp) {
                mAlert(resp);
                //document.cookie = "artfvcookie=1;path=/";
            }
        });
        $(document).keypress(function(e){
            if (e.which==0) { mAlertFadeOut(); $(this).unbind('keypress'); }
            else { e.preventDefault(); }
        });
    }
});
