/** 
 * av_hide_show_transcript.js - Show / hide transcript(s) on reason av pages
 *
 * Expected structure:
 *
 * <div class="transcript">
 * <* class="transcriptHead">Transcript</*>
 * <blockquote>
 * .....
 * </blockquote>
 * </div>
 *
 * @author Nathan White
 * @requires jQuery
 */
$(document).ready(function()
{
	var divs = new Array();
	
	$("div.transcript").each(function(index)
	{
		my_anchor = $("a[name]:first", this).attr("name");
		my_hash = ($(location).attr('hash'));
		if (my_anchor && my_hash && ("#"+my_anchor == my_hash))
		{
			showTranscript(index, $(".transcriptHead:first", this).text());
		}
		else
		{
			hideTranscript(index, $(".transcriptHead:first", this).text());
		}
		divs[index] = this;
	});
	
	function hideTranscript(index, text)
	{
		$("blockquote", divs[index]).hide();
		var link_text = $('<a href="#transcript_text_'+index+'">' + "Show " + text + '<a/>').click(function()
		{
			return showTranscript(index, text);
		});
		$(".transcriptHead:first", divs[index]).html(link_text);
		return false;
	}
	
	function showTranscript(index, text)
	{
		$("blockquote", divs[index]).show();
		var link_text = $('<a href="#transcript_text_'+index+'">' + "Hide " + text + '<a/>').click(function()
		{
			return hideTranscript(index, text);
		});
		$(".transcriptHead:first", divs[index]).html(link_text);
		return false;
	}
});
