/*
	slidedown toggles
*/

(function($) {
	var settings = {
		duration: 400,
		openClass: 'slidedown_open',
		contentClass: 'fold',
		toggle: 'h2'
	};

	function toggle(el) {
		set(el, !el.hasClass(settings.openClass), settings.duration);
	}

	function set(el, state, duration) {
		if (state) {
			el.addClass(settings.openClass);
			el.find('.'+settings.contentClass).slideDown(duration);
		} else {
			el.removeClass(settings.openClass);
			el.find('.'+settings.contentClass).slideUp(duration);
		}
	}

	var methods = {
		init: function(options) {
			return this.each(function() {
				var self = $(this);
				set(self, self.hasClass(settings.openClass), 0);
				self.find(settings.toggle).click(function() {
					toggle($(this).parent());
				});
			});
		}
	}

	$.fn.slidedown = function(method) {
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		} else if (typeof method === 'object' || ! method) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.slidedown' );
	    }
	};
})(jQuery);

$(function() {
	$('.expandable').slidedown();
});

