var CustomSlider = new Class({
        options:{
            duration: 250,
            wrap: false,
            previous: "",
            next: "",
            target: ""
        },
        initialize: function(id,options){
            this.setOptions(options);
            this.container = $(id);
            this.wrap = this.options.wrap;
            this.target = $(this.options.target);
            this.previous = $ES('.'+this.options.previous,$(id));
            this.next = $ES('.'+this.options.next,$(id));
            this.individual = $ES('.cartItem');
            
            this.initPrevious(this.options.previous);
            this.initNext(this.options.next);
        },
        initPrevious: function(previous){
        	if(this.wrap == false){
        		//console.log(this.previous);
        	}	
            this.previous.each(function(previous){
                previous.addEvent('click',function(){
					//this.show = previous.getParent().getPrevious();
					this.show = previous.getPrevious(this.individual);
					if ((this.wrap == true)&&(this.show == null)){
						this.show = previous.getLast(this.individual);
                		this.scrollToElement(this.show)
            		}else if(this.show != null){
                    	this.scrollToElement(this.show)
            		}
            		this.next.setStyle('display','inline');
                }.bind(this));
            }.bind(this));
        },
        initNext: function(next){
            this.next.each(function(next){
                next.addEvent('click',function(){
					this.show = next.getNext($('.cartItem'));
					if ((this.wrap == true)&&(this.show == null)){
						this.show = next.getFirst($('.cartItem'));
                		this.scrollToElement(this.show)
            		}else if(this.show != null){
                    	this.scrollToElement(this.show)
						//console.log(this.show.className);
            		}
					//console.log(this.show.className);
                }.bind(this));
            }.bind(this));
        },
        scrollToElement: function(show){
			var fx = new Fx.Scroll(this.container, {duration:this.options.duration, wait:false, transition:Fx.Transitions.Quad.easeInOut,
						onStart:function(){
							// console.log(target);
				        	// console.log('show: '+show);
						},
						onComplete:function(show){
				        	//
						}
					});	
			fx.toElement(show);
        }
});
CustomSlider.implement(new Events, new Options);