/*
Site-wide JS
*/

var flash_duration = 6000;

$(function(){
  setTimeout('hideMessages()', flash_duration);
	$("#foundation_tab").click(function(){
		$("#main_footer").hide();
		$("#main_footer_foundation").show();
		
		$('#research_tab').addClass('subtab');
		$('#foundation_tab').removeClass('subtab');
	});
	$("#research_tab").click(function(){
		$("#main_footer_foundation").hide();
		$("#main_footer").show();
		
		$('#foundation_tab').addClass('subtab');
		$('#research_tab').removeClass('subtab');
	});
	$("#main_search_button").click(function(){
		$("#main_search").submit();
		return false;
	});
	$('#verification_help').hover(
		function(){
			$("#verification_info").toggle();
		},
		function(){
			$("#verification_info").toggle();
		});
});

function hideMessages() {
	$("div.message").filter(function(){
		return $(this).css("display") != "none"; // don't do the fade action if it's already hidden!
	})
	.animate({
		top: '-=200px'
	}, 'normal', 'swing', function(){
		$(this).remove();
	});
}
var customizeDropdown = function(select_selector, dropdown_target){
	var hideDropDown = function(){
		$(dropdown_target+' .options').hide();
	}
	$('*').click(hideDropDown);
	$(dropdown_target+' a.dropdown_button').click(function(){$(dropdown_target+' .options').show();return false;});
	$(select_selector).find('option').each(function(i, e){
		var select_option_text = $(this).text();
		var id = 'custom_dropdown_'+$(select_selector).attr('id')+'_'+i;
		$(dropdown_target).find('.options').append('<div class="option'+((i%2==0)?' odd':'')+'" id="'+id+'">'+$(this).text()+'</div>');
		$("#"+id)
		.hover(function(){$(this).addClass('hover')}, function(){$(this).removeClass('hover')})
		.click(function(){
			// clear the current selection
			$(select_selector).find('option:selected').attr('selected', false)
			// set the new selection
			$(select_selector).find("option:eq("+i+")").attr('selected', true);
			// trigger the change on the select box
			$(select_selector).change();
			$('#category_display .result_category').text(select_option_text);
			$('#category_display').show();
			hideDropDown();
			
		});
	});
};

