/**
 * AJAX Nette Framwork plugin for jQuery
 *
 * @copyright  Copyright (c) 2009 Jan Marek
 * @license    MIT
 * @link       http://nettephp.com/cs/extras/jquery-ajax
 * @version    0.1
 */

jQuery.extend({
        updateSnippet: function (id, data) {
                $("#" + id).fadeOut("fast", function () {
                        $(this).html(data).fadeIn("fast");
                });
        },

        netteCallback: function (data) {
                // redirect
                if (data.redirect) {
                        window.location.href = data.redirect;
                }

                // snippets
                if (data.snippets) {
                        for (var i in data.snippets) {
                                jQuery.updateSnippet(i, data.snippets[i]);
                        }
                }
        }
});

jQuery.ajaxSetup({
        success: jQuery.netteCallback,
        dataType: "json"
});

$(function () {
    $('<div id="ajax-spinner"></div>').ajaxStart(function () {
        $(this).show();
    }).ajaxStop(function () {
        $(this).hide();
    }).appendTo("body").hide();
});

$(function () {
    $("a.ajax").live("click", function () {
        $.get(this.href);
        return false;
    });
});

