jQuery.fn.initMenu = function(options) {
	options = $.extend({
		onSelectionChanged: $.noop
	}, options)
	return this.each(function(){
		var theMenu = $(this).get(0);
		$('.acitem', this).hide();
		$('li.expand > .acitem', this).show();
		$('li.expand > .acitem', this).prev().addClass('active',1000);
		$(this).find(".select-all").hide();
		$('li a', this).click(
		function(e) {
			e.stopImmediatePropagation();
			var self = this
			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')
						$(this).prev().removeClass('active')
						$(this).prev().addClass('active',1000);
					}
					else {
						$(this).prev().removeClass('active',1000,function()
						{
							$(this).parents("li").find("li").removeClass("hidden").show();
						});

					}
				});

				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')
							$(this).prev().addClass('active')
							$(this).prev().removeClass('active',1000);
						});


						return false;
					}
					return false;
				}
				if(theElement.hasClass('acitem') && !theElement.is(':visible')) {
					$('.acitem:visible', parent).first().slideUp('normal', function() {
						$(parent).find("a.selected").removeClass('selected') // deselect all
						options.onSelectionChanged($(theMenu).find(".selected"))
						$(this).prev().removeClass('active');
						$(this).prev().addClass('active');
						$(this).prev().removeClass('active',1000);
						$(this).prev().find(".type-sel").fadeOut(1000,function(){
							$(this).children(".hide").removeClass("hide");
							$(this).parents("li").find("li").removeClass('hidden').show();
						});
						$(this).prev().find(".select-all").animate({width: "0"},function(){$(this).hide()});
						$(this).prev().find(".select-all").removeClass("all-selected")

					});

					theElement.slideDown('normal', function() {
						$(this).prev().addClass('active');
						$(this).prev().removeClass('active');
						$(this).prev().addClass('active',1000);

						var pics = $(this).find("li:has(span.type[data='1'])").length > 0;
						var movies = $(this).find("li:has(span.type[data='2'])").length > 0;
						$(self).find(".type-pics")[pics ? 'show' : 'hide']();
						$(self).find(".type-movies")[movies ? 'show' : 'hide']();
						$(self).find(".type-sel-splitter")[pics && movies ? 'show' : 'hide']();
						$(self).find(".type-sel").fadeIn(1000);
						$(self).find(".select-all").css({width: 0}).show().animate({width: "24px"});
					});
					return false;
				}


				if(e.target.className != "noprevent")
				{
					$(this).toggleClass('selected');
					options.onSelectionChanged($(theMenu).find(".selected"))
					e.preventDefault();
				}
			}
		}
		);
	});
};


