//Scripts for editing the showing and hiding of extended information

jQuery(document).ready(function() {
	//Auto Hide - part of a paragraph or section - results in a sentence that ends in "read more"
	//Make each class unique by adding an ID to it	

	jQuery('.auto_hide_part').each(function(i){
		jQuery(this).attr('id',i);
		jQuery('<span id="'+i+'" class="expand_part_link '+i+'"> ...<a href="" >read more</a></span>').insertAfter(this); //Why both ID and Class. ID lets me retrieve it easily, but because i also asign the ID to the first part, it is not unique and removing the 'show more' text becomes a problem.
	});
	//Hide the Text
    jQuery('.auto_hide_part').hide();
	//Show the Selected Text
	jQuery('.expand_part_link').click(function(e){
		var selectedID = jQuery(this).attr('id');
  		jQuery('.'+selectedID+'.expand_part_link').remove();
	    jQuery('#'+selectedID+'.auto_hide_part').show('slow','swing');
		e.preventDefault();
	});

	//Auto Hide - Whole Section or Paragraph - results in a heading that is linked to show it's content
	//Class= auto_hide_whole = encloses the whole area
	//Class= title_auto_hide_whole = the section of text that will remain and will link to the filed

	//Adjust the text.
	jQuery('.auto_hide_whole').each(function(i){
		jQuery(this).attr('id','100'+i).addClass('100'+i);//prepend with 100 to ensure no cross over with the above. Add ID & Class to make the combined unique.
		var newTitle = '<a href="">'+jQuery('.title_auto_hide_whole').html()+'</a>';
		jQuery(newTitle).attr('id','100'+i).addClass('title_link').insertBefore(this);
		//Remove the Title Text - which was copied, so it doesn't show up twice.
		jQuery(this).children().remove('.title_auto_hide_whole');
	});

	//Hide the text
    jQuery('.auto_hide_whole').hide();
	
	//Show the Text
	jQuery('.title_link').click(function(e){
		var selectedID = jQuery(this).attr('id');
	    jQuery('.'+selectedID).show('slow','swing');
		e.preventDefault();
	});
});



