$(document.body).ready(function () {
    function Init() {
        $(".readmore").text('Seguir leyendo...');
        $(".noajaxcontinue").hide();
    }
    Init()
    $(".readmore").live("click", function () {
        // Obtenemos la ID...
        var id = /readmore-post-(\d+)/.exec(this.id)[1]
        $(this).hide();
        $('#restentry-id-' + id).html("<img src=\"/static/snow_nekmo/images/loading.gif\" alt=\"Loading...\" class=\"loading\" />")
        $('#restentry-id-' + id).load('/ajax/post-' + id).hide().fadeIn(500);
        $('#comment-' + id).load('/ajax/comment-' + id + '-0').hide().fadeIn(1000);
        $('#post-id-' + id + ' .options').fadeIn(500)
        $.get("/ajax/commentbox", {},
            function(data){
                var data = data.replace(/%ID/g, id)
                $('#writebox-' + id).html(data)
            }
        );
        $('#writebox-' + id).hide().fadeIn(1500)
            
    });
    
    $('.next').live("click", function () {
        // Obtenemos la ID...
        var id = /next-id-(\d+)/.exec(this.id)[1]
        $('#comment-' + id).html("<img src=\"/static/snow_nekmo/images/loading.gif\" alt=\"Loading...\" class=\"loading\" />")
        $('#comment-' + id).load('/ajax/comment-' + id + '-1');
    });
    
    $('.maximize').live("click", function () {
        // Obtenemos la ID...
        var id = /maximize-id-(\d+)/.exec(this.id)[1]
        $('#comment-' + id).html("<img src=\"/static/snow_nekmo/images/loading.gif\" alt=\"Loading...\" class=\"loading\" />")
        $('#comment-' + id).load('/ajax/comment-' + id + '-1');
    });
    
   $(".minimize").live("click", function () {
        // Obtenemos la ID...
        var id = /minimize-id-(\d+)/.exec(this.id)[1]
       $('#restentry-id-' + id).text('');
       $('#comment-' + id).hide();
       $('#writebox-' + id).text('');
       $('#readmore-post-' + id).show();
       $('#post-id-' + id).hide();
   });
   
   $(".exit").live("click", function () {
        // Obtenemos la ID...
        var id = /exit-id-(\d+)/.exec(this.id)[1]
       $('#post-id-' + id).fadeOut(500);
       $('#comment-' + id).fadeOut(1000);
       $('#writebox-' + id).fadeOut(1500);
   });
   
   $('.loading2').live("click", function () { $(this).slideUp(500); } );
    
    $(window).scroll(function(){
        if  ($(window).scrollTop() == $(document).height() - $(window).height()){
            var a = parseInt( /p(\d+)/.exec($("div.id_page:last").attr('id'))[1] )
            $('body').append('<div class="loading2"><img src="/static/snow_nekmo/images/loading.gif" alt="Loading..." /><p>Cargando siguiente página...</p></div>')
           $("div.id_page:last").load( '/ajax/posts-' + (a + 1 ), {}, function () { $('.loading2').slideUp(500); } )
            
//             $('.loading2').text('');
        } });
   
$(".vote").live("click", function () {
       var regex = /vote-(\w+)-(\d)-(\d+)/.exec(this.id)
       var id = regex[3]
       var type_send = regex[1]
       var val = regex[2]
       $('#post' + id + " p").html('Enviado...')
       $.ajax({  
  type: "POST",  
   url: "/vote_" + type_send + "/" + id,  
   data: 'val=' + val,
   complete: function(XMLHttpRequest) {
       $('#post' + id + " p").html(XMLHttpRequest.responseText)
       $('#post' + id + " img").hide()
   }
   });
   $('div#' + type_send + id ).hide().fadeIn(500)
   return false;
   });
   
});

