Functions= {};

$(document).ready(function () {
	window.setTimeout(Functions.init, 150);
});

Functions= {
	init: function() {
		Functions.prepare();
		
	},
	prepare: function() {
		if($(".block")) {
			//set height
			$(".block .item").each(function() {
				$(this).css("height", $(this).height());
				$(this).hide();
			});
			//set event
			$(".block h2").each(function () {
				$(this).click(function() {
					Functions.clap($(this));
				});
			});
			//show first
			$(".block:first .item").show();
			$(".block:first h2").addClass("active").unbind("click");
		}
	},
	clap: function(obj) {
		//close open
		$(".block .item").each(function() {
			if($(this).css("display")=="block") {
				//animate
				var height= $(this).css("height");
				$(this).animate({ 
					height: "0"
				}, 300, 'linear', function() {
					$(this).hide();
					//set height and add event
					$(this).css("height", height)
					$(this).prev().removeClass("active").click(function() {
						Functions.clap($(this));
					});
				});
			}
		});
		//open obj
		var height= $(obj).next().css("height");
		$(obj).next().css("height", 0);
		$(obj).next().show();
		$(obj).next().animate({ 
			height: height
		}, 300, 'linear', function() {
			$(obj).addClass("active").unbind("click");
		});
	}
}