//the status of overlay box
var isOpen = false;
//function to display the box
function showOverlayBox() {
	//if box is not set to open then don't do anything
	if( isOpen == false ) return;
	// set the properties of the overlay box, the left and top positions
	// set the window background for the overlay. i.e the body becomes darker
	
	$('.bgCover').css({
		display:'block',
		position:'absolute',
		//width: $('#content').width(),
		height:$(window).height()
	});
	
}
function doOverlayOpen() {
	//set status to open
	isOpen = true;
	showOverlayBox();
	$('.bgCover').css({opacity:0}).animate( {opacity:0.9} );
	// dont follow the link : so return false.
	return false;
}
function doOverlayClose() {
	//set status to closed
	isOpen = false;
	
	$('.overlayBox').css( 'display', 'none' );
	// now animate the background to fade out to opacity 0
	// and then hide it after the animation is complete.
	$('.bgCover').animate( {opacity:0}, null, null, function() { } );
}
// if window is resized then reposition the overlay box
//$(window).bind('resize',showOverlayBox);
// activate when the link with class launchLink is clicked
//$('a.launchLink').click( doOverlayOpen );
// close it when closeLink is clicked
//$('a.closeLink').click( doOverlayClose );


	var timerID = 0;
	
	function closepanes(excluding) {	
		$('.navSubItems').each( function() {
			if ( excluding != "none" ) {
				if ( $(this).attr('id') != excluding ) {
					$(this).hide('slow');
				}
				else {
					//alert($(this).attr('id'));
				}
			}
			else {
				$(this).hide('slow');
			
			}
		});
	}
	
	function hideNavItems(navItems) {
		$('#' + navItems).hide('fade');
	}

	$(document).ready(function() {
							   
		$('#newsletter_input').click( function() { if ( $(this).attr('value') == "Lots more items coming, sign-up for updates?" ) {$(this).attr('value','');} } );
	
		$('.n').each( function() {
		
				$(this).click(function(){
									   
					var id = $(this).attr('id');
					closepanes( $(this).attr('id') );
					doOverlayOpen();
					$.ajax({
					   type: "POST",
					   url: "navitems.php",
					   data: "navitem=" + id,
					   success: function(msg){
						$('#' +id + 'Items').html(msg);
					   }
					 });
					$('#'+$(this).attr('id')+'Items').toggle('appear', function() {});
				});
			
		});
		
		$('.navSubItems').each( function() { 
		
			$(this).hover(
			
				function() {
				
					clearTimeout( timerID );
				
				},
			
				function() {
				
					timerID = setTimeout( 'hideNavItems("'+$(this).attr('id')+'")', 500 );
					doOverlayClose();
				
				}
			
			);			
		
		});

	});
	
	function toggleOptions() {
	
		$('#options').toggle("slow");
	
	}