/**
 * 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: 7/2/2008
 * @authors Ryan Holt + Trip Oneal
 * @version 1.0.4
 *
 * Requires: jQuery 1.2+
 *
 * Notes:
 *  Internet Explorer 6 + 7 Issues:
 *	- Hiding "top" anchors not working in IE.
 *	- Changed $('a[href="#top"]').hide(); to $('a').attr({'href': '#top'}).hide();
 *	- Changed $('a[href="#top"]').hide(); to $('a[title="Back to the Top"]').hide();
 *     and added to the anchor append.
 *
 *	Scrolls smoothly down page, but jumps when clicking "top" anchor:
 *	- $('html,body').animate({scrollTop:0}, 'slow'); bounces in IE
 *	- $('body').animate({scrollTop:0}, 'slow'); jumps in IE, but doesn't bounce
 *
 *
 *	- Added titles to the dynamically created "subNav".
 *	- Added function to remove box from links when clicked.
 */
 
 
 $(function() {
// Create all "top" anchors
	$("ol>li").addClass('faqItem'); // Add class to the li
	$('<a href="#top" 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
	$(".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).each('a[title="Back to the Top"]').hide();
	});
	
// remove box from links
	$('a').focus(function(){
		this.blur();
	});
});
 
 
