$(function() {
    $("<div>").attr('id', 'popup-bg').css({
        'z-index':1,
        'opacity':0.8
    }).appendTo('body');

    var height = 530;
    var width = 638;
    var popup = $("<div>").attr('id', 'popup').css({
        'height':height,
        'width':width,
        'left':$(window).width()/2 - width/2,
        'top':$(window).height()/2 - height/2,
        'border':'solid 2px #CCC'
    });
    popup.appendTo("body");
    popup.load(String(window.location), {
        'cmd':'getAgeDialog'
    }, function() {
        $("#age-true").click(function() {
            $.cookie("allow", "true", {
                path: "/"
            });
            $('#popup-bg, #popup').fadeOut('slow', function() {
                $('#popup-bg, #popup').remove();
            });
        });
        $("#age-false").click(function(event) {
            var replacement = $(event.target).children("div");
            if (replacement.size() != 0) {
                $(event.target).parent().fadeOut("slow", function() {
                    replacement.replaceAll($(event.target).parent()).fadeIn("slow");
                });
            }
            $("#popup-bg").animate({
                opacity: 1
            }, "slow");
        });
    });
});



