(function($) { 
$(document).ready(function() {		   

	// Open all external links in new window
	$("#main a[href^='http://']").attr("target","_blank");
	
	EqualHeight($(".homepage-panel"));
	EqualHeight($("#footer .section"));
	//$.preloadCssImages();
	HomepageFunds();
	FaqList();
	
	if($("#featured").length > 0){
		var playdata = $("#featured").data("play");
		var pausedata = $("#featured").data("pause");
		$("#featured").slides({
			preload: true,
			preloadImage: 'themes/rivercapital/images/loading.gif',
			play: playdata,
			pause: pausedata,
			effect: 'fade',
			crossfade: true,
			hoverPause: true
		});

	}
});

function HomepageFunds(){
	$('#FundsTabs h3').click(function(){
		$('#Funds .selected').removeClass('selected');
		$(this).parent('li').addClass('selected');
		
		var clicked = 'FundInfo-' + $(this).parent('li').attr('rel');
		$('#'+clicked).addClass('selected');

		return false;
	});
}

function FaqList(){
	$('.faqholder h3').each(function(index){
		var contents = $(this).nextUntil('h3');
		var container = $('<div class="faqEntry"></div>').insertAfter($(this));
		contents.appendTo(container);
		
	});
	
	$('.faqholder h3').click(function(e){
		e.preventDefault();
		$('#footer').css('clear', 'both');
		$(this).toggleClass('open');
		$(this).next('div.faqEntry').slideToggle('fast', function () {$('#footer').css('clear', 'none');});
		
		// $(this).nextUntil('h3').slideToggle('fast', function () {$('#footer').css('clear', 'none');});
		
	});
	
}

/*-- Util Functions -- */
function EqualHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
})(jQuery);

