jQuery(function() {
	Slidemenu = {
	    init: function(){
	    	// Open the opening marked element at the beginning - non JS users will not see any image
	    	// but that is ok. If we would not do this here, the menu jumps at very first hover!
	    	Slidemenu.openElement(jQuery('ul.accordion li.opening'));
	    	// Set href (Functional without JS!)
	    	jQuery('ul.accordion li').mousemove(function(){
	    		Slidemenu.openElement(jQuery(this));
	    	});
	    },
	    
	    /**
	     * Opens a menu item and closes all others.
	     */
	    openElement: function(listElement){
	    	if(jQuery(listElement).hasClass("closed") || jQuery(listElement).hasClass("opening")){
	    		//Remove events for animation!
	    		jQuery('ul.accordion li').unbind();
		    	Slidemenu.animateHide(jQuery(listElement).siblings("ul.accordion li.open"));
		    	Slidemenu.animateShow(listElement, function(){	
	    			//Rebind event!
	    			window.setTimeout("Slidemenu.init()", 100);
	    		});
	    	}
	    },
	    
	    animateShow: function(listElements, furtherCallback){
	    	jQuery(listElements).each(function(){
	    		jQuery(this).addClass("opening");
	    		jQuery(this).children("div.content").slideDown(500, function(){			
	    			jQuery(this).parent().removeClass("closed");
	    			jQuery(this).parent().addClass("open");
	    			jQuery(this).parent().removeClass("opening");
	    			if(furtherCallback != undefined){
	    				furtherCallback(this);
	    			}
	    		});
	    	});
	    },
	    
	    animateHide: function(listElements, furtherCallback){
	    	jQuery(listElements).each(function(){
	    		jQuery(this).removeClass("open");
	    		jQuery(this).children("div.content").slideUp(500, function(){
	    			jQuery(this).parent().addClass("closed");
	    			if(furtherCallback != undefined){
	    				furtherCallback(this);
	    			}
	    		});
	    	});
	    }
	};
});
