AShafer = {};
// $(function(){
//   var secondaryWrapper = $('#secondary-navigation');
//   var secondaryTabs = secondaryWrapper.find('li');
//   $("#tabs").tabs({
//     select: function(event, ui) {
//       var elem = $(ui.panel);
//       secondaryTabs.hide();
//       var secondaryTabsToShow = secondaryWrapper.find('li.'+elem.attr('id')+'-extra');
//       secondaryTabsToShow.show();
//     }
//   });
// });

/*
$('*[data-navigation]').live('click', function(ev){
  ev.preventDefault();
  $('#tabs').tabs('select', parseInt($(this).attr('data-navigation'),10));
});
*/

$(function(){
  $(window).hashchange( function(){
    AShafer.checkForHash();
  });
  $(window).hashchange();  
});

AShafer.checkForHash = function(){
  if(window.location.hash) {
    var requestedLink = $('a[href='+window.location.hash+']');
    if(requestedLink.size() > 0){
      requestedLink.click();
      return;
    }
  }
  $('#navigation li a').first().click();
};

$('#navigation li a').live('click', function(ev){
  //set this one as selected
  var elem = $(this);
  var listItem = elem.closest('li');
  $('#navigation li').removeClass('selected');
  listItem.addClass('selected');
  
  // show this tab panel
  $('.tab-panel').hide();
  $(elem.attr('href')).show();
  //show secondary info
  var secondaryWrapper = $('#secondary-navigation');
  secondaryWrapper.find('li').hide();
  // debugger
  var secondaryTabsToShow = secondaryWrapper.find('li.'+listItem.attr('data-navigation')+'-extra');
  secondaryTabsToShow.show();
});

$('#secondary-navigation li a').live('click', function(ev){
  $('#tab-content .tab-panel').hide();
  var elemToShow = $($(this).attr('data-display'));
  elemToShow.show();
});

$('#references-navigation li').live('mouseover', function(ev){
  $('#reference-content .reference-panel').hide();
  var elemToShow = $($(this).find('a').attr('data-display'));
  elemToShow.show();
});
