// Application specific javascript for the APS Journal Search
// Copyright (c) 2008 American Physical Society
$(document).ready(function(){
  $("a#journal_dropdown_link").click(function(e) {
    e.preventDefault();
    $("div#select_specific_journals").show('fast');
    $("div#search_all_journals").hide('fast');
    $("table#search_form_journals").show('normal');
  });
  $("a#search_all_journals_link").click(function(e) {
    e.preventDefault();
    $("div#select_specific_journals").hide('fast');
    $("div#search_all_journals").show('fast');
    $("table#search_form_journals").hide('normal');
    $("table#search_form_journals//input[@type='checkbox']").each(function(){
      this.checked = false;
    });
  });
  $("a#select_years_link").click(function(e) {
    e.preventDefault();
    $("div#select_specific_years").show('fast');
    $("div#search_all_years").hide('fast');
    $("table#search_form_decades").show('normal');
  });
  $("a#search_all_years_link").click(function(e) {
    e.preventDefault();
    $("div#select_specific_years").hide('fast');
    $("div#search_all_years").show('fast');
    $("table#search_form_decades").hide('normal');
    $("table#search_form_decades//input[@type='checkbox']").each(function(){
      this.checked = false;
    });
  });
  $("a.aps-search-revealabstract").click(function(e) {
    e.preventDefault();
    abs = $(this).attr("id").replace(/^reveal_/, '#');
    if ($(abs).is(":visible")) {
      $(abs).hide('normal');
      $(this).html($(this).html().replace(/Hide/, 'Show'));
    } else {
      $(abs).show('normal');
      $(this).html($(this).html().replace(/Show/, 'Hide'));
    }
  });
  $("a#show_all_abs").click(function(e) {
    e.preventDefault();
    if ($(this).text().match(/Show/)) {
      $("div.aps-search-resultabstract").show('fast');
      $("a.aps-search-revealabstract").text('Hide Abstract');
      $(this).html($(this).html().replace(/Show/, 'Hide'));
    } else {
      $("div.aps-search-resultabstract").hide('fast');
      $("a.aps-search-revealabstract").text('Show Abstract');
      $(this).html($(this).html().replace(/Hide/, 'Show'));
    }
  });
  $("a#show_all_years").toggle(function() {
    $("div#more_years").show('normal');
    $("a#show_all_years").text('(Show Fewer Years)');
  }, function() {
    $("div#more_years").hide('normal');
    $("a#show_all_years").text('(Show All Years)');
  });
  $("a#refinesearch").toggle(function(e) {
    e.preventDefault();
    $("div.searchbox").show('slow');
    $("a#refinesearch").text('Hide "Edit Your Search"');
  }, function() {
    $("div.searchbox").hide('slow');
    $("a#refinesearch").text('Edit Your Search');
  });
});
