
$(document).ready(function() {

    $(".vote_arrow" ).click(function() {
        post_vote( $(this).parents("li") );
    });

    callTimeago();
    $("img").error(function () {
        $.ajax({
          url: "/feed/update_feed",
          cache: false,
          type: "get",
          data: ({id : $(this).attr("id")})
        });
        $(this).unbind("error");
    });
    
});

function callTimeago(){
    $(".timeago").timeago();
}

function post_vote( li_element ){
    var votes = parseInt( $(li_element).find(".votes").html() );
    $(li_element).find(".votes").html( votes +1 );

    var element = $(li_element).find(".up_vote");

    $(li_element).find(".up_vote").fadeOut('slow', function() {
        $(li_element).find(".up_vote .vote_arrow").attr("src", "/images/up_arrow_disabled.png");
        $(li_element).find(".up_vote .vote_arrow").unbind();
        $(li_element).find(".up_vote").replaceWith( $(li_element).find(".up_vote .vote_arrow") );
        $(li_element).find(".up_vote").fadeIn();
    });

    
    $(li_element).find(".down_vote").fadeOut('slow', function() {
        $(li_element).find(".down_vote .vote_arrow").attr("src", "/images/down_arrow_disabled.png");
        $(li_element).find(".down_vote .vote_arrow").unbind();
        $(li_element).find(".down_vote").replaceWith( $(li_element).find(".down_vote .vote_arrow") );
        $(li_element).find(".down_vote").fadeIn();  
    });
    
}