$(document).ready(function(){
    // Lightbox...
    $('a.lightbox').lightBox({
        imageLoading:	 "/pipecms/images/lightbox-ico-loading.gif",
        imageBtnPrev:	 "/pipecms/images/lightbox-btn-prev.gif",
        imageBtnNext:	 "/pipecms/images/lightbox-btn-next.gif",
        imageBtnClose: "/pipecms/images/lightbox-btn-close.gif",
        imageBlank:	 "/pipecms/images/lightbox-blank.gif"
    });

    // Show countdown in days...
    $('.countdown').each(function (index, value) {
        var date = Date.parse($(value).html().replace(/\./g, "/"));
        var now = (new Date()).getTime();
        var ms = date - now;
        var days = Math.round((ms / 1000 / 60 / 60 / 24) + .5);

        var new_value;
        if (days == 1) 
            new_value = "tomorrow";
        else if (days == -1) 
            new_value  = "yesterday";
        else if (days == 0) 
            new_value  = "today";
        else if (days > 0) 
            new_value  = "" + days + " days from now";
        else if (days < 0)
            new_value  = "" + (-1 * days) + " days ago";

        value.old_value = $(value).html();
        value.new_value = new_value;
        $(value).html(new_value);

        $(value).mouseover(function() {
            if (this.already_swapped) 
                return;

            this.already_swapped = true;

            $(this).
                hide().
                html(this.old_value).
                fadeIn('fast');
            
            var target = this;
            setTimeout(function() {
                target.already_swapped = false;
                $(target).
                    hide().
                    html(target.new_value).
                    fadeIn('slow');
            }, 3000);
            
        });
    });


});

