/**
 * 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+
 */
 
 jQuery(document).ready(function() {

// Create all "top" anchors
	jQuery('ol#faq > li').addClass('faqItem'); // Add class to the li
	jQuery('<a class="topSide" title="Back to the Top">Back to the Top</a>').appendTo('.faqItem');
	jQuery('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
	//jQuery('ol#faq').parent().prepend('<ol id="subNav"></ol>');
	jQuery('ol#faq').before('<ol id="subNav"></ol>');
	jQuery('ol#faq>li.faqItem').attr('goat', function (a){return a;});
	jQuery('ol#faq>li.faqItem>:header').each(function(i){
		jQuery('<li><a href="#' + (i) + '" monkey="' + (i) + '">' + jQuery(this).text() + '</a><br />&nbsp; &gt;&gt; <a href="#' + (i) + '" monkey="' + (i) + '">Video Answer</a></li>').appendTo('ol#subNav');
		jQuery('<br /><a class="quickLink">Video Answer</a><br />').appendTo(this).parent();
	});
	 //&nbsp;|&nbsp; <a href="#' + (i) + '" monkey="' + (i) + '">Video Answer</a>

	jQuery('a[monkey*=]').click(function() {
		jQuery('.faqHover').removeClass('faqHover'); // Remove all traces of ".faqHover"
		jQuery('a[title="Back to the Top"]').hide(); // Hide all "top" anchors
		
		if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'')&&location.hostname==this.hostname) {
			var goatHead = jQuery(this.hash);
			goatHead = goatHead.length && goatHead || jQuery('[goat=' + this.hash.slice(1) +']');
			if (goatHead.length) {
				var targetOffset = goatHead.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset-200}, 'slow');
				jQuery(goatHead).addClass('faqHover'); // Add class to the target li
				jQuery('.faqHover a[title="Back to the Top"]').show(); // Show target "top" anchor
				return false;
			}
		}
	});

	jQuery('.quickLink').click(function(){
		jQuery(this).parent().parent().addClass('faqHover');
		jQuery('.faqHover a[title="Back to the Top"]').show();
		return false;
	});

// Create scroll function to eliminate need for named page anchor
// then hide this and all "top" anchors when clicked
	jQuery('a[title="Back to the Top"]').click(function() {
		jQuery('html,body').animate({scrollTop: 0}, 'slow');
		jQuery(this).each('a[title="Back to the Top"]').hide();
	});
	
});
 
 