$(document).ready(function() {
	$('.ddmenu ul').each(function(){
		var width = $(this).width();
		$('li,a', this).width(width);
	});
	$('.ddmenu ul li:last-child a').addClass('last');
	$('.ddmenu > li').hover(
		function(){ 
			$('ul', this).css('display', 'block'); 
			$('a:first', this).addClass('selected');
		},
		function() { 
			$('ul', this).css('display', 'none'); 
			$('a:first', this).removeClass('selected');
		}
	);
});


var top_menu = false;
var top_menu_timer = false;
$(document).ready(function(){
	$('.box_top_menu').hover(
		function(){
			//scot timer
			if(top_menu_timer != false){clearTimeout(top_menu_timer);	top_menu_timer = false;}
			var t_top_menu = $(this).attr('id').substr(3);
			//daca e acelasi submeniu, ignor
			if(t_top_menu == top_menu) return;
			//retin element selectat
			top_menu = t_top_menu;
			//ascund submeniuri daca e deschis vre-unul
			$('.box_top_menu_sub').hide();
			//pozitionez si afisez meniu
			var offset = $(this).offset();
			$('#sub' + top_menu).css('left', offset.left).css('top', offset.top + 20).show();
		},
		function(){
			//scot timer
			if(top_menu_timer != false){clearTimeout(top_menu_timer);	top_menu_timer = false;}
			//daca in x ms n-ajung pe submeniu, il inchid
			if(top_menu == false) return;
			//bag timer pentru inchidere auto in 1/2 sec
			top_menu_timer = setTimeout('if(\''+$(this).attr('id').substr(3)+'\' == top_menu){$(\'#sub'+$(this).attr('id').substr(3)+'\').hide();	top_menu = false; top_menu_timer = false;}', 500);
		}
	);
	$('.box_top_menu_sub').hover(
		function(){
			if(top_menu == false) return;
			top_menu = false;
		},
		function(){
			$('#' + $(this).attr('id')).hide();
			top_menu = false;
		}
	);
});