var shipMoving = false;
var shipLive = false;

// hover state configs
var frontMenuConfig = {
	sensitivity: 20, // number = sensitivity threshold (must be 1 or higher)    
	interval: 300, // number = milliseconds for onMouseOver polling interval    
	over: openMenu, // function = onMouseOver callback (REQUIRED)    
	timeout: 400, // number = milliseconds delay before onMouseOut    
	out: closeMenu // function = onMouseOut callback (REQUIRED)    
};

var hoverShipConfig = {
	sensitivity: 20,
	interval: 25,
	over: stopShip,
	timeout: 400,
	out: moveShip
};


$(document).ready(function(){
	
	// initialize season passport offer - front page only
//	$('#seasonPassportOffer').click(moveShip);
	
	// initialize main menu
	
	// rollover effect for main images in nav menu
    $('.navCap').hover(	
    	// on hover
    	function() {
    		$(this).attr('src', $(this).attr('src').replace('.png', '_msover.png'));
    	},
    	
    	// on mouse out
    	function() {
    		$(this).attr('src', $(this).attr('src').replace('_msover.png', '.png'));
    	}
    );
    
    // left nav in content area
    $('#leftNavMid ul li a').hover(
        	function() {
        		
        		if (isIE6())
        			$(this).parent().append('<img style="left: -75px" class="pointer" src="/images/common/hand_pointer.gif" />');
        		else
        			$(this).parent().append('<img class="pointer" src="/images/common/hand_pointer.png" />');
        	},
        	
        	function() {
        		$('.pointer').remove();
        	}
        );
	
	$("#slideShow ul.navSliderHead").hoverIntent( frontMenuConfig );
	
	$(".slider").easySlider({
			auto: true, 
			continuous: false,
			pause: 6000,
			speed: 1500,
			controlsHover: true,
			controlsShow: false
	});
	
	// fix png images
	$(document).pngFix();
	
	window.setTimeout(function() {
 		$('#slideShow ul li ul').slideUp(1300);
 		moveShip(); // being called from flash file
	}, 800);
	

});

function isIE6() {
	if('ActiveXObject' in window && !('XMLHttpRequest' in window))
		return true;
	else
		return false;
}

function moveShip() {
	
	if (shipMoving == false ) {
	
		if (!shipLive) {
		//	$('body').append('<div id="offerShip"><img src="/images/common/ship_offer.png" alt="Click for offer" /></div>');
			$('#offerShip').hoverIntent( hoverShipConfig );
			shipLive = true;
		}
		
		var bwidth = $('body').width();
			
		var shipDisplay = $('#offerShip').css('display');
	
		if (shipDisplay = 'none'); {
			$('#offerShip').show();	
		}
	
		var shipRightVal = $('#offerShip').css('right').replace('px', '');
		
		var moveTo = bwidth - shipRightVal;
		var moveTime = moveTo * 15; // time to get across the screen.
	
		shipMoving = true; // global
		$('#offerShip').animate({
			right: '+='+moveTo,
			top: '0'
			}, moveTime, function() {
				$('#offerShip').hide();
				var shipDisplay = $('#offerShip').css('display');
				if (shipDisplay = 'block')
					resetShip(); // write function to reset ship to starting position.
			}
		);

	}
}

function resetShip() {
	$('#offerShip').css('display', 'none');
	$('#offerShip').css('top', '0px');
	$('#offerShip').css('right', '0px');
//	$('#offerShip').remove();
	
	shipMoving = false; // global
	shipLive = false; // able to add another ship to site
}

function stopShip() {
	$('#offerShip').clearQueue();
	$('#offerShip').stop();
	shipMoving = false; // global
}


function openMenu() {
	$(this).find('ul').slideDown('slow');
}

function closeMenu() {
	$(this).find('ul').slideUp('slow');
}