$(function(){
	if ($('#mainmenu')) {
		$("#mainMenu ul li a").each(function(index) {
			var subMenu = $('#' + $(this).attr('rel'));
			if (subMenu.attr('id') != null) {
				var position = $(this).position();
				var width = $(this).width() / 2;				
				var subMenuWidth = subMenu.width() / 2;				
				var newPos = (position.left + width) - subMenuWidth - 1;				
				subMenu.css('left',newPos);
				subMenu.hide();
				
				
				subMenu.mouseover(function() {
                	subMenu.stop(true, true);
    	            return false;
            	});
				
				subMenu.mouseout(function() {
					subMenu.delay(100).slideUp();
    	            return false;
            	});
			
			
			}
			
			
			$(this).mouseover(function() {
                var subMenu = $('#' + $(this).attr('rel'));
				if (subMenu.attr('id') != null) {
					subMenu.stop(true, true);
					subMenu.slideDown();
				}
                return false;
            });
			
			$(this).mouseout(function() {
                var subMenu = $('#' + $(this).attr('rel'));
				if (subMenu.attr('id') != null) {
					subMenu.stop(true, true);
					subMenu.delay(100).slideUp();
				}
                return false;
            });
			
			
			
			
        });
	}
});


/*
$(function(){
	if ($('#mainmenu')) {
		maxWidth =$('#mainmenu').width();
	    $("#mainmenu ul.dropdown li").has('ul').hover(function(){
			if (!eval($('ul:first',this).attr('rel'))) {
				curWidth = $('ul:first',this).width();
				if (curWidth < $(this).width()) {
					curWidth = $(this).width();
				}
				curMarginLeft = -10;
				curRight = $(this).position().left + $('ul:first',this).width();
				if (curRight > maxWidth) {
					curMarginLeft = (maxWidth - curRight) - 10;
				}
				$('ul:first',this).css({'width':curWidth, marginLeft:curMarginLeft});
				$('ul:first',this).attr('rel', true);
			}
			$('ul:first',this).stop(true, true).slideDown();
	   	}, function(){
			$('ul:first',this).stop(true, true).slideUp();
	    });
	}
});
*/
