(function($) {
  $(document).ready(function() {

    // Add expandable/collapsable sub menu to exemplar side navigation
    if ($("#nass_exemplar_menu_treeview").length > 0) {
      $("#nass_exemplar_menu_treeview").treeview({collapsed: false});  
    }


// Activate Lightbox plugin for image gallery on the bottom of an Examplar
// We don;'t have class on these a's so we just get every a inside the #content-exemplar-narrow div 
// that has an img inside. We then exclude the simpleditcontainer.
 $(function() {
        $('#content-exemplar-narrow img').not($('#simpleeditcontainer img')).parent('a').lightBox({
        overlayBgColor: '#000',
	overlayOpacity: 0.6,
	imageLoading: '/__data/assets/image/0017/40634/lightbox-ico-loading.gif',
	imageBtnClose: '/__data/assets/image/0014/40631/lightbox-btn-close.gif',
	imageBtnPrev: '/__data/assets/image/0016/40633/lightbox-btn-prev.gif',
	imageBtnNext: '/__data/assets/image/0015/40632/lightbox-btn-next.gif',
	imageBlank: '/__data/assets/image/0013/40630/lightbox-blank.gif',
        fixedNavigation:true,
	containerResizeSpeed: 350,
	txtImage: 'Image',
	txtOf: 'of'
      });
    });

   
// Activate Lightbox plugin for list off all alt tags (asset 49620)
 $(function() {
        $('#list-of-all-alt-tags a').lightBox({
        overlayBgColor: '#000',
	overlayOpacity: 0.6,
	imageLoading: '/__data/assets/image/0017/40634/lightbox-ico-loading.gif',
	imageBtnClose: '/__data/assets/image/0014/40631/lightbox-btn-close.gif',
	imageBtnPrev: '/__data/assets/image/0016/40633/lightbox-btn-prev.gif',
	imageBtnNext: '/__data/assets/image/0015/40632/lightbox-btn-next.gif',
	imageBlank: '/__data/assets/image/0013/40630/lightbox-blank.gif',
        fixedNavigation:true,
	containerResizeSpeed: 350,
	txtImage: 'Image',
	txtOf: 'of'
      });
    });

 //Lightbox only shows the title of the a element as caption. Copy the alt attribute of all images into the title attribut
	function copyAltIntoTitle() {
		var img = $(this).children('img');
		var a =$(this);
		a.attr('title',img.attr('alt'));
	}
	
	$('#content-exemplar-narrow img').parent('a').each(copyAltIntoTitle);

 

     




    // Browse exemplars page. Filter results based on school type
    $("#filter_by a").click(function() {
      var filterBy = $(this).attr("class");

      // Switch results on and off 
      $('#filter_by_results > li:visible').not('.'+filterBy).hide();
      $('#filter_by_results li.'+filterBy).show();

      // Highlight selected option    
      $('#filter_by .selected').not('.'+filterBy).removeClass('selected');
      $('#filter_by .'+filterBy).addClass('selected');
    });

    // Slide exemplar wheel up and down 
    $('#hide_exemplar_wheel a').toggle(
			function () {
	    	$('#exemplar_wheel').show('slow');
		    $(this).text("Hide links to the curriculum");
      }, function () {
      	$('#exemplar_wheel').hide('slow');
      	$(this).text("Show links to the curriculum");
   	  }
   	);

// Slide exemplar key in browse and search result pages up and down
	$('#key_accordion> div').hide();  
  $('#key_accordion> h3').click(function() {
    $(this).next('div').slideToggle('slow')
    .siblings('div:visible').slideUp('slow');
return(false);
  });





  // Last two brackets belong to function and document.ready
  });  
})(jQuery);


// We call this function with inline javascript. (not nice) Therefor it is outside the document.ready
// Make Topic and Student into Topics and Students on some Story pages because there is more then one.
	function makeTableHeadersPlural(single) {
		$(".story_details th").each(function() {
			$(this).html($(this).html().replace(single, single + "s"));
		});
	};
