var state = 0;
var currentslide = 1;
var slides = 2;
var mxcarousel = new Class({
		wrapper:'',
		items:'',
		moveleft:'',
		moveright:'',
		slides:2,
		offset:350,
		currentslide:1,
		pos:0,
		ispaged:false,
		//aa:{},
		initialize: function(wrapper,items,moveleft,moveright, ns,sss,ispaged){
			//this.setOptions(options);
			$("carousel1_moveleft").style.display ="none";
			if(ns>1){
				$("carousel1_moveright").style.display ="";
			}else{
				$("carousel1_moveright").style.display ="none";
			}
						
			this.wrapper = $(wrapper);
			this.items = $(items);
			this.moveleft = $(moveleft);
			this.moveright = $(moveright);
			this.slides = ns;
			slides = this.slides;
			this.offset = sss;
			this.ispaged = ispaged;
			this.parent = "";
			this.parent = this.wrapper.getParent();
			this.dir = "right"; // direction of paging
			var that = this;
			
			this.moveleft.addEvent('click', this.camoveleft.bind(this));
			this.moveright.addEvent('click', this.camoveright.bind(this));
			
		},
		
		
		camoveleft: function(event){
			if(state==0){
				event = new Event(event).stop();
				if(this.currentslide == 1) return;
				//this.aa[this.currentslide].className= "paging_anchor current"
				this.currentslide--;	
				currentslide = this.currentslide;
				if(this.ispaged){																						
					this.setcss('left');
					this.dir = 'left';
				}
				this.pos += -(this.offset);
				Fxscroll = new Fx.Scroll(this.wrapper, {
						duration: 1000,
						offset:{'x':0, 'y':0}, 
						onStart:function(){
							state = 1;
							$("carousel1_moveleft").style.display ="none";
						}, 
						onComplete:function(){
							state = 0;
							if(currentslide == 1){
								$("carousel1_moveleft").style.display ="none";
							}else{
								$("carousel1_moveleft").style.display ="";
							}
							$("carousel1_moveright").style.display ="";
						}
				});
				Fxscroll.start(this.pos);
				Fxscroll.toLeft();
			}
		},
		camoveright: function(event){
			if(state==0){
				
				event = new Event(event).stop();
				if(this.currentslide >= this.slides) return;
				this.currentslide++;
				currentslide = this.currentslide;
				if(this.ispaged){																						
					this.setcss('right');
					this.dir = 'right';
				}
				this.pos += this.offset;
				Fxscroll = new Fx.Scroll(this.wrapper, {
						duration: 1000,
						offset:{'x':0, 'y':0}, 
						onStart:function(){
							state = 1;
							$("carousel1_moveright").style.display ="none";
						}, 
						onComplete:function(){
							state = 0;
							if(currentslide >= slides){
								$("carousel1_moveright").style.display ="none";
							}else{
								$("carousel1_moveright").style.display ="";
							}
							$("carousel1_moveleft").style.display ="";
						}
				}, this);
				Fxscroll.start(this.pos);
				Fxscroll.toLeft();
				//this.resetcss();
				//this.aa[this.currentslide].className= "paging_anchor current"
		
			}
		},
		
		page: function(pagenum,o, p){
			//event = new Event(event).stop();
			//alert("page -" + pagenum);
			var sss = ((pagenum-1)*this.offset) ;
			if(pagenum > this.slides) return;
			if(pagenum == 1) sss = 0;
			this.currentslide = pagenum
			this.pos = sss
			this.scroll.start(this.pos);this.scroll.toLeft();
			//o.className="current";
			this.resetcss(o, p);
			/*var pa = $$(".paging_anchor");
				pa.each(function(el,i){
				el.className="page";
			});*/
		},
		setcss:function(dir){
			var x = parseInt(this.currentslide)-1; 		
			if(x < 0 ) x = 0; if( x >9) x =9; 
			var o = this.carousel_paging.getElements('a')[x];
			this.resetcss(o,this.carousel_paging);
		},
		resetcss: function(o,p){
			var cpa = p.getElements('a');
			cpa.each(function(el,i){
				el.className="page";
			});
			o.className="current";
		}
		
	});
	mxcarousel.implement(new Events);
	mxcarousel.implement(new Options);