function TPlank(plankID, indexInArray) {
	this.id = plankID;
	this.plank = null;
	this.indexInArray = indexInArray;
	this.contentsLayer = null;
	this.toggleLink = null;
	this.animationTimer = null;
	this.contentsHeight;
	this.currentTop;
	this.step = 20;
	this.direction = 0;
	
	this.getHandles = function () {
		this.plank = getCachedElement(this.id);
		this.contentsLayer = getCachedElement(this.id+'_contents');
		this.toggleLink = getCachedElement(this.id+'_toggleLink');
		if (!this.plank || !this.contentsLayer) return false;
//		this.currentTop = parseInt(this.contentsLayer.style.top) || 0;
		this.currentTop = parseInt(this.contentsLayer.style.marginTop) || 0;
		this.contentsHeight = this.contentsLayer.offsetHeight;
	}
	
	this.animate = function () {
		this.currentTop += this.step * this.direction;
		this.step += 10;
		if (this.step > 100) this.step = 100;
		if (Math.abs(this.currentTop) > this.contentsHeight) {
			this.currentTop = this.contentsHeight * (-1);
			if (this.toggleLink != null) this.toggleLink.innerHTML = 'Razširi';
			this.stopAnimation();
		}
		if (this.currentTop > 0) {
			this.currentTop = 0;
			if (this.toggleLink != null) this.toggleLink.innerHTML = 'Skrij';
			this.stopAnimation();
		}
//		this.contentsLayer.style.top = this.currentTop+'px';
		this.contentsLayer.style.marginTop = (this.currentTop)+'px';
//		this.plank.style.height = this.contentsHeight + this.currentTop + 7;
	}
	
	this.startAnimation = function (direction) {
		clearTimeout(this.animationTimer);
		this.direction = direction;
//		if (!this.plank || !this.contentsLayer) this.getHandles();
//		if (!this.plank || !this.contentsLayer) return false;
		this.animationTimer = setInterval('planks['+this.indexInArray+'].animate();', 100);
	}
	
	this.stopAnimation = function () {
		this.direction = 0;
		this.step = 20;
		clearTimeout(this.animationTimer);
	}
	
	this.toggle = function () {
		/* if (!this.plank || !this.contentsLayer) */ this.getHandles();
		if (!this.plank || !this.contentsLayer) return false;
//		if (this.currentTop == 0) this.startAnimation(-1);
		if ((parseInt(this.contentsLayer.style.marginTop) || 0) == 0) this.startAnimation(-1);
		 else this.startAnimation(1);
	}
}

var planks = new Array();

function togglePlank(plankID) {
	var planksCount = planks.length;
	for (var i=0; i<planksCount; i++) {
		if (planks[i].id == plankID) {
			planks[i].toggle();
			return false;
		}
	}
	planks[planksCount] = new TPlank(plankID, planksCount);
	planks[planksCount].toggle();
	return false;
}