(function( $ ){

	var settings = {};

	var methods = {

		init : function( options ) {

			if ( options ) $.extend( settings, options );

			settings.items = this;

			return this.each(function() {

				$(this)
				.find(".events")
				.find("div[rel]")
				.each(function(){
					$(this)
					.data( "height" , $(this).height()+20 )
					.height(0)
					.hide()
					;
				})
				;

				$(this)
				.find(".times")
				.children()
				.css({
					"cursor": "pointer"
				})
				.click(function(){

					if( $(this).hasClass("active") ) return;

					var r = $(this).attr("rel");

					$(this)
					.siblings()
					.removeClass("active")
					;

					$(this)
					.addClass("active")
					;

					$(this)
					.parent()
					.parent()
					.find(".events div[rel]")
					.hide()
					.height(0)
					;

					var s =
					$(this)
					.parent()
					.parent()
					.find(".events div[rel='"+r+"']")
					;

					s
					.show()
					.animate({"height":s.data("height")},1000)
					;

				})
				.eq(0)
				.click()
				;

			});

		}

	};

	$.fn.WomanspaceTimeline = function( method ) {
		// Method calling logic
		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 );
		}
	};

})( jQuery );

$(document).ready(function(){
	$("#timeline")
	.WomanspaceTimeline("init");
});

