// function that are for the whole site
$(document).ready(function(){
	
	setFooter();
	
	// select copy in input boxes automatically
	$("input[type=text]").focus(function(){
	    this.select();
	});
  // Search Form input
  $("#searchForm input")
    .focus(function () {
      $(this).val("");
    })
    .blur(function() {
      if($(this).val() == "") {
        $(this).val($(this)[0].defaultValue);
      }
    });

	// SB navigation
  $("ul#SB_navlist li > ul").addClass("SB_subnavlist");
	$("ul#SB_navlist li.current ul").parent().addClass("open");
  
	/*$("ul#SB_navlist li#active a.level1").next().toggle("slow");
	$("ul#SB_navlist li#active").toggleClass("open");
	
	$("ul#SB_navlist li a.level1").click( function() {
		$(this).next().toggle("slow");
		$(this).parent().toggleClass("open");
	});*/
	
	
	// ministry index
	var moveBody_ministry = $("#ministry_index_holder").height();
	var ministry = false;
	
	$("#ministry").click(function() {
		$("#ministry_index_holder").slideToggle(1100);
		if (ministry == false) {
			$('body').animate({ backgroundPositionY: moveBody_ministry + "px" }, 1100);
			ministry = true;
		} else {
			$('body').animate({ backgroundPositionY:"0px" }, 1000);
			ministry = false;
		}
	});
	
	
	// contact us
	var moveBody_contact = $("#contact_form_holder").height();
	var contact = false;
	
	$("#contact").click(function() {
		$("#contact_form_holder").slideToggle(1100);
		if (contact == false) {
			$('body').animate({ backgroundPositionY: moveBody_contact + "px" }, 1100);
			contact = true;
		} else {
			$('body').animate({ backgroundPositionY:"0px" }, 1000);
			contact = false;
		}
	});
});



// get the window height
function getWindowHeight() {
	var windowHeight = 0;
	windowHeight = $(window).height();
	return windowHeight;
}



// set the footer size
function setFooter() {
		
	var windowHeight = getWindowHeight();
	
	if (windowHeight > 0) {
	
		var wrapperHeight = $('#wrapper').outerHeight();
		var contentHeight = $('#content_holder').outerHeight();
		var footerHeight = $('#footer_holder').outerHeight();
		
		if (windowHeight - (wrapperHeight+footerHeight) >= 0) {
		
			/*
$("#footer_holder").css('position', 'relative');
			$("#footer_holder").css('top', (windowHeight - (wrapperHeight+footerHeight)) + 'px');
*/
			$("#content_holder").css('height', (windowHeight - (wrapperHeight+footerHeight)) + contentHeight + "px");
			$("#content").css('height', (windowHeight - (wrapperHeight+footerHeight)) + contentHeight + "px");
		
		} else {
			
			$("#content_holder").css('height', 'auto');
			$("#content").css('height', 'auto');

		}
		
	}
}

// place footer
$(window).resize(function(){
	setFooter();
});