var RevistaDOMActions = Class.create ({
	
	container: 'container-news',
	div: 'news',
	
	baseWidth: 0,
	thumbWidth: 228 + 10,
	list: null,
	
	images: [],
	
	i: 0,
	total: 0,
	totalPages: 1,
	currentPage: 0,
	itensPerPage: 0,
	
	initialize: function ()
	{
		Event.observe (document, 'dom:loaded', this._onDomReady.bindAsEventListener (this) );
	},
	search: function (form)
	{
		form = $(form);
		window.location = form['url'].value + "?" + "q=" + form['q'].value;
	},
	_onDomReady: function (e)
	{
		var inputs = $$('input');
		for (var i = 0; i < inputs.length; i++) {
			inputs[i].observe ('focus', this._onFocus.bindAsEventListener (this, inputs[i]) );
			inputs[i].observe ('blur',  this._onBlur.bindAsEventListener  (this, inputs[i]));
			inputs[i].writeAttribute ('alt', inputs[i].readAttribute ('value') );
		}
		
		try
		{
			this.div = $(this.div);
			this.container = $(this.container);
			
			this.div.setStyle ({width: (this.div.childElements ().length * this.thumbWidth)+'px'});
			
			this.total = parseInt( this.div.getWidth () );
			this.baseWidth = parseInt( this.container.getWidth () );
			this.itensPerPage = Math.floor (this.baseWidth / this.thumbWidth);
			this.totalPages = Math.ceil ( this.baseWidth / this.total );
			this.totalPages++;
		}
		catch (e) {}
	},
	_onFocus: function (e, el)
	{
		var alt = el.readAttribute ('alt');
		if (el.value == alt) {
			el.value = '';
		}
	},
	_onBlur: function (e, el)
	{
		if (el.value == '') {
			el.value = el.readAttribute ('alt');
		}
	},
	next: function ()
	{
		this._updatePage ( this.currentPage + 1 );
	},
	prev: function ()
	{
		this._updatePage ( this.currentPage - 1 );
	},
	_updatePage: function ( index )
	{
		index = parseInt (index);
		if (index < 0)
			index = this.totalPages - 1;
		if (index > this.totalPages - 1)
			index = 0;
		this.currentPage = index;
		
		index = this.baseWidth * this.currentPage * -1;
		
		this.div.morph ('left:'+index+'px');
	}
});

var RevistaDOM = new RevistaDOMActions ();