var imageW = 1900;
var imageH = 1261;

var timeoutId = null;

function hideSubmenu()
{
	clearTimeout(timeoutId);
	
	if($('div.submenuActive').size() != 0)
	{
		$('div.submenuActive').animate({ 'top': 80 }, 150, function(){
			$(this).removeClass('submenuActive');
		});		
	}	
}

$(document).ready(function(){
	
	
	$('a.main-menu-link').mouseenter(function(){
		var id = 'sub'+$(this).attr('id');

		if($('div#'+id).size() != 0)
		{
			clearTimeout(timeoutId);
			
			if($('div.submenuActive').size() != 0)
			{
				if($('div.submenuActive').attr('id') != id)
				{
					$('div.submenuActive').animate({ 'top': 80 }, 150, function(){
						$(this).removeClass('submenuActive');
						$('div#'+id).animate({ 'top': 117 }, 200);
						$('div#'+id).addClass('submenuActive');
					});
				}
			}
			else
			{
				$('div#'+id).animate({ 'top': 117 }, 200);
				$('div#'+id).addClass('submenuActive');
			}
		}
	}).mouseleave(function(){
		clearTimeout(timeoutId);
		timeoutId = setTimeout('hideSubmenu()', 200);
	});
	
	$('div.submenu').mouseleave(function(){
		clearTimeout(timeoutId);
		timeoutId = setTimeout('hideSubmenu()', 200);
	}).mouseenter(function(){ clearTimeout(timeoutId); });;
	
	
	
	$(window).resize(function(){
		var winW = $(window).width();
		var winH = $(window).height();
		
		var cImgW = $('img#backgroundImage').width();
		var cImgH = $('img#backgroundImage').height();
		
		if(winW > imageW || winH > imageH)
		{
			var w = winW;
			var h = Math.round(winW * (imageH / imageW));
			
			$('img#backgroundImage').css('width', w);
			$('img#backgroundImage').css('height', h);
			$('img#backgroundImage').css('left', Math.round(-1 * w / 2));
			
		}
		else if(cImgW != imageW || cImgH != imageH)
		{
			$('img#backgroundImage').css('width', imageW);
			$('img#backgroundImage').css('height', imageH);
			$('img#backgroundImage').css('left', Math.round(-1 * imageW / 2));
			
		}		
	}).resize();
});
