$(document).ready(function() {
	//Get the FoundationURL;
	var FoundationURL = $("input[id='ctl00_FoundationURL']").val().toLowerCase();
	$('a.donate').colorbox ({href:FoundationURL + "/Pages/DonationForm.aspx", onClosed:function(){$('.formError').remove()}});
	
	$('.edit.hidden').parent().each(function(index) {
	    $(this).hover(function(){
	    	$(this).find('.edit').fadeIn();
	    },
		function () {
			$(this).find('.edit').fadeOut();
		});
	});
		$('.edit.pageImage.hidden,.edit.panelEdit.hidden').parent().parent().hover(function(){
	    	$(this).find('.edit').fadeIn();
	    },
		function () {
			$(this).find('.edit').fadeOut();
		});

	/* Make article title H2 full width if there's no header image */
	if ($('#promoCanvas').find('h2').prev().find('.ms-rtestate-field').html()=='')
	{
		$('#promoCanvas').find('h2').css("width", "auto");
	}
	$('#promoCanvas').find('.ms-formfieldcontainer').parent('h2').css('top', '50px');

	
	/* Adjust height of feature boxes so they are the same height */
	var maxHeight = 0;
	//Make all the boxes the same height
	$("#fourUp div").each(function(){
		if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
	});
	$("#fourUp div").height(maxHeight);
		
	var maxHeight3 = 0;
	//Make all the boxes the same height
	$("#threeUp div").each(function(){
		if ($(this).height() > maxHeight3) { maxHeight3 = $(this).height(); }
	});
	$("#threeUp div").height(maxHeight3);
	
	//Homepage twoUp
	$("#focusTopics div").each(function(){
		if ($(this).height() > maxHeight3) { maxHeight3 = $(this).height(); }
	});
	$("#focusTopics div").height(maxHeight3);

	//Homepage threeUp
	$("#additionalTopics div").each(function(){
		if ($(this).height() > maxHeight3) { maxHeight3 = $(this).height(); }
	});
	$("#additionalTopics div").height(maxHeight3);
	
	/* Features */
	$('input:checkbox[title="Get Content from Existing Page"]').each(function(index) {
		if ($(this).is(':checked'))
		{
			$(this).parents('li').find('.featureCustom').hide();
		}
    	$(this).click(function() {
    		if ($(this).is(':checked'))
    		{
    			$(this).parents('li').find('.featureCustom').slideUp();
    		}
    		else
    		{
    			$(this).parents('li').find('.featureCustom').slideDown();
    		}
       	});
  	});
	

});

$('.editModeLink').click(function() {
	$(this).next().slideToggle();
});

$('#headerNav li').hoverIntent({over: makeTall, timeout: 150,out: makeShort});

function makeTall(){ $(this).children('ul.subNav').fadeIn('fast');}
function makeShort(){ $(this).children('li ul.subNav').fadeOut('fast');}

function srchGO(searchType) {
	var FoundationURL = $("input[id='ctl00_FoundationURL']").val().toLowerCase();

    var newLocation = "";
	if (searchType=="main") {
    	if ($('#searchBox').val()=='')
	  	{
	  		newLocation = FoundationURL + "/Pages/search-results.aspx";
	  	}
		else
		{
			newLocation = FoundationURL + "/Pages/search-results.aspx?k=";
			newLocation +=document.getElementById('searchBox').value;
			//newLocation +="&s="
		}
	}
	else if (searchType=='form') {
		if (document.activeElement.id=="searchBox")
	 	{
	 		return false;
	 	} else {
	 		return _spFormOnSubmitWrapper();
	 	}
	}
	window.location.replace(newLocation);
}


