/**
 * jQuery.jFAQ - Easy FAQ creator using jQuery.
 * Copyright (c) 2008 XombieDesign - http//xombiedesign.com
 * Licensed under GPL license (http://www.opensource.org/licenses/gpl-license.php).
 * Date: 10/31/2008
 * @authors Ryan Holt / Trip O'neal
 * @version 1.0.5
 *
 * Requires: jQuery 1.2+
 */
 
 
 $(document).ready(function() {
// Create all "top" anchors
	$("ol>li").addClass('faqItem'); // Add class to the li
	$('<a class="topSide" title="Back to the Top">Back to the Top</a>').appendTo('.faqItem');
	$('a[title="Back to the Top"]').hide(); // Hide all "top" anchors

// Start "subNav" list, read content of each Header tag and create "subNav" li dynamically
	$("h1").after('<ol id="subNav"></ol>');
	$(".faqItem").attr("goat", function (a) { return a; });
	$(".faqItem>:header").each(function(i){
		$('<li><a href="#'+(i)+'" monkey="'+(i)+'" title="'+$(this).text()+'">'+$(this).text()+'</a></li>').appendTo('#subNav');
	});
	
	$('a[monkey*=]').click(function() {
		$('.faqHover').removeClass('faqHover'); // Remove all traces of ".faqHover"
		$('a[title="Back to the Top"]').hide(); // Hide all "top" anchors
		
		if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'')&&location.hostname==this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[goat=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset-200}, 'slow');
				($target).addClass('faqHover'); // Add class to the target li
				$('.faqHover a[title="Back to the Top"]').show(); // Show target "top" anchor
				return false;
			}
		}
	});

// Create scroll function to eliminate need for named page anchor
// then hide this and all "top" anchors when clicked
	$('a[title="Back to the Top"]').click(function() {
		$('html,body').animate({scrollTop: 0}, 'slow');
		$(this).hide();
	});
});
 
 
