$(function(){
	
	$('#menu .subMenuOpen').hover(function(){		
		var padding_a_top = parseInt($(this).find('.subMenu a').css('padding-top').replace("px", ""));
		var padding_a_bottom = parseInt($(this).find('.subMenu a').css('padding-bottom').replace("px", ""));
		var height_a = $(this).find('.subMenu a').height()+padding_a_top+padding_a_bottom;
		//alert(height_a);
		var _height = $(this).find('.subMenu > *').length * height_a;
		//alert(_height);
		var _selected = $(this).find('.subMenu');
		_selected.stop().animate(
			{height: _height+'px'},
			{queue:false,
			 duration:200,
			 complete: 	function() {
     						_selected.css('overflow', 'visible');
   			 			}
			 }
		);
		
	}, function(){
		var _selected = $(this).find('.subMenu');
		_selected.stop().animate(
			{height: '0px'},
			{queue:false,
			 duration:50,
			 complete: 	function() {
     						_selected.css('overflow', 'hidden');
   			 			}
			 }
		);
	});
	
	$('#menu .subSubMenuOpen').hover(function(){
		var _marginTop = parseInt($(this).find('.subSubMenu a').css('padding-top').replace("px", ""));
		
		var padding_a_left = parseInt($(this).find('.subSubMenu a').css('padding-left').replace("px", ""));
		var marginLeft_a = $(this).parent().width();
		$(this).find('.subSubMenu').css('margin-left', '0px');
				
		if( $(this).parent().get(0).offsetLeft > 650 ){
			var _marginLeft = - 200 - padding_a_left;
			$(this).find('.subSubMenu').css('margin-top', '-'+_marginTop+'px');
			$(this).find('.subSubMenu').stop().animate(
				{width: '200px', marginLeft:_marginLeft+'px'},
				{queue:false,
				 duration:400}
			);
		}else{
			var _marginLeft = marginLeft_a - padding_a_left;
			$(this).find('.subSubMenu').css('margin-left', _marginLeft+'px');
			$(this).find('.subSubMenu').css('margin-top', '-'+_marginTop+'px');
			$(this).find('.subSubMenu').stop().animate(
				{width: '200px'},
				{queue:false,
				 duration:400}
			);
		}
					
	}, function(){
		$(this).find('.subSubMenu').stop().css('width', '0px');
	});
	
	$('#menu .subMenu').hover(function(){
		$(this).parent().parent().children('.menu').css('background-position', 'left bottom');
	}, function(){
		$(this).parent().parent().children('.menu').css('background-position', 'left top');
	});
	$('#menu .menu').hover(function(){
		$(this).css('background-position', 'left bottom');
	}, function(){
		$(this).css('background-position', 'left top');
	});
	
	/*$('.subMenu, .subSubMenuOpen > a').hover(function(){
		$(this).stop().animate({color: '#00a4e4'}, {queue:false, duration:400});
		$(this).stop().animate({backgroundColor: '#5ec8f1'}, {queue:false, duration:400});
	}, function(){
		$(this).stop().animate({color: '#ffffff'}, {queue:false, duration:200});
		$(this).stop().animate({backgroundColor: '#00a4e4'}, {queue:false, duration:200});
	});*/
});
