
/*
 * Плавное скрытие блоков
 * TimeZero <http://www.timezero.ru/>
 * 2007-12-24
 * Автор: Дмитрий Шкинёв <berkel@timezero.ru>
 */

var HideAnimation = function(containerId, isHide){

	this._container = $(containerId);
	this._containerDefaultHeight = 171;

	this._arr = $(containerId + "-arr");

	this._changeHeightInterval = 10;
	this._changeHeightDefaultStep = 7;

	this._containerIntervalId = null;

	this._isHide = false;

	if (isHide){

		this._container.style.height = "1px";
		this._container.style.display = "none";

		this._isHide = true;

		this._arr.getElementsByTagName("IMG")[0].src = "/i/i-p.gif";

	} else {

		this._container.style.display = "block";
	}

	var eThis = this;

	cmnAdd_event(this._arr, "click",

		function(){

			if (eThis._isHide){

				eThis.show();

			} else {

				eThis.hide();
			}
		}
	);
}

HideAnimation.prototype = {

	hide : function(){

		var eThis = this;

		if (eThis._containerIntervalId){

			return false;

		} else {

			eThis._containerIntervalId = setInterval(

				function(){

					eThis.changeHeight("hide");

				}, eThis._changeHeightInterval
			);
		}

		eThis._isHide = true;
	},

	show : function(){

		var eThis = this;

		if (eThis._containerIntervalId){

			return false;

		} else {

			eThis._container.style.display = "block";

			eThis._containerIntervalId = setInterval(

				function(){

					eThis.changeHeight("show");

				}, eThis._changeHeightInterval
			);
		}

		eThis._isHide = false;
	},

	changeHeight : function(mode){

		var eThis = this;

		var containerHeight = eThis._container.offsetHeight;

		var step = eThis._changeHeightDefaultStep;

		if (mode == "hide"){

			if ((containerHeight - step) <= 0){

				eThis._container.style.height = "1px";
				eThis._container.style.display = "none";
				clearInterval(eThis._containerIntervalId);
				eThis._containerIntervalId = null;

				eThis._arr.getElementsByTagName("IMG")[0].src = "/i/i-p.gif";

			} else {

				eThis._container.style.height = (containerHeight - step) + "px";
			}

		} else if (mode == "show"){

			if ((containerHeight + step) >= eThis._containerDefaultHeight){

				eThis._container.style.height = eThis._containerDefaultHeight + "px";
				clearInterval(eThis._containerIntervalId);
				eThis._containerIntervalId = null;

				eThis._arr.getElementsByTagName("IMG")[0].src = "/i/i-m.gif";

			} else {

				eThis._container.style.height = (containerHeight + step) + "px";
			}
		}
	}
}