/**
 *	jQuery Skip-Nav by Scott Lenger and Paul Zumbrun
 *	http://beaconfire.com 
 *	This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
 *	This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.  
 *	You should have received a copy of the GNU Lesser General Public License along with this library; Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
 */
function skipNavigation(skipNavContainer) {
	var defaultHeight = $('#'+skipNavContainer).height(); // get default container height before this script minimizes the container
	closeSkipNavContainer(skipNavContainer); // minimize the container so that later we can slide it open
	skipNavTimeout = null;

	// if a link in the skip-nav container receives focus:
	// 1. apply class="active" to the container (class="active" should be set to 'visible' via CSS)
	// 2. slide open the container  
	// 3. apply class="nav-focused" to the linked element
	$('#'+skipNavContainer+' a').bind('focusin', function(event) {
		if ( !$('#'+skipNavContainer).hasClass('active') ) {
			$('#'+skipNavContainer).addClass('active');
			$('#'+skipNavContainer).animate({"height":defaultHeight},{duration:"medium"}); //
		}
		$(event.target).addClass('nav-focused');
	});

	// remove class 'nav-focused' if linked element loses focus
	$('#'+skipNavContainer+' a').bind('focusout', function(event) { // if skip nav link loses focus
		$(event.target).removeClass('nav-focused'); // remove 'nav-focused' class
		
		// if none of the links in the skip-nav container have class="nav-focused" run the function to hide the container
		if ( !skipNavTimeout ) { // if skipNavTimeout is not set
			skipNavTimeout = setTimeout( function() { // set timer
				if ( $('#'+skipNavContainer+' .nav-focused').length == 0 ) { // if 'nav-focused' is not found close container
					closeSkipNavContainer(skipNavContainer);
				}
				skipNavTimeout = null;
			}, 200 );
		}
		
	});

	// reduce container height to 1 px and remove class="active" (CSS should be set to hide container if class is absent)
	function closeSkipNavContainer(skipNavContainer) {
		$('#'+skipNavContainer).animate( {"height": '1px'}, 'medium', 'linear', function() { 
			$(this).removeClass('active');
		});
	}
}
