$(document).ready(function(){				
	$('#navigation').css('width', $('#navigation').width());
	$('#navigation').css('float', 'none');
	$('#navigation > li > ul').each(function(){
		$(this).children().last().addClass('border-none');	
	});
	$('#navigation > li > ul > li').each(function(){
		if($(this).children().size() == 2){
			$(this).addClass('withThirdNav');
		}
	});
	
	$("#slider").sudoSlider({
				numeric:true,
				fade:true,
				auto:              true,
        		pause:             '2000',
				autoheight:        true,
        		autowidth:         true
	});
	
	$('#footerNav li:last-child').addClass('bg-none');
	$('#footerNav li:first-child').css('paddingLeft', '0px');
	
	$('#navigation > li').hover(function(){
		var firstDrop = $(this).children('ul');
		firstDrop.css('height', '0px');
		firstDrop.show();
		var firstDropHeight = findHeight(firstDrop);
		firstDrop.stop().animate({height: firstDropHeight}, 400);		
	},function(){
			var firstDrop = $(this).children('ul');
			firstDrop.stop().animate({height: 0}, 400, function(){ firstDrop.hide();});
		}
	);
	
	$('#navigation > li > ul > li').hover(function(){
	//	var firstDrop = $(this).parent();
		var secondDrop = $(this).children('ul');
		secondDrop.css('height', '0px');
		secondDrop.show();
		var secondHeight = findHeight(secondDrop);
	//	var firstDropHeight = findHeight(firstDrop)+secondHeight;
		//firstDrop.stop().animate({height: firstDropHeight}, 500);
		secondDrop.stop().animate({height: secondHeight}, 400);		
	},function(){
			//var firstDrop = $(this).parent();
			var secondDrop = $(this).children('ul');
			//var secondHeight = findHeight(secondDrop);
			//var firstDropHeight = findHeight(firstDrop)-secondHeight;
			//firstDrop.animate({height: firstDropHeight}, 500);
			secondDrop.stop().animate({height: 0}, 400, function(){secondDrop.hide();});
		}
	);
	
	
});

function findHeight(elem){
	var resHeight = 0;
	elem.children('li').each(function(){
		/* console.log($(this)); */
		resHeight = resHeight + $(this).height()+parseInt($(this).css('paddingTop'))+parseInt($(this).css('paddingBottom'));
	});
	return resHeight;
}
