function Slider(obj){
	var currentPage;
	var maxPages;
	var object;
	var delta=500;
	
	var self=this;
	
	this.init=function(obj){
		object=jQuery(obj);
		currentPage=0;
		var items=object.find('.scroller .page');
		maxPages=items.length;
		var i=0;
		items.each(function(){
			jQuery(this).addClass('page_'+i);
			if(i==0){
				jQuery(this).addClass('on');
			}
			i++;
		});
		i=0;
		object.find(".controls .page").each(function(){
			jQuery(this).addClass('page_'+i);
			if(i==0){
				jQuery(this).addClass('on');
			}
			jQuery(this).attr('i',i);
			i++;
		});
		i=0;
		object.find(".scroller .page").each(function(){
			jQuery(this).addClass('page_'+i);
			if(i==0){
				jQuery(this).addClass('on');
			}
			else{
//				jQuery(this).hide();
				jQuery(this).css('z-index',-1);
			}
			jQuery(this).attr('i',i);
			i++;
		});
		self.startTriggers();
	}
	
	this.startTriggers=function(){
		object.find('.controls .prev').click(function(e){
			self.setPage(currentPage-1);
		});
		object.find('.controls .next').click(function(e){
			self.setPage(currentPage+1);
		});
		object.find('.controls .page').click(function(e){
			var newPage= jQuery(this).attr('page');
			self.setPage(newPage);
		});
	}
	
	this.clean=function(value){
		if(value>=maxPages)
		{
			return 0;
		}
		if(value<0){
			return maxPages-1;
		}
		return value;
	}
	
	this.setPage=function(page){
		var setAnimation="left";
		if(page>currentPage){
			setAnimation="right";
		}
		page=self.clean(page);
		var scrollerWidth=object.find('.scroller').width();
		
		var current=object.find('.scroller .on');
		var next=object.find('.scroller .page_'+page);

		var first="-";
		var second="+";
		if(setAnimation=="right"){
			first="+";
			second="-";
		}
		object.find('.controls .on').removeClass('on');
		object.find('.scroller .page_'+page).addClass('on');
		object.find('.controls .page_'+page).addClass('on');
		next.animate({left:first+"="+scrollerWidth+"px"},0);
		next.css('z-index', 0);
		next.animate({left:second+"="+scrollerWidth+"px"}, delta);
		current.animate({left:second+"="+scrollerWidth+"px"}, delta);
		current.animate({left:first+"="+scrollerWidth+"px"}, 0, function(){
			object.find('.scroller .page_'+current.attr('i')).removeClass('on');
			object.find('.scroller .page_'+current.attr('i')).css('z-index',-1);
		});
		
		currentPage=page;
	}
	self.init(obj);
}

