/**
* Drop Down Menu
*
* @author Webfox Developments - James Simmonds
* @version 1.0
* @date 04/12/2009
*
**/


function dropdownmenu(id) {
	this.duration = 0.5;
	this.endDelay = 0.25;
	this.id = id;
	this.state = 0;
	this.height = 150;
	this.width = 120;

	this.menuup = null;
	this.menudown = null;

	this.slideDown = slideMenuDown;
	this.slideUp = slideMenuUp;
	this.cancel = cancelSlide;
	this.changeState = menuState;
	this.setHeight = setHeight;
	this.setWidth = setWidth;
	this.slideTime = getSlideTime;

}

function slideMenuDown() {
	this.cancel();
	if (this.state == 0) {
		this.menudown = new Effect.Morph(this.id, {duration:this.slideTime('down'), style:'height:'+this.height+'px;'});
		this.state = 1;
	}
}

function slideMenuUp() {
	this.cancel();
	if (this.state == 1) {
		this.menudown = new Effect.Morph(this.id, {duration: this.slideTime('up'), delay: this.endDelay, style:'height:0px;'});
		this.state = 0;
	}
}

function menuState(state) {
	this.state = state;
}

function cancelSlide() {
	if (this.menudown != null) {
		this.menudown.cancel();
	}
	if (this.menuup != null) {
		this.menuup.cancel();
	}
}

function setHeight(height) {
	this.height = height;
}

function setWidth(width) {
	this.width = width;
	$(this.id).style.width = width+'px';
}

function getSlideTime(dir) {
	var currHeight = $(this.id).getHeight();
	var dur = this.duration;
	switch (dir) {
		case 'down':
			if (currHeight > 0) {
				var acc = this.duration / this.height;
				var dist = this.height - currHeight;
				dur = dist * acc;
			}
			break;
		case 'up':
			if (currHeight < this.height) {
				var acc = this.duration / this.height;
				dur = currHeight * acc;
			}
			break;
		break;
	}
	return dur;
}