Working with cookies and jQuery
===

Today I decided to get to understand cookies better. The easiest way seemed jQuery. I used carhartl's [Cookie plugin][1].

Here's a [**fiddle**][2].

Basically, what I want is: when a user clicks the 'X', the pop-up closes (works fine) and a cookie is written so that the next time that user hits that page, he doesn't see the pop-up again!

    function showPopUp() {
        var popUpMT = -($("#popUp").height() / 2) - 50;
        $("#popUp").css("marginTop", popUpMT).fadeIn("slow");
        $("#overlay").fadeIn("fast");
    }
    
    function setCookie() {
        $("#popUp").fadeOut("fast");
        $("#overlay").fadeOut("fast");
        $.cookie("popUpCookie", {
            expires: 365
        });
    }
    
    $(document).ready(function() {
        var ourCookie = $.cookie("popUpCookie");
        if (ourCookie === null) {
            showPopUp();
        }
    
        $("#popUp span#close").click(function() {
            setCookie();
        });
    });


  [1]: https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js
  [2]: http://jsfiddle.net/BramVanroy/Y3pjm/3/