$(document).ready(function() {
	
	// Find out what page we're on and then highlight the menus correctly
	pathParts = window.location.pathname.substring(1,window.location.pathname.length).split('/');
	topDirectory = pathParts[0]
	fileName = pathParts[pathParts.length-1]

	if (topDirectory != "" && topDirectory.indexOf("default.aspx") != 0) {
		$('#mainMenu .' + topDirectory).addClass('current');	
		$('#localNav a[href*="'+ fileName +'"]').parent().addClass('current').parents('li').addClass('current')

		// main menu dropdowns
		// get all main menu items
		var mainMenuOffset = $('#mainMenu').offset()
		var mainMenuItems = $('#mainMenu ul li span a')
		var screenDimensions = getWindowSize()
		
		mainMenuItems.each(function() {
			var localDropdown = $(this).parent().siblings('ul');
			var localMenuOffset = $(this).offset();
							
			var newLeft = localMenuOffset.left - mainMenuOffset.left;
			var newTop = (localMenuOffset.top + $(this).height()) - mainMenuOffset.top;
	
			var temp = $(this).width();
			
			$(localDropdown).css('left', newLeft+'px');	
			$(localDropdown).css('top', newTop+'px');
			
			// check to see if CSS has a width on a specific main menu item
			if ($(localDropdown).css('width') == "auto") {
				$(localDropdown).css('width', $(this).width()+'px');
			} else {
				// ensure the width is the same as the CSS width
				temp = $(localDropdown).css('width')
				temp = parseInt(temp)
			}
			
			$(this).parent().parent().children('ul').children('li').children('a').each(function() {
				 $(this).css('width', temp-10+'px');
			});	
			
			
		})
		
		$('#mainMenu ul li').hover(
				function() {
					$(this).toggleClass('over');
				},
				function() {
					$(this).toggleClass('over');
		 });
	
	}
	
	$("body .mainContent dd").css("display", "none");
	$("body .mainContent dt").click(function(event) {
		event.preventDefault();
		$(this).nextUntil("dt").toggle();
	});
	
});

function getWindowSize() {
	var tempSize = new Object();
	if( typeof( window.innerWidth ) == 'number' ) {
		tempSize.width = parseFloat(window.innerWidth);
		tempSize.height = parseFloat(window.innerHeight);
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		tempSize.width = parseFloat(document.documentElement.clientWidth);
		tempSize.height = parseFloat(document.documentElement.clientHeight);
	}
  return tempSize;
}

