var NWDoc = {
	
	page_nav: 0,
	current_nav: this.page_nav,
	timer:null,
	
	ShowSubNav: function(cur, init, is_timer) {
		if (cur == NWDoc.current_nav && !init) return false;
		
		if (!is_timer && !init) {
			clearTimeout(NWDoc.timer);
			NWDoc.timer = setTimeout( "NWDoc.ShowSubNav("+cur+","+init+",true)", 100);
			return false;
		}
		
		
		// hide all sub nav then fade in current
		var current = $('#sub-nav ul').removeClass('selected').hide().eq((cur-1)).fadeIn().addClass('selected');
		
		// add class to the main nav
		$('#main-nav ul li').removeClass('over').eq((cur-1)).addClass('over');
		
		
		
		// if the current sub nav has no items, hide it.
		NWDoc.ShowHideSubNav(current.children().length);
		
		NWDoc.current_nav = cur;
	},
	
	ShowHideSubNav: function(dir) {
		var height = (dir) ? '43px' : '2px';
		$('#sub-nav').animate({ height: height }, 200 );
	},
	
	SwapSplashTitle: function() {
		$('#title1').fadeOut(1000, function () {
			$('#title2').fadeIn(1000);
		});
	},
	
	BindMoreBtns: function() {
		$('a.more-btn').click(function(){	$(this).hide().parent().find('div.image-thumb').show(); return false; });
	}
};




$(document).ready(function() {
	//$("#header ul").tabs("#sub-nav ul", {event:'mouseover', effect:'fade', initialIndex:current_section });
	
	// hide all except the current
	NWDoc.ShowSubNav(NWDoc.page_nav, true);
	
	
	$("#main-nav ul li").each(function() {				
							var els = $(this).find('a');
							
							els.mouseover(function(){
												//console.log($(this).parent().attr('id').split('-')[1]);
												NWDoc.ShowSubNav($(this).parent().attr('id').split('-')[1]);
											});
						});
	
	
	$('#main-nav').mouseleave(function(){ clearTimeout(NWDoc.timer); });
	
	$('#header').mouseleave(function(){ 	//console.log('leave'); 
											NWDoc.ShowSubNav(NWDoc.page_nav);
											//clearTimeout(NWDoc.timer);
										});
	
	

	//$("#sub-nav ul.selected").tabs("#page > div", {effect: 'fade' });/*, {history:true}*/


	
	$("a.zoom").fancybox({	'overlayShow'			: false,
						 	'zoomOpacity'			: true,
							'overlayShow'			: false,
							'zoomSpeedIn'			: 300,
							'zoomSpeedOut'			: 200,
							'padding'				: 0

						 
						   });
	
});

