
$(document).ready( // Wait until the DOM is loaded, then go nuts

  function () {

    $('.tableHeaderTxt').css({ height : '30px' });

    // Displays all selected categories in the advanced search form
    $("#acts").change(function () {

          var str      = "You searched for category(s) : ";
          var catCount = 0 ;

          $("#acts option:selected").each(function () {
                str += $(this).text() + " " ;
                catCount = catCount + 1 ;
          });

          if (catCount == 0) { str = "" }
          $("#catTerms").text(str);
        })
        .trigger('change');

    // Makes sure the right form is displayed when the user hits the back button
		var search_type = $("input[name='search_type']:checked").val();
		if(search_type == 2){
			$('#adv_search1').css({ display : 'none' });
			$('#adv_search2').css({ display : 'block' });
			if ( $("#searchTerms").length > 0 ) { $('#searchTerms').css({ display : 'none' }); }
			if ( $("#catTerms").length > 0 ) { $('#catTerms').css({ display    : 'none' }); }
		}else{
			$('#adv_search1').css({ display : 'block' });
			$('#adv_search2').css({ display : 'none' });
			if ( $("#searchTerms").length > 0 ) { $('#searchTerms').css({ display : 'block' }); }
			if ( $("#catTerms").length > 0 ) { $('#catTerms').css({ display    : 'block' }); }
		}

  }
 
);

function showSearch1(){
	document.getElementById("adv_search1").style.display = 'block';
	document.getElementById("adv_search2").style.display = 'none';
	if ( $("#searchTerms").length > 0 ) { document.getElementById("searchTerms").style.display = 'block'; }
	if ( $("#catTerms").length > 0 ) { document.getElementById("catTerms").style.display    = 'block'; }
}

function showSearch2(){
	document.getElementById("adv_search1").style.display = 'none';
	document.getElementById("adv_search2").style.display = 'block';
	if ( $("#searchTerms").length > 0 ) { document.getElementById("searchTerms").style.display = 'none'; }
	if ( $("#catTerms").length > 0 ) { document.getElementById("catTerms").style.display    = 'none'; }
}

function rotatingImages() {

  //Start random imgs
  images = new Array();
  descs = new Array();
  
  images[0] = "<img src='/img/spot_img_1878_kelly.jpg' alt='1878_kelly'>";
  descs[0] = "<a href='/view.cgi?year=1878&amp;class=general&amp;page_num=963&amp;state=V&amp;classNum=G47'>Notice of reward for Ned Kelly's capture, April 1878</a>";
  
  /*
  images[1] = "<img src='/img/spot_img_1856_land.jpg' alt='1856_land'>";
  descs[1] = "<a href='/view.cgi?year=1878&amp;class=general&amp;page_num=963&amp;state=V&amp;classNum=G47'>Description for 1856_land</a>";
  
  images[2] = "<img src='/img/spot_img_1893_tea.jpg' alt='1893_tea'>";
  descs[2] = "<a href='/view.cgi?year=1878&amp;class=general&amp;page_num=963&amp;state=V&amp;classNum=G47'>Description for 1893_tea</a>";
  
  images[3] = "<img src='/img/spot_img_1915_forest.jpg' alt='1915_forest'>";
  descs[3] = "<a href='/view.cgi?year=1878&amp;class=general&amp;page_num=963&amp;state=V&amp;classNum=G47'>Description for 1915_forest</a>";
  
  images[4] = "<img src='/img/spot_img_1948_seal.jpg' alt='1948_seal'>";
  descs[4] = "<a href='/view.cgi?year=1878&amp;class=general&amp;page_num=963&amp;state=V&amp;classNum=G47'>Description for 1948_seal</a>";
  
  images[5] = "<img src='/img/spot_img_1978_wildflowers.jpg' alt='1978_wildflowers'>";
  descs[5] = "<a href='/view.cgi?year=1878&amp;class=general&amp;page_num=963&amp;state=V&amp;classNum=G47'>Description for 1978_wildflowers</a>";
  */
  
  index = Math.floor(Math.random() * images.length);
  
  document.write(images[index]);
  document.write("<p>" + descs[index] + "</p>");
  
  //End random imgs

}
