$(document).ready(function() {
  $("input.replace_text").focus(function() {
    if( this.value == this.defaultValue ) {
        this.value = "";
    }
  }).blur(function() {
    if( !this.value.length ) {
        this.value = this.defaultValue;
    }
  });
  // Sidebar toggler
   $(".section h4").bind("click", function(e){
     $(this).siblings('ul').toggle();
   });
   $('a.remote').bind('click', function(e) {
     e.preventDefault();
     if(!$(this).hasClass('rendered')) {
       $(this).addClass('rendered');
       render_remote($(this).attr('id').split('_')[1]);
     }
   })
  $(".post img").lazyload({
    effect:"fadeIn",
    placeholder: "http://ritholtz.com/blog/wp-content/themes/thebigpicture/images/grey.gif"
  });
})

function render_remote(cat_id) {
  //check if it has been rendered already
  category = $.getJSON('/blog/', { json: 'get_category_posts', category_id: cat_id, count: 5, order: 'DESC' }, function (data) {
    $.each(data.posts, function(i,post) {
      jQuery('#category_'+cat_id).parent().siblings('ul').append('<li class="reg_list"><a href="'+post.url+'">'+post.title+'</a></li>')
    })
  });
}
