
$(document).ready(function() {
  // Register the link
  $("a").click(function() {
    
    var url = $(this).attr("href");
    // Find the ?
    var index = url.indexOf('.php');
    if (index != -1) {
      // Strip anything before the ?
      url = url.substr(index+5, url.length);
    }
    
    // Find the first /
    var index = url.indexOf('/');
    if (index != -1) {
      // Strip anything before the first /
      //url = url.substr(index+1, url.length);
    }
    
    loadPage($(this).attr("href"));
    window.location.hash = url;
    recentHash = url;
    return false;
  });
  
});

/**
 * Load in a page via AJAX
 */
function loadPage(page) {
  
  $("#content-main").html("<div id=\"content-top\"></div><div id=\"content-center\" class=\"loading\"><img src=\"/images/loading.gif\" alt=\"loading...\" /><p>loading ...</p></div>");
  
  $.get(page, {  },
  function(data) {
    
    // Display the loaded page
    $("#content-main").html(data);
    
    $.scrollTo(0);
    
    return false;
  });
  return false;
}
