var endlessScroller = new Class({ 
    getOptions:function(){
        return {
            orient:'horizontal',
            duration:'long'
        };
    },
    initialize:function(itemsCont,activatorOne,activatorTwo,Opts) {
        this.setOptions(this.getOptions(),Opts);
        this.orient = this.options.orient;
        this.activatorOne = activatorOne;
        this.activatorTwo = activatorTwo;
        this.duration = this.options.duration;
        myNavFx = new Fx.Morph(itemsCont,{duration:this.duration,link:'ignore',wait:'true'});
        
        this.moveAmtHoriz = $(itemsCont).getFirst().getStyle('width');
        this.moveAmtVert = $(itemsCont).getFirst().getStyle('height');
        this.moveDir = false;
        $(this.activatorOne).addEvent('click',function(){
            if (this.orient=='vertical'){
                this.curPos = $(itemsCont).getStyle('margin-top');
                this.moveTo = parseInt(this.curPos)-parseInt(this.moveAmtVert);
                myNavFx.start({'margin-top':['0','-'+this.moveAmtVert+'px']});
                (function (){
                    this.firstItem = $(itemsCont).getFirst();
                    this.lastItem = $(itemsCont).getLast();

                    if ($(itemsCont).getStyle('margin-top')=='-'+parseInt(this.moveAmtVert)+'px') {
                        this.firstItem.inject(this.lastItem,'after');
                    }
                    
                    $(itemsCont).setStyle('margin-top','0px');
                }.bind(this).delay(this.duration));
            }
            if (this.orient=='horizontal'){
                this.curPos = $(itemsCont).getStyle('margin-left');
                this.moveTo = parseInt(this.curPos)-parseInt(this.moveAmtHoriz);
                myNavFx.start({'margin-left':['0','-'+this.moveAmtHoriz+'px']});
                (function (){
                    this.firstItem = $(itemsCont).getFirst();
                    this.lastItem = $(itemsCont).getLast();

                    if ($(itemsCont).getStyle('margin-left')=='-'+parseInt(this.moveAmtHoriz)+'px') {
                        this.firstItem.inject(this.lastItem,'after');
                    }
                    
                    $(itemsCont).setStyle('margin-left','0px');
                }.bind(this).delay(this.duration));
            }
        }.bind(this));
        $(this.activatorTwo).addEvent('click',function(){
            if (this.orient=='vertical'){
                this.curPos = $(itemsCont).getStyle('margin-top');
                this.moveTo = parseInt(this.curPos)-parseInt(this.moveAmtVert);
                this.firstItem = $(itemsCont).getFirst();
                this.lastItem = $(itemsCont).getLast();
                if ($(itemsCont).getStyle('margin-top')=='0px') {
                    this.lastItem.inject(this.firstItem,'before');
                }
                this.negMarg = '-'+parseInt(this.moveAmtVert)+'px';
                $(itemsCont).setStyle('margin-top',this.negMarg);
                myNavFx.start({'margin-top':[this.negMarg,'0px']});
            }
            if (this.orient=='horizontal'){
                this.curPos = $(itemsCont).getStyle('margin-left');
                this.moveTo = parseInt(this.curPos)-parseInt(this.moveAmtHoriz);
                this.firstItem = $(itemsCont).getFirst();
                this.lastItem = $(itemsCont).getLast();
                if ($(itemsCont).getStyle('margin-left')=='0px') {
                    this.lastItem.inject(this.firstItem,'before');
                }
                this.negMarg = '-'+parseInt(this.moveAmtHoriz)+'px';
                $(itemsCont).setStyle('margin-top',this.negMarg);
                myNavFx.start({'margin-left':[this.negMarg,'0px']});                
            }
        }.bind(this));
    }
});
endlessScroller.implement(new Options);