var LW_Carousel = function(lw_carouselpanel,lw_carouselitem,lw_leftarrow,lw_rightarrow,lw_speed,lw_movewhen,lw_margin,lw_automove) {
	this.carouselpanel = lw_carouselpanel
	this.carouselitem = lw_carouselitem
	this.leftarrow = lw_leftarrow
	this.rightarrow = lw_rightarrow
	this.speed = lw_speed
	this.movewhen = lw_movewhen
	this.itemmargin = lw_margin
	this.curTimer = 0;
	this.autoTimer = 0;
	this.autoMoveTime = 0;
	if (lw_automove) {
		this.autoMoveTime = lw_automove;
	}
	$("." + this.carouselpanel + " ." + this.carouselitem + ":first").before($("." + this.carouselpanel + " ." + this.carouselitem + ":last"))
	if (lw_movewhen=='onclick') {
		this.OverCarouselLeft = 1;
		this.OverCarouselRight = 1;
		$("." + this.rightarrow + " img").click(function(){
			self.OverCarouselRight = 1;
			self.MoveCarouselRight();
			//get the width of the items ( i like making the jquery part dynamic, so if you change the width in the css you won't have o change it here too ) '
		});
		$("." + this.leftarrow + " img").click(function(){
			self.OverCarouselLeft = 1;
			self.MoveCarouselLeft();
		});
	} else {
		this.OverCarouselLeft = 0;
		this.OverCarouselRight = 0;
		$("." + this.rightarrow + " img").mouseover(function(){
			self.OverCarouselRight = 1;
			self.MoveCarouselRight();
			//get the width of the items ( i like making the jquery part dynamic, so if you change the width in the css you won't have o change it here too ) '
		});
		$("." + this.rightarrow + " img").mouseout(function(){
			self.OverCarouselRight = 0;
		});
		
		$("." + this.leftarrow + " img").mouseover(function(){
			self.OverCarouselLeft = 1;
			self.MoveCarouselLeft();
		});
		$("." + this.leftarrow + " img").mouseout(function(){
			self.OverCarouselLeft = 0;
		});
	}
	this.AutoMove = function() {
		if (self.movewhen=='onclick' || (self.OverCarouselLeft == 0 && self.OverCarouselRight == 0)) {
			if (self.autoMoveTime < 0) {
				var item_width = $("." + self.carouselpanel + " ." + self.carouselitem + ":first").outerWidth()+self.itemmargin;
				var left_indent = parseInt($("." + self.carouselpanel).css('left')) + item_width;
				$("." + self.carouselpanel + ":not(:animated)").animate({'left' : left_indent},self.speed,function(){    
					$("." + self.carouselpanel + " ." + self.carouselitem + ":first").before($("." + self.carouselpanel + " ." + self.carouselitem + ":last")); 
					$("." + self.carouselpanel).css({'left' : parseInt($("." + self.carouselpanel).css('left')) - item_width +'px'});
				});
			} else {
				var item_width = $("." + self.carouselpanel + " ." + self.carouselitem + ":first").outerWidth()+self.itemmargin;
				var left_indent = parseInt($("." + self.carouselpanel).css('left')) - item_width;
				$("." + self.carouselpanel + ":not(:animated)").animate({'left' : left_indent},self.speed,function(){    
					$("." + self.carouselpanel + " ." + self.carouselitem + ":last").after($("." + self.carouselpanel + " ." + self.carouselitem + ":first")); 
					$("." + self.carouselpanel).css({'left' : parseInt($("." + self.carouselpanel).css('left')) + item_width +'px'});
				}); 
			}
		}
		if (self.autoMoveTime > 0) {
			self.autoTimer = setTimeout(self.AutoMove,self.autoMoveTime);
		} else {
			self.autoTimer = setTimeout(self.AutoMove,(self.autoMoveTime * -1));
		}
	}
	this.MoveCarouselLeft = function() {
		if (self.OverCarouselLeft == 1) {
			var item_width = $("." + self.carouselpanel + " ." + self.carouselitem + ":first").outerWidth()+self.itemmargin;
			var left_indent = parseInt($("." + self.carouselpanel).css('left')) + item_width;
			$("." + self.carouselpanel + ":not(:animated)").animate({'left' : left_indent},self.speed,function(){    
				$("." + self.carouselpanel + " ." + self.carouselitem + ":first").before($("." + self.carouselpanel + " ." + self.carouselitem + ":last")); 
				$("." + self.carouselpanel).css({'left' : parseInt($("." + self.carouselpanel).css('left')) - item_width +'px'});
			});
			if (self.movewhen!='onclick') {
				self.curTimer = setTimeout(self.MoveCarouselLeft,1);
			}
			if (self.autoMoveTime > 0) {
				self.autoMoveTime = self.autoMoveTime * -1
			}
		}
	}
				
	this.MoveCarouselRight = function() {
		if (self.OverCarouselRight == 1) {
			var item_width = $("." + self.carouselpanel + " ." + self.carouselitem + ":first").outerWidth()+self.itemmargin;
			var left_indent = parseInt($("." + self.carouselpanel).css('left')) - item_width;
			$("." + self.carouselpanel + ":not(:animated)").animate({'left' : left_indent},self.speed,function(){    
				$("." + self.carouselpanel + " ." + self.carouselitem + ":last").after($("." + self.carouselpanel + " ." + self.carouselitem + ":first")); 
				$("." + self.carouselpanel).css({'left' : parseInt($("." + self.carouselpanel).css('left')) + item_width +'px'});
			}); 
			if (self.movewhen!='onclick') {
				self.curTimer = setTimeout(self.MoveCarouselRight,1);
			}
			if (self.autoMoveTime < 0) {
				self.autoMoveTime = self.autoMoveTime * -1
			}
		}
	}
	var self = this;
	if (this.autoMoveTime != 0) {
		if (this.autoMoveTime > 0) {
			this.autoTimer = setTimeout(this.AutoMove,this.autoMoveTime)
		} else {
			this.autoTimer = setTimeout(this.AutoMove,(this.autoMoveTime * -1))
		}
	}
	
}
