// wenn untermenue nicht in die Zeile passen
// --> boxen ganz links anfangen lassen

$(function() {

	$("#navi > ul > li > div > a").mousemove(function(){

		var to_move = false;

	    	$(this).parent().children("ul").each(function(){    

	        	$(this).children("li").each(function(){
		        	if ($(this).position().top > 0) to_move = true;
                                // IE bricht nicht um, deshalb Position nach links ueberprüfen
                                if ($(this).position().left >= 0) to_move = true;
        		});

        		if (to_move && $(this).children("li").length > 4) {
        			$(this).css('left','0');
                        }
    		$(this).show();
    		});
	});

	$("#navi > ul > li").mouseleave(function(){
		$(this).children("div").each(function(){    
	    		$(this).children("ul").each(function(){    
				$(this).hide();
    			});
		});
	});
});
