(function($){
    $.fn.slidePanel = function(opts) {
        opts = $.extend({
            triggerName: '#trigger',
			position: 'absolute',
			triggerTopPos: '0px',
			panelTopPos: '0px',
            speed: 'slow',
			ajax: false,
			ajaxSource: null,
			clickOutsideToClose: true
        }, opts || {});
		var panel = this;
		var trigger = $(opts.triggerName);
		var isIE6 = $.browser.msie && $.browser.version=="6.0"
		if(isIE6) { opts.position = 'absolute' }
		trigger.css('position',opts.position)
		trigger.css('top',opts.triggerTopPos);
		panel.css('position',opts.position)
		panel.css('top',opts.panelTopPos);
		trigger.attr( "href", "javascript:void(0)" ).mousedown(function() {
			if (!opts.ajax) {
				panel.toggle(opts.speed);
				trigger.toggleClass("active");
			};
			return false;
		});
		if (opts.clickOutsideToClose) {
			$(document).bind('mousedown',function(){panel.hide(opts.speed);trigger.removeClass('active');});
			panel.bind('mousedown',function(e){e.stopPropagation();});
		};
	};
})(jQuery);

jQuery.fn.initMenu = function() {  
    return this.each(function(){
        var theMenu = $(this).get(0);
        $('.acitem', this).hide();
        $('li.expand > .acitem', this).show();
        $('li.expand > .acitem', this).prev().addClass('active');
        $('li a', this).click(
            function(e) {
                e.stopImmediatePropagation();
                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                if($(parent).hasClass('noaccordion')) {
                    if(theElement[0] === undefined) {
                        window.location.href = this.href;
                    }
                    $(theElement).slideToggle('normal', function() {
                        if ($(this).is(':visible')) {
                            $(this).prev().addClass('active');
                        }
                        else {
                            $(this).prev().removeClass('active');
                        }    
                    });
                    return false;
                }
                else {
                    if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.acitem:visible', parent).first().slideUp('normal', 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;  
                    }
                    return false;
                }
                if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                    $('.acitem:visible', parent).first().slideUp('normal', function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return false;
                }
            }
        }
    );
});
};

$(document).ready(function() {$('.menu2').initMenu();});
