var slideServicos = function( _target )
{
	var ul = $t( 'ul', _target )[0];
	var links = $t( 'a', ul );
	if( links.length<=3 ) return;

	this.deslocamento = links[1].offsetLeft - links[0].offsetLeft;
	this.deslocamentoAtual = parseFloat( getStyle( ul, 'margin-left' ).replace( /[^0-9-]/gi, '') );
	this.deslocamentoMaximo = - ((links.length*this.deslocamento) - _target.offsetWidth ) + this.deslocamentoAtual;

	this.intervaloDeslocamento = null;
	this.tempoScroll = 0;

	ul.style.height = '190px';
	ul.style.width = (links.length*this.deslocamento+10) +'px';

	this.objetoDeslocado = ul;

	var o = this;

	// cria o proximo e o anterior
	var a = DOM.create( 'a' );
	a.className = 'anterior';
	a.innerHTML = 'anterior';
	Evt.add( a, 'click', function( evt ){ Evt.cancel(evt); o.anterior(); } );
	DOM.before(a, ul);

	var p = DOM.create( 'a' );
	p.className = 'proximo';
	p.innerHTML = 'proximo';
	Evt.add( p, 'click', function( evt ){ Evt.cancel(evt); o.proximo(); } );
	DOM.after(p, a);


}

slideServicos.prototype.proximo = function( evt )
{
	var d = this.deslocamentoAtual - this.deslocamento;
	if( d < this.deslocamentoMaximo ) return;
	this.scroll( d );
	this.deslocamentoAtual = d;
}

slideServicos.prototype.anterior = function( evt )
{
	var d = this.deslocamentoAtual + this.deslocamento;
	if( d > 0 ) return;
	this.scroll( d );
	this.deslocamentoAtual = d;
}

slideServicos.prototype.scroll = function( pos ) {
	var t = new Animator();
	t.addSubject(new NumericalStyleSubject(this.objetoDeslocado, 'margin-left', this.deslocamentoAtual, pos));
	t.play();
}


onElementLoad('servicos', function( $servicos ){ new slideServicos($servicos); } );