$(document).ready(function(){
	
	if($('#scrollbox').length > 0){
	$('#scrollbox img:first').css('display', 'block');
	
	setInterval(function(){
	
		var current = $('#scrollbox img:visible');
		var next = current.next('img');
		
		if(!next.length > 0){
			next = $('#scrollbox img:first');
		}
		
		current.fadeOut();
		next.fadeIn();
	
	}, 3000)
	}				   
	$("#header ul input").focus(function(){
										 
										 if($(this).val() == "Enter Keyword Here"){
											
											$(this).val == "";
										 }
										 });
										 
										$("#header ul input").focusout(function(){
										 
										 if($(this).val() == ""){
											
											$(this).val == "Enter Keyword Here";
										 }
										 });

	$("#featurebox div > ul li a").click(function(){

											  var linkToSelect = $(this);
											  var boxToShow = $(this).attr("rel");
											  var moreURL;
											  $("#featurebox").fadeOut("normal", function(){
											  $("#featurebox div > ul li").removeClass("selected");
											  linkToSelect.parent("li").addClass("selected");
											  
											  $("#featurebox > div:first-child")
											  .attr("class", "")
											  .addClass(boxToShow);
											  
											  switch(boxToShow){
												
												case "insport":
												moreURL = "/changing-lives-in-sport/";
												bgcolor = "#00b9f2";
												break;
												case "inpartners":
												moreURL = "/changing-lives-with-partners/";
												bgcolor = "#00ae8e";
												break;
												case "about":
												moreURL = "/about-greater-sport/";
												bgcolor = "#8363aa";
												break;
												default:
												moreURL = "/changing-lives-for-you/";
												bgcolor = "#ff2b82";
												break;
												  
											  }
											  
											  $("#featurebox a.more.large").attr("href", moreURL);
											  $("#featurebox").css("background-color", bgcolor);
											  }).fadeIn("normal");
											  
											  return false;
											  
	 });
	
	// javascript helper for subnav 
	
	var activesubnav = $("#subnav > .current_page_item");
	if(activesubnav){
	
		if(activesubnav.children("ul").length > 0){
		
			activesubnav.next("li").css("margin-top", 0);	
			
		}
		
	}
	
	// javascript helper for vertical centering
	
	var ngbListing = $("#ngbHold");
	
	if(ngbListing){
		
		var containWidth = parseInt($("#ngbHold a").css("width"));
		var containHeight = parseInt($("#ngbHold a").css("height"));
		$(window).load(function(){
								
			$("#ngbHold a").each(function(){
									
							var imgHeight = $(this).children("img").height();
							var margToAdd = (containHeight / 2) - (imgHeight / 2);
							$(this).children("img").css("padding-top", margToAdd);
									
		});					
								
								
								});
		
		
	}
	
	// set lightboxes for gallery
	
	var gallery = $("#content.gallery");
	
	if(gallery){
	
		$('a[rel*=lightbox]').lightBox();
		
	}
	
	// javascript footer helper
	var footHeight = $("body").height();
	if(typeof document.body.style.maxHeight === "undefined"){
		footHeight = footHeight + 75;
	}
	$("#footer").css({"position":"absolute", "top" : footHeight});
	if(footHeight < $(window).height()){ $("#footer").css({"position":"absolute", "bottom" : 0, "top" : "auto"}); }
	
	if(typeof document.body.style.maxHeight === "undefined"){
;
		if($('ul > li.current_page_item > ul').length <= 0){ $("#subnav > li.current_page_item").css("height", 35); }
	
	}
	
	// job listings
	
	var jobul = $("#jobs");
	
	if(jobul){
	
		jobul.children("li").find(".infohold").slideUp("fast");
		
		jobul.children("li").find("h4").click(function(){
								$(".infohold").slideUp("fast");
								jobul.children("li").removeClass("active");
								$(this).next(".infohold").slideToggle("fast");
								$(this).parent("li").toggleClass("active");
						
													   
		});
		
	}
						   
});
