
var carousel = {
							
	inicialize: function(options){
		
		this.options = Object.extend({
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			container: document.body,
			descriptions: true,
			opacity: 0.7,
			url: '',
			showedItems: 6
		}, options || {});
		
		this.first_showing = 1;
		this.last_showing = this.options.showedItems;
		
		this.next = 1 + this.options.showedItems;
		this.number_objects = $$('.carousel_item').length;
		
		
		/*$A($$('.project_link')).each(function(el) {
			
			el.onclick = this.click.pass(el, this);			
			
		}, this);*/
		
		if ( $('items_cont') ) {
			this.setupArrows();
		}
		
		//var Tips1 = new Tips($$('.project'));
	
	},
	
	/*click: function(element) {
		
		this.url = element.href;
		
		scroller.toElement('cont_section');
		
		this.changeProfile();
		
		return false;
	},*/
	
	/*changeProfile: function() {
		
		// Amaga el profile actual
		var reposition = new Fx.Styles('portfolio_profile', {
			duration: 1000,
			wait:false,
			transition: Fx.Transitions.Cubic.easeInOut
		});
		reposition.start({
			'height': 0
		}).addEvent('onComplete',function() {
			this.loadContents();				
		}.bind(this));
		
		// carrega els continguts per loadContents()
		
	},*/
	
	
	scrollRight: function() {
		
		var slideshow_scroll = new Fx.Scroll("worksCarouselWrapper",{					 
			wait: false,
			duration: 600, 
			transition: Fx.Transitions.Cubic.easeInOut
		});
		
		slideshow_scroll.toElement($("item-" + this.next));
		
		this.first_showing = this.first_showing + this.options.showedItems;
		this.last_showing = this.last_showing + this.options.showedItems;
		
		this.setupArrows();
				
		return false;
		
	},
	
	
	scrollLeft: function() {
		
		var slideshow_scroll = new Fx.Scroll("worksCarouselWrapper",{					 
			wait: false,
			duration: 600, 
			transition: Fx.Transitions.Cubic.easeInOut
		});
		
		slideshow_scroll.toElement($("item-" + this.back));
		
		this.first_showing = this.first_showing - this.options.showedItems;
		this.last_showing = this.last_showing - this.options.showedItems;
		
		this.setupArrows();
				
		return false;
		
	},
	
	
	setupArrows: function() {
		
		$('arrow_left').removeEvents('click');
		$('arrow_right').removeEvents('click');
		
		
		if ( (this.first_showing + this.options.showedItems) > this.number_objects )
			this.next = this.first_showing;
		else
			this.next = this.first_showing + this.options.showedItems;
		
		if ( (this.first_showing - this.options.showedItems) < 1 )
			this.back = 1;
		else
			this.back = this.first_showing - this.options.showedItems;
		
		
		// Estic al principi
		if ( this.first_showing == 1 ) {
			
			//alert('al principi');
			
			$('arrow_right').addEvent('click', function() {
				this.scrollRight();
			}.bind(this));
			
			$('arrow_left').addClass('disabled_arrow_left');
			
			if ( $('arrow_right').hasClass('disabled_arrow_right') )
				$('arrow_right').removeClass('disabled_arrow_right');
		}
		
		
		// No estic ni al començament ni al final
		if ( this.first_showing > 1 && this.last_showing < this.number_objects ) {
			
			//alert('al mig');
			
			$('arrow_left').addEvent('click', function() {
				this.scrollLeft();
			}.bind(this));
			
			$('arrow_right').addEvent('click', function() {
				this.scrollRight();
			}.bind(this));
			
			if ( $('arrow_left').hasClass('disabled_arrow_left') )
				$('arrow_left').removeClass('disabled_arrow_left');
			
			if ( $('arrow_right').hasClass('disabled_arrow_right') )
				$('arrow_right').removeClass('disabled_arrow_right');
				
		}
		
		// Estic al final
		if ( this.last_showing >= this.number_objects ) {
			
			//alert('al final');
			
			$('arrow_left').addEvent('click', function() {
				this.scrollLeft();
			}.bind(this));
			
			if ( $('arrow_left').hasClass('disabled_arrow_left') )
				$('arrow_left').removeClass('disabled_arrow_left');
						
			$('arrow_right').addClass('disabled_arrow_right');
		}
		
		return false;
		
	}
	
	
	
};
