animate.framesPerSec = 30;
var accordion = {
	div : null,
	folds : null,
	height : null,
	openHeight : null,
	init : function (divID,method) {
		this.div             = $(divID);
		this.method          = method;
		this.folds           = this.div.getElementsByClassName("accordion");
		this.height          = this.div.offsetHeight;
		this.openHeight      = this.height;
		
		for (this.i=0; this.i<this.folds.length; this.i++) {
			this.fold        = this.folds[this.i];
			this.header      = this.fold.getElementsByTagName("h2")[0];
			
			
			this.fold.setStyles({overflow:"hidden"});
			if (this.method == "click") {
				this.fold.onclick = function () { accordion.toggle(this) };
			}
			if (this.method == "hover") {
				this.fold.onmouseover = function () { accordion.toggle(this) };
			}
			
			dom.applyMethods(this.header);
			this.header.setStyles({cursor:"pointer"});
			
			
			if (this.i != 0) {
				this.openHeight -= this.header.offsetHeight;
			}
		}
	},
	create : function () {
		for (this.i=0; this.i<this.folds.length; this.i++) {
			this.fold    = this.folds[this.i];
			if (this.i == 0) {
				this.fold.addClass("open");
				this.fold.setStyles({height:this.openHeight+"px",overflow:"auto"});
			}
			else {
				this.header = this.fold.getElementsByTagName("h2")[0];
				this.fold.setStyles({height:this.header.offsetHeight+"px"})
			}
		}
	},
	toggle : function (fold) {
		if (fold.className.indexOf("open") == -1) {
			//get other folds
			this.folds = fold.parentNode.getElementsByClassName("accordion");
			for (this.i=0; this.i<this.folds.length; this.i++) {
				if (this.folds[this.i].className.indexOf("open") != -1) {
					this.folds[this.i].removeClass("open");
					this.folds[this.i].style.overflow="hidden";
					this.folds[this.i].style.width="100%";
					this.newHeight = this.folds[this.i].getElementsByTagName("h2")[0].offsetHeight;
					animate.scale(this.folds[this.i],null,this.newHeight,5);
				}
			}
			
			//set classname
			fold.className = "accordion open";
			
			animate.scale(fold,null,this.openHeight,5);
			animate.setEvent("$('"+fold.id+"').style.overflow='auto'",5);
		}
	}
};
