//Inserts a list of top rated blog posts at the top of the blog list page

var page_url = window.location.pathname;
var on_blog_display_page = page_url.match('/profiles/blog/list'); 
if(on_blog_display_page != null) {
  //Fucntion to make request to blog_rater.php to see what score this blog post has
  function make_list() {
    x$.getJSON('/blog_rater/blog_rater.php?action=get', function(data) {
	  var list_html = '<div class="xg_module"><div class="xg_module_head"><h2>Highest Rated Blog Posts</h2></div><div class="xg_module_body"><ul class="nobullets">';
      //Build the list of highest reated blog posts
      for(i=0;i<=6;i++) {
        var id = data[i].id;
        var title = data[i].title;
        list_html += '<li><a href="/xn/detail/'+id+'">'+title+'</a></li>';
      }
      list_html += '</ul></div></div>';
      //Insert list of the highest scoring blog posts above the existing blog lists
	  x$("#xg_body div.xg_span-16 div.xg_last div.xg_module:nth-child(1)").before(list_html);
    });
  }
  make_list();
}
