$(function(){

	/* ADD 'RETURN TO TOP' LINK IF THE DOCUMENT IS LONGER THAN THE CURRENT WINDOW */
	if($(document).height() > $(window).height()) {
		$("#content").append('<p class="return"><a href="#header">Return to Top</a></p>');
	};
	
	
	
	
	/* SCROLL-TO-LINK */
	var speed = 4; /* SET THE GLOBAL SCROLL SPEED HERE -- HIGHER NUMBERS ARE FASTER */
	$('a[href*=#header]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target
			|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				var scrollSpeed = $(document).height() / speed; /* TAKES THE HEIGHT OF THE DOCUMENT, DIVIDES BY SPEED */
				$('html,body')
				.animate({scrollTop: targetOffset}, scrollSpeed);
				return false;
			}
		}
	});
	
	
	
	
	/* DROP DOWN MENU */
	var timeout         = 500;
	var closetimer		= 0;
	var ddmenuitem      = 0;
	
	function jsddm_open()
	{	jsddm_canceltimer();
		jsddm_close();
		ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}
	
	function jsddm_close()
	{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}
	
	function jsddm_timer()
	{	closetimer = window.setTimeout(jsddm_close, timeout);}
	
	function jsddm_canceltimer()
	{	if(closetimer)
		{	window.clearTimeout(closetimer);
			closetimer = null;}}
	
	$(document).ready(function()
	{	$('#navbar > li').bind('mouseover', jsddm_open);
		$('#navbar > li').bind('mouseout',  jsddm_timer);});
	
	document.onclick = jsddm_close;

	
	function hoverBG() {
		$(this).css('background', 'url(../_images/_layout/navbar_hover.png');
	}
	
	
	function navbarHover() {
		$("#navbar li a").bind('mouseover', hoverBG);
	}
	
	
	
	
	/* BASEBALL PROGRAMS EXPANDING MENU */

	var pageId = $('body').attr('id');  // Get the ID of the current page.
	
	var current = pageId.split("_");  // This will split the variable pageId into an array called 'current', at each '_'. The first part of pageId goes into current[0], and the second part goes into current[1], etc. Here, we are only using the first part to determine which part of the menu should be expanded, by default.
	
	var ulId = "ul#" + current[0] + "-subnav"; // Concatenate the pieces to make up the ID of the portion of the Quick-Links that we want to keep expanded.
//	console.log(pageId);
//	console.log(current);
//	console.log(ulId);
	
	$(ulId).show(); // Expand Quick-Links for current section.
	
	$("li#baseball-programs-link > a").click(function(){
		$("ul#baseball-programs-subnav").slideToggle();
		return false;
	});
		
	
});
