function body_height_fix() {
	/* Body-Height fix */
	$('body').height(($(window).height() * .4) + $('#contentContainer').height() + 100);
}

jQuery(window).resize(body_height_fix);

jQuery(window).load(body_height_fix);

jQuery(function ($) {
	/* Flyout-Menu 
	 * --------------------------------------------------------------------- */

	var cur_over = null,  /* Last hovered top-level menu item */
		last_mousemove = new Date().getTime(),
		hide_timeout = null,
		hide_after_timeout = function () {
			/* Hide submenu 1 sec after mouseout */
			if (hide_timeout) clearTimeout(hide_timeout);
			hide_timeout = setTimeout(function () {
				if (cur_over && ($li = $(cur_over).not(':hover').find('ul:not(:hover) > li')).length) {
					$li.stop(true, true).animate({width: 'toggle'}, 500);
					cur_over = null;
				}
			}, 1000);
		};
	
	$('#nav > ul > li:has(ul) > a').click(function () {
			/* Disable click on links with submenu */
			return false;
		});

	/* Hover flyout effect for submenus */
	$('#nav > ul > li:has(ul)').hover(function () {
			/* Mouse over */
			var $this = $(this);
			if (cur_over != this) {
				$(cur_over).find('ul > li').stop(true, true).animate({width: 'toggle'}, 500);
				cur_over = this;
				$this.find('ul > li').stop(true, true).animate({width: 'toggle'}, 500);
			}
		},
		hide_after_timeout);

	/* Hide submenu 1 sec after mouseout */
	$('#nav > ul > li > ul').mouseout(hide_after_timeout);

	/* Hide submenu when hovering other top-level menuitems */
	$('#nav > ul > li:not(:has(ul))').hover(function () {
			/* Mouse over */
			var $this = $(this);
			if (cur_over != this && $(cur_over).has('ul').length) {
				$(cur_over).find('ul > li').stop(true, true).animate({width: 'toggle'}, 500);
				cur_over = this;
			}
		},function () {
			/* Mouse out */
			cur_over = null;
		});

	/* record time when mouse is moving */
	$(document).mousemove(function () {
		last_mousemove = new Date().getTime();
	});

	/* Show sub-menus... */
	$('#nav ul li ul').show();
	/* ...and hide sub-menu items */
	$('#nav ul li ul li').animate({width: 'toggle'}, 0);


	/* Portfolio hover
	 * --------------------------------------------------------------------- */
	 
	$('.portfolio-caption').hide().each(function () {
		/* Set width to width of image */
		var padding = 15 * 2 /* Padding left-right */,
			width = 0;
		$(this).parent().find('img').each(function () {
			width += $(this).width();
		});
		$(this).width(width - padding);
	});
	$('.portfolio p').hover(function () {
			$(this).find('.portfolio-caption').slideDown();
		},
		function () {
			$(this).find('.portfolio-caption').slideUp();
		});
});
