var jQuerySmaAccordionMenu = {
    init: function() {
	jQuery(document).ready(function() {
		var AccordionContainer = jQuery(".jquery-sma-accordion-menu");
		
	    activeLevel = AccordionContainer.find(".activeLevel");
	    if ( activeLevel.length == 1 ) {
	    	activeLevelParentParent = activeLevel.parent().parent();
	    	activeLevelParentParent.find(".close:first").addClass('close_active');
	    	activeLevelParentParent.find(".bottom:first").addClass('bottom_active');	    	
	    } else {
	    	activeLevel = 0
	    	AccordionContainer.find(".close:first").addClass('close_active');
	    	AccordionContainer.find(".bottom:first").addClass('bottom_active');
	    }
	    
	    AccordionContainer.accordion({
	    active: activeLevel,
		header: '.toggler',
		event: 'mouseover',
		selectedClass: 'bottom_active',
		changestart: function(event, ui) {
		    ui.newContent.parent().next().addClass('close_active');
		    ui.newContent.parent().addClass('bottom_active');
		    ui.oldContent.parent().next().removeClass('close_active');
		    ui.oldContent.parent().removeClass('bottom_active');
		},

		change: function(event, ui) {

		}
	    });
	    
	    /*
	    // IE Fix:
	    // make sure that the accordion container have a constant height
	    // to avoid flickering elements below the accordion 
	    */
	    
	    // get the computed height 
	    var constantHeight = AccordionContainer.height();
	    // add the computed height as height via inline styles
	   	AccordionContainer.css("height", constantHeight);
	    jQuery("div:first-child", AccordionContainer).css("height", "auto");
	});
    }
}

jQuery(document).ready(function() {
	jQuerySmaAccordionMenu.init();
});
