(function($) {
	$.fn.extend({
		accordionize: function (options) {
			// Handling standard arguments
			options.clickElement  = options.clickElement  || '.title';
			options.duration      = options.duration      || 600     ;
			options.activeClass   = options.activeClass   || 'active';
			options.easing        = options.easing        || 'swing' ;
			
			// Saving $this and give the ul the correct css-styles.
			var $this = $(this);
			$this.css({
				'position': 'relative',
				height: $this.height(),
				width: $this.width(),
				'overflow': 'hidden'
			});
			
			// Saves the li-elements
			var $childs = $this.children();

			// Store the count of child-elements
			var i = $childs.length;
			
			var totalVisibleHeight = 0;

			// Method for all li's.
			var bindElements = function (index) {
				var $this = $(this).css({
					'z-index': i--,
					'position': 'absolute',
					'top': totalVisibleHeight
				});
				
				totalVisibleHeight += $this.children(options.clickElement).height();
				
				var elementMethod = function () {
					var offset = 0;
					var animationElements = [];
					var top;							
					var sliderMethod = function (index2) {
						var $this = $(this);
						var thisHeight = $this.height();
						var titleHeight = thisHeight - $this.children(':not(' + options.clickElement + ')').height();
						
						$this.children(options.clickElement).removeClass(options.activeClass);
						top = offset;

						if (index2 < index) {
							top -= thisHeight - titleHeight;
						} else if (index2 == index) {
							$this.children(options.clickElement).addClass(options.activeClass);
						}
						
						animationElements.push({
							$element: $this,
							animation: {top: top}
						});

						offset += titleHeight;
					};

					$childs.each(sliderMethod);
					
					for(var k = 0, count = animationElements.length; k < count; ++k) {
						animationElements[k].$element.animate(animationElements[k].animation, {queue: false, duration: options.duration, easing: options.easing});
					}
				};
				
				$this.children(options.clickElement).bind('mouseenter', elementMethod);
			};
			
			$childs.each(bindElements);
			
			/* Auto-Height */
			$this.css({
				height: (totalVisibleHeight + 132) + 'px'
			});
			
			/* Box verlinken */
			$childs.each(
				function() {
					$(this).click(
						function() {
							window.location = $('base').attr("href") + $(this).children().children().filter('a').attr("href");
							return false;
						}
					);
				}
			);
		}
	});
})(jQuery);