/**
 * Common AJAX setup
 */

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

// prolínací efekt při updatu snippetu
jQuery.extend({
    nette: {
        updateSnippet: function (id, html) {
            $("#" + id).fadeTo("fast", 0.3, function () {
                $(this).html(html).fadeTo("fast", 1);
                $.nette.registerAfterUpdate();
            });
        },

        registerAfterUpdate: function() { }
    }
});

/**
 * Texyla
 */
/*
$(function () {
    Texyla.prototype.submit = function () {
        var f = this.textarea.get(0).form;
        if (!(typeof f.onsubmit == 'function') || f.onsubmit()) {
            $(f).ajaxSubmit();
            return false;
        }
    };
});

$(function () {
    $.texyla.setDefaults({
        bottomRightEditToolbar: ['submit'],
        previewPath: '/texy/',
        width: null,
        linkWindowDimensions: [400, 240]
    });
});

$('#snippet-discussion-notes-wrapper .texyla textarea').livequery(function () {
    $(this).texyla({
        toolbar: [
            'bold', 'italic',
            null,
            'ul', 'ol',
            null,
            'link',
        ],
        texyCfg: 'comment'

    });
});

$('.texyla .button').livequery(function () {
    $(this).parent().parent().hide();
});

*/

/**
 * AJAX support
 */

//form buttons
$("form.ajax :submit").live("click", function (e) {
    $(this).ajaxSubmit(e);
    return false;
});

// form submit
$("form.ajax").livequery("submit", function (e) {
    $(this).ajaxSubmit(e);
    return false;
});

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