var AccordionLinkbox;
AccordionLinkbox = function( id ) {
	this.container = $( '#' + id );
	this.headlines = Array();
	this.contents = Array();
	this.current = null;

	this.init = function() {
		this.headlines = this.container.children( 'ul.alb-main-menu' ).children();
		this.contents = this.container.children( 'ul.alb-main-menu' ).find( 'ul.alb-sub-menu' );
		this.contents.css( 'display' , 'none' );
		var self = this;
		this.headlines.each( function( index , item ) {
			$( item ).children( 'a' ).click( function() {
				var content = $( item ).children( 'ul.alb-sub-menu' );
				if( index != self.current ) {
					self.open( content );
					if( self.current != null ) {
						self.close( $( self.contents[self.current] ) );
					}
					self.current = index;
				} else {
					self.close( $( self.contents[self.current] ) );
					self.current = null;
				}
				return false;
			} );
		} );
	};

	this.open = function( content ) {
		content.slideDown();
		var li = content.parent();
		li.addClass( 'active' );
	};

	this.close = function( content ) {
		content.slideUp();
		var li = content.parent();
		li.removeClass( 'active' );
	};
};


$( document ).ready( function() {
	alb = new AccordionLinkbox( 'more-links-sidebar' );
	alb.init();
} );
