function ActiveObject(el)
{
	this.target = this.item = el;
	this.itemHeight = el.offsetHeight;
	this.itemWidth = el.offsetWidth;
}

ActiveObject.prototype.item = null;
ActiveObject.prototype.target = null;
ActiveObject.prototype.intervalFade = null;
ActiveObject.prototype.intervalFold = null;
ActiveObject.prototype.opacity = 0;
ActiveObject.prototype.intervalOpacityChange = 0.1;
ActiveObject.prototype.intervalFoldChange = 25;
ActiveObject.prototype.timer = 50;
ActiveObject.prototype.itemHeight = 0;
ActiveObject.prototype.itemWidth = 0;
ActiveObject.prototype.folded = false;
ActiveObject.prototype.folding = false;
ActiveObject.prototype.movements = [];
ActiveObject.prototype.foldIndex = 0;
ActiveObject.prototype.easing = 0;
ActiveObject.prototype.fadeMin = 0;
ActiveObject.prototype.fadeMax = 1;
ActiveObject.prototype.maxHeight = 0;

//object.style.clip="rect(0px,50px,50px,0px)"
ActiveObject.prototype.setOpacity = function(opacity)
{
	if(this.item.filters)
	{
		if(this.item.filters.alpha)
		{
			this.item.filters.alpha.opacity=100*opacity;
		}
	}
	this.item.style.mozOpacity=opacity;
	this.item.style.opacity=opacity;
}

ActiveObject.prototype.hide = function(opacity)
{
	this.opacity = 0;
	this.setOpacity(0);
}

ActiveObject.prototype.show = function(opacity)
{
	this.opacity = 1;
	this.setOpacity(1);
}

ActiveObject.prototype.fadeIn = function(start)
{
	if(start == undefined) start = 0;
	this.setOpacity(start);
	var self = this;
	this.intervalFade = setInterval(function(){self.update(1)}, this.timer);
	this.fading = true;
	this.onFadeInStart();
}

ActiveObject.prototype.fadeOut = function(start)
{
	if(start == undefined) start = 1;
	this.setOpacity(start);
	var self = this;
	this.intervalFade = setInterval(function(){self.update(2)}, this.timer);
	this.fading = true;
	this.onFadeOutStart();
}

ActiveObject.prototype.onFadeInStart = function(){}
ActiveObject.prototype.onFadeOutStart = function(){}
ActiveObject.prototype.onFadeIn = function(){}
ActiveObject.prototype.onFadeOut = function(){}

ActiveObject.prototype.foldIn = function(start)
{
	if(this.intervalFold){
		return false;
	}

	if(start == undefined) start = this.itemHeight;

	this.item.style.height = start + 'px';
	var self = this;
	this.folding = true;

	if(this.easing > 0){
		this.foldIndex = 0;
		if(start != 0){
			this.movements = this.getEase(start, 0, this.easing);
		} else {
			this.movements = [0];
		}
	}
	this.intervalFold = setInterval(function(){self.update(3)}, this.timer);
	this.onFoldInStart();
}

ActiveObject.prototype.foldOut = function(start, max)
{
	if(max){
		this.maxHeight = max;
	}

	if(this.intervalFold){
		return false;
	}

	if(start == undefined) start = 0;

	this.item.style.height = start + 'px';
	var self = this;
	this.intervalFold = setInterval(function(){self.update(4)}, this.timer);
	this.folding = true;

	if(this.easing > 0) {
		this.foldIndex = 0;
		this.movements = this.getEase(start, this.itemHeight, this.easing);
	}

	this.onFoldOutStart();
}

ActiveObject.prototype.onFoldInStart = function(){}
ActiveObject.prototype.onFoldOutStart = function(){}
ActiveObject.prototype.onFoldIn = function(){}
ActiveObject.prototype.onFoldOut = function(){}

// private
ActiveObject.prototype.update = function(mode)
{
	switch(mode)
	{
		case 1:
			if(this.opacity < this.fadeMax) {
				this.opacity += this.intervalOpacityChange;
				this.setOpacity(this.opacity);
			} else {
				this.fading = false;
				this.setOpacity(this.fadeMax);
				clearInterval(this.intervalFade);
				this.intervalFade = 0;
				this.onFadeIn();
			}
			break;
		case 2:
			if(this.opacity > this.fadeMin) {
				this.opacity -= this.intervalOpacityChange;
				///this.setOpacity(this.opacity);
			} else {
				this.fading = false;
				this.setOpacity(this.fadeMin);
				clearInterval(this.intervalFade);
				this.intervalFade = 0;
				this.onFadeOut();
			}
			break;
		case 3:
			var h = (this.easing > 0) ? this.movements[this.foldIndex++] : parseInt(this.item.offsetHeight);
			if(h > 0){
				if(this.easing == 0)
					h -= this.intervalFoldChange;

				this.item.style.height = Math.max(h, 0) + 'px';
			} else {
				this.item.style.height = 0;
				this.folding = false;
				this.folded = true;
				clearInterval(this.intervalFold);
				this.intervalFold = 0;
				this.onFoldIn();
			}
			break;
		case 4:
			var h = (this.easing > 0) ? this.movements[this.foldIndex++] : parseInt(this.item.offsetHeight);

			var targetHeight = this.maxHeight > 0 ? this.maxHeight : this.itemHeight;

			if(h < targetHeight) {
				if(this.easing == 0){
					h += this.intervalFoldChange;
				}
				this.item.style.height = h + 'px';
			} else {
				this.item.style.height = targetHeight + 'px';
				this.folding = false;
				this.folded = false;
				clearInterval(this.intervalFold);
				this.intervalFold = 0;
				this.onFoldOut();

				this.maxHeight = 0;
			}
			break;
	}
}

ActiveObject.prototype.getEase = function(start, end, factor)
{
	if (factor == undefined){
		factor = 5;
	}
	var ar = new Array();
	if (start != undefined && end != undefined){
		start = Math.round(start);
		end = Math.round(end);
		if (end != start)
		{
			var mop = '';
			if (end>start){
				mop = 'ceil';
			} else {
				mop = 'floor';
			}

			do {
				ar.push(start);
				start += (end-start)/factor;
				start = Math[mop](start);
			}
			while(Math[mop](start+((end-start)/factor)) != start);
		}
		ar.push(end);
	}
	return ar;
}