var sandvenSliderNew = Class.create(
{
	initialize: function(obj)
	{
		var self = this;
		this.obj = obj;
		
		this.currentImg = 0;
		this.previousImg = 0;
		this.allImages = $$('#'+this.obj.sliderUl+' .'+this.obj.sliderLi);
		this.numOfImages = this.allImages.size();

		this.ulWidth = (this.imgWidth*this.numOfImages);
		
		this.imgWidth = new Array();
		this.totalWidth = 0;
	
		this.allImages.each(function(elm,i){
			 self.imgWidth[i] = $(elm).getWidth();
			 self.totalWidth = (self.totalWidth + $(elm).getWidth());
		});
		
		$(this.obj.sliderUl).setStyle({
			'width': self.totalWidth+'px'
		});
		
		this.isAnimating = false;		
		
		if(this.obj.nextBtn != ''){
			$(this.obj.nextBtn).observe('click',function(ev){
					Event.stop(ev);
					self.slide('+',0);	
			});
		}
		
		if(this.obj.previusBtn != ''){
			$(this.obj.previusBtn).observe('click',function(ev){
					Event.stop(ev);
					self.slide('-',0);
			});
		}
		
		if(this.obj.numBtns != ''){
			this.allBtns = $$('.'+this.obj.numBtns);
			
			self.addRemoveClassName();
			this.allBtns.each(function(elm,i){
				$(elm).observe('click',function(ev){
					Event.stop(ev);
					self.slide('num',i);
				});
			});
		}

	},
	
	addRemoveClassName: function(){
		var self = this;
		
		$(self.allBtns)[self.currentImg].addClassName('active');
		if(self.currentImg != self.previousImg){
			$(self.allBtns)[self.previousImg].removeClassName('active');
		}
	},
	
	
	slide: function(move,number){
		
		var self = this;
		var moveTo = 0;
		
		self.previousImg = self.currentImg;
		
		if(!self.isAnimating){
			
			if(move == '+'){
				if(self.currentImg == (self.numOfImages-1)){
					moveTo = ((-self.totalWidth)+(self.imgWidth[self.currentImg]));
					self.currentImg = 0;
				}else{
					moveTo = self.imgWidth[self.currentImg];
					self.currentImg += 1;
				}
			}
			
			if(move == '-'){
				if(self.currentImg == 0){
					self.currentImg = (self.numOfImages-1);
					moveTo = ((self.totalWidth - self.imgWidth[self.currentImg]));
				}else{
					self.currentImg -= 1;
					moveTo = -self.imgWidth[self.currentImg];
					
				}
			}
			
			if(move == 'num'){
				if(number != self.currentImg){

					moveTo = ((number - self.currentImg)*self.imgWidth[0]);
					
					self.currentImg = number;

				}
			}
			
			if(this.obj.numBtns != ''){
				self.addRemoveClassName();
			}
			
			var y = 0;
			var x = moveTo;

			var elm = $(self.obj.sliderUl);
			self.isAnimating = true;
			
			new Effect.Move(elm,
			{
					x: -x,
					y: y,
					mode: 'relative',
					afterFinish: function(){ self.isAnimating = false; }
	        });
		}
	}
});

Event.observe(window, 'load', function()
{
	
	if($('latestWorkSliderContent')){
		var newSandvenSliderNew2 = new sandvenSliderNew(
		{
			sliderUl : 'latestWorkSliderContent',
			sliderLi : 'latestWork',
			nextBtn : '',
			previusBtn : '',
			numBtns: 'naviNum'
		});
	}
	
	if($('mydesignfavoritesContent')){
		var newSandvenSliderNew = new sandvenSliderNew(
		{
			sliderUl : 'mydesignfavoritesContent',
			sliderLi : 'mydesignfavoritesItem',
			nextBtn : 'mydesignfavoritesNext',
			previusBtn : 'mydesignfavoritesPrevious',
			numBtns: ''
		});
	}
	
});