function loadPage(a_tag) {
    //$('.current_page_item').removeClass('current_page_item');
    $('.removable').remove();
    $.getJSON(a_tag.href, function(data){
      $.each(data, function(target, html){
        if (target == 'page_title') {
          $.each(html, function(index, content){
            document.title = content['html'];
            return;
          });
        }
        if (target == 'css') {
          $.each(html, function(index, content){
            $('.template_css').remove();
            $('head').append('<link class="template_css" rel="stylesheet" href="' + content + '" type="text/css" />');
            return;
          });
        }
        if (target == 'node_info') {
            $.each(html, function(index, content){
                if (!document.getElementById(index)) {
                    var parent_node = document.getElementById(content['parent_node']);
                    var newdiv = document.createElement('div');
                    $.each(content["attributes"], function(attr, value) {
                        newdiv.setAttribute(attr, value);
                    });
                    if (content['next_node'] == "")
                        parent_node.appendChild(newdiv);
                    else {
                        var next_node = document.getElementById(content['next_node']);
                        parent_node.insertBefore(newdiv, next_node);
                    }
                }
            });
        }
        else {
          var temp_content = [];
          $.each(html, function(index, content){
            temp_content[index] = content['html'];
            if (content['js']) {
              $(document).ready(function(){
                $.getScript(content['js'][0], function(){
                  if (content['js'][1])
                    $.getScript(content['js'][1], function(){
                      if (content['js'][2])
                        $.getScript(content['js'][2], function(){
                          if (content['js'][3])
                            $.getScript(content['js'][3], function(){
                              if (content['js'][4])
                                $.getScript(content['js'][4], function(){
                                  $('#' + target).html(temp_content.join(''));
                                });
                              else
                                $('#' + target).html(temp_content.join(''));
                            });
                          else
                            $('#' + target).html(temp_content.join(''));
                        });
                      else
                        $('#' + target).html(temp_content.join(''));
                    });
                  else
                    $('#' + target).html(temp_content.join(''));
                });
              });
            }
            else {
                $('#' + target).html(temp_content.join(''));
            }
          });
        }
      });
    });
    $(a_tag).addClass('current_page_item');
  }
  
  function imgLoad(img, completeCallback, errorCallback){
    if (img && completeCallback){
      var loadWatch = setInterval(watch, 100);
      function watch(){
        if(img.complete){
          clearInterval(loadWatch);
          completeCallback(img);
        }
      }
    }
    else {
      if(typeof errorCallback=="function") errorCallback();
    }
  }
  function openLocation(href) {
    jQuery.ajax({
      url: href,
      success: function(data) {
        jQuery('#content').html(data);
      }
    });
  }
  function loadCategory(a_tag) {
    if (jQuery('.current_page_item'))
      jQuery('.current_page_item').removeClass('current_page_item');
    jQuery.ajax({
      url: a_tag.href,
      success: function(data) {
        jQuery('#content').html(data);
      }
    });
    jQuery(a_tag).addClass('current_page_item');
  }
