function Carrousel(){
	this.next = $('#next');
	this.prev = $('#prev');
	this.prev.css('display', 'none');
	this.count = 0;
	this.init();	
	this.listeners();	
	this.checkPos(this, 'prev');
	this.checkPos(this, 'next');
};

Carrousel.prototype.init = function(){
	this.container = $('#img-container');
	this.images = $("img", this.container).get();
	// get some measurements
	this.UNIT_WIDTH = (this.images[0].offsetWidth + 5) +'px';
	this.TOTAL_MARGIN = this.images.length * 5;
	this.TOTAL_IMG_WIDTH = this.images.length * this.images[0].offsetWidth;
	// add them up
	this.CONTAINER_WIDTH = (this.TOTAL_IMG_WIDTH + this.TOTAL_MARGIN + 100) + 'px';
	// set img-container width
	this.container.css('width', this.CONTAINER_WIDTH);
};

Carrousel.prototype.listeners = function(){
	this.next.bind('click',[this],this.nextAct);
	this.prev.bind('click',[this],this.prevAct);
};

Carrousel.prototype.nextAct = function(e){
	var base =  e.data[0];
	$('#img-container').animate( { "left": "-=" + base.UNIT_WIDTH }, 300, base.checkPos(base, 'next'));
};

Carrousel.prototype.prevAct = function(e){
	var base =  e.data[0];
	$('#img-container').animate( { "left": "+=" + base.UNIT_WIDTH }, 300, base.checkPos(base, 'prev'));
};

Carrousel.prototype.checkPos = function(base, type){
	if(type == 'next'){
		base.count += 1;
	};
	if(type == 'prev'){
		base.count -= 1;
	};
	if(base.count > 0){
		base.prev.css('display', 'block');
	};
	if(base.count == 0){
		base.prev.css('display', 'none');
	};
	if(base.count == (this.images.length - 8)){
		base.next.css('display', 'none');
	};
	if(base.count < (this.images.length - 8)){
		base.next.css('display', 'block');
	};
};

