// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function tab_panel_select(tab,elm) {
  // handle tabs
  $('.tabs li').removeClass('selected');
  $(tab).parent().addClass('selected');

  // handle panels
  $('.panels').hide();
  $(elm).show();
}

function selectNavBar(anchorString){
  $('.nav_section .active').removeClass('active');
  $('.nav_section a').each(function(i){
    linkHref = $(this).attr("href");
    if(linkHref != undefined && linkHref.split('#')[1] == anchorString ){
      $(this).parent().addClass('active');
    }
  })
}

function chooseSectionToShow() {
  $(".section").hide();
  var url = document.location.toString();
  if (url.match('#')) { // the URL contains an anchor
    var anchor = url.split('#')[1];
    var toShow = $('#'+ anchor);
  } else {
    var anchor = "cover";
    var toShow = $('#cover'); // default section
  };
  toShow.show();
  toShow.addClass('active-section');
  if(anchor != undefined){selectNavBar(anchor)};
};

function quoteNavBarLinks(){
  $('.nav_section a, a.tab-link').click(function(){
    // select the right nav bar
    var selectedOrNot = $(this).parent();
    if(selectedOrNot.hasClass('active')){
      //nothing really since we are on the selected section already
    }else{
      // show the correct section
      anchor = $(this).attr("href").split('#')[1];
      selectedSection = $('#'+ anchor);
      selectedSection.slideDown();
      $('div.active-section').hide();
      $('div.active-section').removeClass('active-section');
      selectedSection.addClass('active-section');
      $('.nav_section .active').removeClass('active');
      selectedOrNot.addClass('active')
      document.location.hash = anchor;
    }
    selectNavBar(anchor);
    return(false);
  });
}

$(document).ready(function() {
  $("span.rating").click(function() {
      $(this).toggleClass('up');
      $(this).next(".review_ratings").slideToggle(500);
    })// .mouseout(function() {
    //       $(this).find(".review_ratings").slideUp(300);
    //       // $(this).removeClass('accent');
    //     })
    ;
});

