var dropdownsettings = {
	/* ID of the DIV your navigation UL is inside */
	containerID: 'nav',
	/* Time in milliseconds to take when dropping down */
	dropSpeed: 100
};

$(document).ready( function() {
	$('#' + dropdownsettings['containerID']).find('li').each( function() {
		if ($(this).children('ul').length > 0) {
			$(this).addClass('hasChildren');		
		}
		$(this).data('origHeight', $(this).children('ul').height());	
		$(this).children('ul').height(0);
	});
	$('#' + dropdownsettings['containerID']).find('li').bind('mouseenter', function() {
		$(this).children('ul').animate({ height: ($(this).data('origHeight') -26) }, dropdownsettings['dropSpeed']);
		$(this).addClass('over');
		
	});
	$('#' + dropdownsettings['containerID']).find('li').bind('mouseleave', function() {
		if ($(this).hasClass('hasChildren')) {
			$(this).children('ul').animate({ height: 0 }, dropdownsettings['dropSpeed'], 0, function() {
				$(this).parent().removeClass('over');
			});	
		} else {
			$(this).removeClass('over');		
		}
	});
	$('#' + dropdownsettings['containerID']).find('ul li ul').each( function () {
		$(this).width(findWidest($(this)));
	});
});

function findWidest(containingUL) {
	var widest = 0;
	containingUL.find('li').each( function() {
		if ($(this).width() > widest) {
			widest = $(this).width();
		}
	});
}

var faqsettings = {
	containerClass: 'faq', 
	dropSpeed: 100
};

$(document).ready( function() {
	$('div.' + faqsettings.containerClass).each(function () {
		var faqItem = $(this);
		var question = $(this).children('h2, h3');
		var answer = $(this).children('div');
		var expectedHeight = answer.outerHeight();
		question.css('cursor', 'pointer');
		question.css('display', 'inline-block');
		var showHideSpan = $('<span />');
		showHideSpan.css('background-image', 'url(/assets/images/FAQDropDownItem.gif)');
		showHideSpan.css('display', 'inline-block');
		showHideSpan.css('vertical-align', 'top');
		showHideSpan.css('margin-top', '5px');
		showHideSpan.width('18px');
		showHideSpan.height('18px');
		showHideSpan.css('background-position', 'left top');
		answer.after('<hr />');
		question.append(showHideSpan);
		
		answer.hide();
		question.click( function () {
			var answerHeight = faqItem.outerHeight();
			if (question.hasClass('open')) {
				answer.hide(faqsettings.dropSpeed, function() {
					var newAnswerHeight = faqItem.outerHeight();
					var heightChange = answerHeight - newAnswerHeight;
					$('.columns').height($('.columns').height() - heightChange);
				});
				showHideSpan.css('background-position', 'left top');
				question.removeClass('open');
			} else {
				$('.columns').height($('.columns').height() + expectedHeight + 1);
				answer.show(faqsettings.dropSpeed);
				showHideSpan.css('background-position', 'left bottom');
				question.addClass('open');
			}	
		});
	});
});


