// resize background image and font size when windows is resized
function backgroundImage () {
	if ($(window).width() > 1280 || $(window).height() > 848) {
		if ($(window).width() > 1920 || $(window).height() > 1272) {
			$('body').addClass('bg3');
			$('#navigation').addClass('bg3');
		}
		else {
			$('body').addClass('bg2');
			$('#navigation').addClass('bg2');
		}
	}
	else {
		$('body').addClass('bg1');
		$('#navigation').addClass('bg1');
	}
	if ($(window).width() < 1170 || $(window).height() < 676) {
		$('body').addClass('size8');
	}
	else {
		$('body').removeClass('size8');
	}
}

$(document).ready(function(){
	// resize background image and font size when windows is resized
	backgroundImage ();
	$(window).bind('resize',function(){
		backgroundImage ();
	});

	// show and hide navigation
	$('.nav-first').not('.active').hover(
		function(){
			$(this).children('ul').fadeIn('fast');
		},
		function(){
			$(this).children('ul').fadeOut('fast');
		}
	);

	// show and hide footer
	var $footerOpen = false;
	$('#footer').mouseenter(function(){
		if (!$footerOpen) {
			$('#footer .hidden').show(0, function(){
				$('.footer-item').animate({height: '6.5em'},'fast');
				$footerOpen = true;
			});
		}
	});
	$('#footer').mouseleave(function(){
		$('.footer-item').delay(1000).animate({height: '2.5em'}, 'fast', 'swing', function() {
			$('#footer .hidden').hide();
			$footerOpen = false;
		});
	});

	// set nav pos when scrolling
	var nav = $('#navigation');
	var navMargin = 50;
	if ($('body').hasClass('size8')) {
		navMargin = navMargin * 0.8;
	}
	$(window).scroll(function(){
		if ($(window).scrollTop() >= navMargin) {
			nav.css('padding-top', '0');
			nav.css('position', 'fixed');
		}
		else {
			nav.css('padding-top', '5em');
			nav.css('position', 'absolute');
		}
	});

});

