var eWeb = (function() {
	// constants
	var EXTRA_SCROLL_PADDING = 20;
	
	// lookups
	var COLORMAP = {
		'#about': { bkg: '#000044', border: '#000099' },
		'#games': { bkg: '#440044', border: '#990099' },
		'#jobs': { bkg: '#004400', border: '#009900' },
		'#contact': { bkg: '#440000', border: '#990000' }
	};
				
	// private
	var	_scrollOffset;
	
	function scrollToSection(section) {
		$('html, body').animate({
			scrollTop: $(section).offset().top - _scrollOffset
		}, 350);			

		$('body').animate({
			backgroundColor: COLORMAP[section].bkg				
		}, 500);
		
		$('#navbar').animate({
			borderBottomColor: COLORMAP[section].border
		}, 500);
	}

	// public 
	return {
		init: function() {
			_scrollOffset = $('#navbar').height() + EXTRA_SCROLL_PADDING;
			
			$('#navlist').click(function(e) {
				if (e.target.nodeName.toLowerCase() != 'a') return;
				
				e.preventDefault();
				
				scrollToSection($(e.target).attr('href'));
			});
			
			$('#navlist a').hover(
				function(e) {
					var current = $(this);
					var section = current.attr('href');
					current.
						animate({
							backgroundColor: '#eee',
						}, 90).
						animate({
							backgroundColor: COLORMAP[section].bkg,
						}, 300);
				},
				function(e) {
					$(this).animate({
						backgroundColor: '#000',
					});
				}
			);
			
			$("a.iframe").fancybox({
				'hideOnContentClick': true,
				'centerOnScroll': true,
				'autoScale': true,
				'padding': 20
			});
			
			$("a.map").fancybox({
				'type': 'iframe',
				'centerOnScroll': true,
				'scrolling': 'no',
				'width': 560,
				'height': 340,
				'padding': 0
			});
			
			$(".screenshots").fancybox({
				'type': 'image',
				'titleShow': false,
				'autoScale': false
			});
		}
	}
})();

$(document).ready(eWeb.init);
