var sAppPath = "/stevens";

$(window).load(function(){

	var topNavConfig = {    
		interval: 100,
		sensitivity: 4,
		over: openNav,
		timeout: 100,
		out: closeNav
	};
	$('#topNav li.topNav').hoverIntent(topNavConfig);
	

	// interior Promos
	if ($('#interiorPromo').length) {
		$('#interiorPromoNext').click(function(){
			var $current = ($('#interiorPromo li.active'));
			var $next = $current.next();
			if (!$next.length) $next = $('#interiorPromo li:first');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')

			$('#interiorPromoCount .showing').html( $('#interiorPromo li').index($next)+1 );
			
		});	
		
		$('#interiorPromoPrev').click(function(){
			var $current = ($('#interiorPromo li.active'));
			var $next = $current.prev();
			if (!$next.length) $next = $('#interiorPromo li:last');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')
			
			$('#interiorPromoCount .showing').html( $('#interiorPromo li').index($next)+1 );
			
		});		
		
		if ( $('#interiorPromo li').length > 1 ) {
			$('#interiorPromoCount .total').html( $('#interiorPromo li').length );
			$('#interiorPromoNext').click();
			$('#interiorPromoNav').show();
		} else {
			$('#interiorPromoNext').click();
			$('#interiorPromoNav').hide();
		}
	}
	
	// add this
	$('.addThis').click(function() {
		var oPopup = $(this).parent().find('.addThisPopup');
		$(oPopup).show();
		$(document).one("click", function() { oPopup.hide(); });
		return false;
	});
	
	// love this
	$('.promoLove img').click(function() {
		var id = $(this).attr("id");
		var loveCookie = $.cookie(id);
		if (!loveCookie || loveCookie == '') {
			var oCounter = $(this).parent().find('.loveThisCounter');
			if (id!='') {
				$.ajax({
					url: sAppPath  + '/SiteBase/includes/feedHandler.ashx?action=addLove&id=' + id,
					dataType: 'json',
					success: function(data) {
						oCounter.html(data);
						$.cookie(id, data, { expires: 3650});
					},
					error: function(request, status, errorMsg) {
						//alert("error retrieving photos " + errorMsg);
					}
				});			
			}
		}
	});
	$('#tabHours').click(function() {
		$('#interiorWeatherPopup').hide();
		$('#parksPopup').hide();
		$('#hoursPopup').toggle();
	});	
	$('#tabParks').click(function() {
		$('#interiorWeatherPopup').hide();
		$('#hoursPopup').hide();
		$('#parksPopup').toggle();
	});			
	var bWeatherLoaded=false;
	$('#tabWeather').click(function() {
		if (!bWeatherLoaded) {
			$('#interiorWeatherPopup').load(
				sAppPath + '/SiteBase/wrap/theme2/includes/interiorWeatherPopup.aspx',
				function() {
					bWeatherLoaded = true;
				}
			);
		}
		$('#hoursPopup').hide();
		$('#interiorWeatherPopup').toggle();
	});		

	// gallery
	$('#togglePhotos').click(function(){
		$('.galleryDiv').removeClass('on').hide();
		$('.galleryToggle').removeClass('on');
		$('#divPhotos').show();
		$(this).addClass('on');
		$('#galleryNav .galleryNav').hide();
		$('#navPhotos').show();
	});		
	$('#toggleVideo').click(function(){
		$('.galleryDiv').removeClass('on').hide();
		$('.galleryToggle').removeClass('on');
		$('#divVideo').show();
		$(this).addClass('on');
		$('#galleryNav .galleryNav').hide();
	});
	var bCamsLoaded=false;
	$('#toggleWebCams').click(function(){
		$('.galleryDiv').removeClass('on').hide();
		$('.galleryToggle').removeClass('on');
		if (!bCamsLoaded) {
			loadWebCams();
		}
		$('#divWebCams').show();
		$(this).addClass('on');
		$('#galleryNav .galleryNav').hide();
		$('#navWebCams').show();
	});	
	$('#toggleWebCams').click();	




	$('#popupWeatherClose').click(function() {
		$('#interioWeatherPopup').toggle();
		$('#homepageWeatherPopup').toggle();
	});		
	
	$('#gsearchBox').click(function(){
		var $box = $('#gsearchBox');
		if ($box.val()=='CAN WE HELP YOU FIND YOU SOMETHING') $box.val('');
	});
	$('#emailSignup').click(function(){
		var $box = $('#emailSignup');
		if ($box.val()=='ENTER YOUR EMAIL') $box.val('');
	});	
		
});

function loadWebCams() {
	// load content
	$('#divWebCams').load(
		sAppPath + '/SiteBase/wrap/theme2/includes/galleryWebCams.aspx',
		function() {
			bCamsLoaded = true;
			$('#webcamNext').click(function(){
				var $current = ($('#divWebCams li.active'));
				var $next = $current.next();
				if (!$next.length) $next = $('#divWebCams li:first');
				
				$next.fadeIn('slow');		
				$next.addClass('active');
				$current.hide();
				$current.removeClass('active')

				$('#webcamCount .showing').html( $('#divWebCams li').index($next)+1 );
				
			});	
			
			$('#webcamPrev').click(function(){
				var $current = ($('#divWebCams li.active'));
				var $next = $current.prev();
				if (!$next.length) $next = $('#divWebCams li:last');
				
				$next.fadeIn('slow');		
				$next.addClass('active');
				$current.hide();
				$current.removeClass('active')
				
				$('#webcamCount .showing').html( $('#divWebCams li').index($next)+1 );
				
			});		
			
			if ( $('#divWebCams li').length > 1 ) {
				$('#webcamCount .total').html( $('#divWebCams li').length );
				$('#webcamNext').click();
				$('#webcamNav').show();
			} else {
				$('#webcamNext').click();
				$('#webcamNav').hide();
			}
		}
	);		
}


function openNav(){  
	$(this).addClass('topNavOpen');  
}  
function closeNav(){  
	$(this).removeClass('topNavOpen');  
}


