$(document).ready(function() {
    $(".subNavButton").click(function(){
		if($(this).parent().next().is(':hidden')) {
			$(this).parent().next().slideDown('normal', function(){
			    var targetOffset = $(this).prev('.subNavGallery').offset().top;
				//var targetHeight = toggleCont.outerHeight();
				//var scrollDist = targetOffset - targetHeight + 15;
				var docHeight = $(document).height();
				var screenHeight = $(window).height();
				if (docHeight > screenHeight) {
					$('html,body').animate({scrollTop: targetOffset}, 1500);
				}
			});
		}
		else {
			$(this).parent().next().slideUp('normal');
			$(".wrecksText").slideUp('normal');
			var docHeight = $(document).height();
			var screenHeight = $(window).height();
			if (docHeight > screenHeight) {
				$('html,body').animate({scrollTop: 0}, 1500);
			}
		}
		return false;
	});
	
	$(".wreckSubTitle a").click(function(){
		if($(this).parents('.wreckSubTitle').next().is(':hidden')) {
			$(this).parents('.wreckSubTitle').next().slideDown('normal', function(){
			    var targetOffset = $(this).prev('.wreckSubTitle').offset().top;
				//var targetHeight = toggleCont.outerHeight();
				//var scrollDist = targetOffset - targetHeight + 15;
				var docHeight = $(document).height();
				var screenHeight = $(window).height();
				if (docHeight > screenHeight) {
					$('html,body').animate({scrollTop: targetOffset}, 1500);
				}																	  
			});
		}
		else {
			$(this).parents('.wreckSubTitle').next().slideUp('normal');
			$(".wrecksText").slideUp('normal');
			if (docHeight > screenHeight) {
				$('html,body').animate({scrollTop: 0}, 1500);
			}
		}
		return false;
	});
});