var waiting = false;
var nid;
var hoveredLink;

$(document).ready(
	function() {
		$('li:not(#link-10)').hover(
      // on rollover
		  function() {
		    if(!$(this).hasClass('active') && !(waiting)) {
  		    hoveredLink = $(this).children('a');
  		    ahahCall();
  		    		          waiting = true;
		    }
		  },
      // on rollout
		  function(){
		  }
		);
		$('li a').each(
		  function(e) {
        $(this).attr('href', $(this).attr('href').replace('/home', ''));
		  }
		);
	}
);

/**
 * Call back to replace content after the data has been returned
 */
function swapContent(content) {
    $('li.active').removeClass('active');
    $(hoveredLink).parents('li').addClass('active');
    $('.circle-text-content').slideUp('normal', function(){$(this).remove()}).after('<div class="circle-text-content new"></div>');
    $('.circle-text-content.new').removeClass('new').hide().html(content).slideDown('normal', function(){ 
      waiting = false;
    });
    content = null;
}

/**
 * perform a jQuery .ajax() operation.
 */
function ahahCall() {
  var oldNid = nid;
  nid = hoveredLink.parents('li').attr('id').split('-');
  if(oldNid[1] != nid[1]) {
    $.ajax({ 
      type: 'POST',
      url: baseURL + '/backend/content/' + nid[1] + '/json',
      dataType: 'json', 
      success: swapContent
    });
  }
}
