
$(function() 
{
	$("#main_nav_ul ul").not($(".cur, .act").parent("ul").add(".cur > ul")).hide();
	
	$("#main_nav_ul li").not(".cur, .act").bind('mouseover', function() {
		$(this).stopTime("closeNavTimer");
		var obj = this;
		$(this).oneTime("500ms", "closeNavTimer", function() {
			$(obj).children("ul").slideDown("fast");
		});
	}).bind('mouseleave', function() {
		$(this).stopTime("closeNavTimer");
		var obj = this;
		$(this).oneTime("2s", "closeNavTimer", function() {
					$(obj).children("ul").slideUp("slow");
				});


	});
	
	
	
/*	$("#main_nav_ul li").mouseover(function() {
		$(this).children("ul").slideDown("slow");
		$("#main_nav_ul ul").not($(".cur, .act").parent("ul").add(".cur > ul").add($(this).parent("ul"))).slideUp("slow");
	});*/
	
	$(window).resize(function(){
		resize_bg_img();
	});
	
	resize_bg_img();
	
	
});

function resize_bg_img() {
	var i_width = 1331;
	var i_height = 1200;
	var wh_ratio = i_height / i_width;
	var w_width = $(window).width();
	var w_height = $(window).height();
	var nav_height = $("#nav-container").height();
	
	var target_width = w_width;
	var target_height = w_width / i_width * i_height;
	var margin_left = 0;
	var content_space = $("#wrapper").width();
	var add_scroll = w_width < content_space ? content_space - w_width : 0;
	
	if(target_height < w_height)
	{
		target_height = w_height;
		target_width = target_height / i_height * i_width;
		margin_left = target_width - w_width;
		if(add_scroll > 0)
		{
			margin_left = margin_left - add_scroll;
			if(margin_left < 0)
			{
				margin_left = 0;
			}
			
		}
	}
	$("#bg-div").css({'width': (w_width + add_scroll) + 'px'});
	$("#bg-img").css({'width': target_width + 'px', 'height': target_height + 'px', 'margin-left': '-' + margin_left + 'px'});	
	if(nav_height > (w_height - 150))
	{

		 $("#contact").css({'bottom': (w_height - nav_height - 150) + 'px'});
	}
	else
	{
		 $("#contact").css({'bottom': '0px'});
	}
		
}

