jQuery.fn.submitWithAjax = function() {
  this.submit(function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })
  return this;
};


function resize(length) {
    return Math.floor(-0.16 * length + 60);
}

function czikit(t) {
    var th = $(t);
    $.post($(t).attr('href'), { authenticity_token: window._token }, function(data) {
        if(data != null) {
            $(th).parent().children('.thx').html('Dzięki!');
            $(th).parent().children('.ratingup').html(data.votes_up);
            $(th).parent().children('.ratingdown').html(data.votes_down);
        }
    }, "json");
    $(t).parent().children('.thumb').hide();
}

$(document).ready(function() {

    $("#loading").ajaxStart(function(){
       $(this).show();
    });
    $("#loading").ajaxStop(function(){
       $(this).hide();
    });

    $('#flash').fadeOut(2500);

    $('.czikit').click(function() {
        czikit(this);
        return false;
    });

    $('.guy').click(function() {
        var th = $(this);
        $.get('/?format=js', {}, function(data) {
            $(th).parent().children('div.center').html(data);
            $('.czikit').click(function() {
                czikit(this);
                return false;
            });
        }, 'javascript');
        return false;
    });

    $("#nav-one li").hover(
        function(){ $("ul", this).fadeIn("fast"); },
        function() { }
    );
    if (document.all) {
        $("#nav-one li").hoverClass ("sfHover");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover(
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};


