new Namespace("eu.mckinley.slider.teambox");
eu.mckinley.slider.teambox = Class.create({
	sliderheigh : null,
	pages : 0,
	active : 1,
	container :
			[
			],
	initialize : function (elems) {

		this.container = elems;
		this.actualOpen = null;
		this.writeEvents();
	},
	writeEvents : function () {

		for (var i = 0; i < this.container.length; i++) {
			try {
				this.container[i].head = $(this.container[i]).getElementsByClassName('productheadline')[0];
			}
			catch (e) {
				this.container[i].head = this.container[i].childElements()[0];
			}

			this.container[i].head.myClass = this;
			this.container[i].head.myID = i;

			this.container[i].head.observe('click', this.press);
			try {
				var sliderheigh = $(this.container[i]).getElementsByClassName('detail')[0].getHeight() + 47;
				this.container[i].sliderheigh = sliderheigh;
				this.sliderheigh = sliderheigh;
			}
			catch (e) {
				this.container[i].sliderheigh = 180;
				this.sliderheigh = 180;
			}
			this.container[i].statusOpen = false;
			this.container[i].setStyle({height: '33px'});
			this.container[i].removeClassName("open");

			if (this.container[i].getAttribute("lang") == "open") {
				window.setTimeout(this.press.bind(this.container[i].head), 1);
			}
		}
	},
	press : function () {
		if (this.myClass.container[this.myID].statusOpen == false) {
			this.myClass.openSingle(this.myID);
		}
		else {
			this.myClass.closeSingle(this.myID);
		}

	},
	openSingle : function (id) {
		var ani = new Animator({transition: Animator.makeEaseIn(2),duration: 1000});
		ani.addSubject(new NumericalStyleSubject($(this.container[id]), 'height', 32, $(this.container[id]).sliderheigh));
		ani.play();
		this.container[id].statusOpen = true;
		this.container[id].className = 'product open';
		this.actualOpen = id;
	},
	closeSingle : function (id) {

		var ani = new Animator({transition: Animator.makeEaseIn(2),duration: 1000});
		ani.addSubject(new NumericalStyleSubject($(this.container[id]), 'height', $(this.container[id]).sliderheigh, 32));
		ani.play();
		this.container[id].statusOpen = false;
		this.container[id].className = 'product';
		this.actualOpen = null;
	},
	removeIndex : function (index) {

		if (this.container[index].statusOpen == true) {
			this.closeSingle(index);
		}
		var ani = new Animator({transition: Animator.makeEaseIn(2),duration: 500,onComplete: function() {
			$(this.container[index]).update('');
			$(this.container[index]).remove();

		}.bind(this)});
		ani.addSubject(new NumericalStyleSubject($(this.container[index]), 'opacity', 1, 0));
		ani.play();
	}

});

