var Books = function() {
	return {
		items: new Array(),
		create: function(pElement) {
			var book = new Book(pElement);
			this.items.push(book);
		}
	};
}();

var Book = function(pContainer) {
	this.moveableDiv = YAHOO.util.Selector.query('div[class=text-full]',pContainer);
	var imgs = YAHOO.util.Selector.query('div[class=top_orange]',pContainer)[0].getElementsByTagName('img');
	
	this.moveLivro = function() {
		if (this.anim.isAnimated()) {
			this.anim.stop();
		}
		this.anim.attributes.left = { to: 0 }; 
		this.anim.attributes.height = { to: this.sizeLivro };
		this.anim.animate();
	};
	
	this.moveTrecho = function() {
		if (this.anim.isAnimated()) {
			this.anim.stop();
		}
		this.anim.attributes.left = { to: -520 }; 
		this.anim.attributes.height = { to: this.sizeTrecho };
		this.anim.animate();
	};
	
	YAHOO.util.Event.on(imgs[0],'click',this.moveLivro,this,true);
	YAHOO.util.Event.on(imgs[1],'click',this.moveTrecho,this,true);

	var items = YAHOO.util.Selector.query('div[class=text-item]',this.moveableDiv[0]);
	this.sizeLivro = items[0].clientHeight;//YAHOO.util.Dom.getClientHeight(items[0]);
	this.sizeTrecho = items[1].clientHeight;//YAHOO.util.Dom.getClientHeight(items[1]);
	YAHOO.util.Dom.setStyle(this.moveableDiv,'height',this.sizeLivro+'px');
	
	this.anim = new YAHOO.util.Anim(this.moveableDiv,{},1,YAHOO.util.Easing.easeOut);
};

YAHOO.util.Event.onDOMReady(function() {
	var x = YAHOO.util.Selector.query('div[class=container]');
	for (var i=0; i < x.length; i++) {
		Books.create(x[i]);	
	}
});
