(function ($) {
	$.fn.accordion2 = function(options) {
		var settings = {
			autoHeight: false,
			changestart: function(event, ui) { },
			subsectionSelector: false
		};

		if ($.browser.msie) {
			/*  On IE, minimized title tends to stick to the previous title, due to a dom/css glitch.
				There is also a problem with the content, which has a padding until the mouse moves over it.

				Adding a non-existent class to the parent forces the redrawing of the section.  */
			settings = $.extend(settings, {
				change: function(event, ui) { 
							if ($.browser.msie) {
								$(ui.oldHeader).parent().addClass("") ; 
								$(ui.newContent).parent().addClass("") ;
							}
						}
			});
		}

		settings = $.extend(settings, options);

		var $this = $(this);

		if (settings.subsectionSelector) {
			// join adjacent subsections ( tinymce bug, nodes should not be cloned )
			var selector = settings.subsectionSelector + " + " + settings.subsectionSelector ;
			while ($(selector).length > 0) {
				var $section = $($(selector)[0]) ;
				$section.prev().append($section.html());
				$section.remove();
			}

			/* fix ie bug: move all br to inner div - or accordion won't work */
			
			$(["br", "p"]).each(function(index, e) {
				var element_selector = settings.subsectionSelector + " + " + e ;
				while ($(element_selector).length > 0) {
					var $section = $($(element_selector)[0]) ;
					$section.prev().append($section);
					$section.remove();
				}
			})
		}

		$this.accordion(settings);
		return $this;
	}
}(jQuery));

