var sliderObj;
jQuery.fn.extend({
	moveSlider:function(setting){
		
		var self = this;
		
		this.scrollarea = $(this).find(".scroll_motion")[0];
		this.scrollbar = $(this).find(".scroll_bar")[0];
		this.motioninline = $(this).find(".motion_inline")[0];
		this.motioninlink = $(this).find(".motion_link_block")[0];
		this.motionblock = $(this).find(".motion_block")[0];
		this.motiondv = $(this).find(".motion_dv")[0];

		this.movenum = parseInt(setting.movenum);
		this.movenumber = parseInt(setting.num);
		this.listw = parseInt(setting.w);
		this.listh = parseInt(setting.h);
		
		this.direction = setting.direction;
		this.showpage = setting.showpage;
		this.speed = parseInt(setting.speed);
		
		this.list = $($(this).find(".motion_dv")[0]).find("li");
		this.listnum = parseInt(this.list.length);
		
		
		
		if(self.direction == "vertical"){
			$(this.motioninlink).css("width",setting.w+"px");
			$(this.motioninline).css("width",setting.w+"px");
			$(this.motionblock).css("width",setting.w+"px");
			$(this.motionblock).css("height",setting.h*setting.num+"px");
			$(this.motiondv).css("width",setting.w+"px");
			$(this.motiondv).css("height",setting.h*this.listnum+"px");
		}else{
			$(this.motioninlink).css("width",setting.w*setting.num+"px");
			$(this.motioninline).css("width",setting.w*setting.num+"px");
			$(this.motionblock).css("width",setting.w*setting.num+"px");
			$(this.motionblock).css("height",setting.h+"px");
			$(this.motiondv).css("width",setting.w*this.listnum+"px");
			$(this.motiondv).css("height",setting.h+"px");
		}
		
		var temp_num = (this.listnum-setting.num)*setting.w;
		
		this.list.each(function(){
			$(this).css("width",setting.w+"px");
			$(this).css("height",setting.h+"px");
			if(self.direction == "vertical"){
				$(this).css("float","none");
			}
		});
		
		this.enterpagenum = function(){
			if(self.movenumber > 1){
				self.beginpage = self.defpage+1;
				self.endpage = self.defpage+self.movenumber;
				if(self.endpage > self.listnum){
					self.endpage = self.listnum;
				}
				$(self.page_num_area).html(self.beginpage+"-"+self.endpage+" of "+self.listnum);
				var right_px = -1*self.defpage*self.listw+"px";
			}else{
				self.beginpage = self.defpage+1;
				$(self.page_num_area).html(self.beginpage+" of "+self.listnum);
			};
			var right_px = -1*self.defpage*self.listw+"px";
			$(self.motiondv).animate({
				"left": right_px
				},self.speed,"linear"
			);
			return "ture";
		}
		
		this.enterpagenum_v = function(){
			if(self.movenumber > 1){
				self.beginpage = self.defpage+1;
				self.endpage = self.defpage+self.movenumber;
				if(self.endpage > self.listnum){
					self.endpage = self.listnum;
				}
				$(self.page_num_area).html(self.beginpage+"-"+self.endpage+" of "+self.listnum);
				var top_px = -1*self.defpage*self.listh+"px";
			}else{
				self.beginpage = self.defpage+1;
				$(self.page_num_area).html(self.beginpage+" of "+self.listnum);
			};
			var top_px = -1*self.defpage*self.listh+"px";
			$(self.motiondv).animate({
				"top": top_px
				},self.speed,"linear"
			);
			return "ture";
		}

		this.prelink = $(this).find(".go_left_button")[0];
		this.nextlink = $(this).find(".go_right_button")[0];
		this.page_num_area = $(this).find(".page_num_area")[0];
		this.defpage = 0;
		
		if(self.showpage == "0"){
			$(self.page_num_area).css("display","none");
		}
		
		if(self.direction == "vertical"){
			self.enterpagenum_v();
		}else{
			self.enterpagenum();
		}
		
		
		$(this.prelink).bind("click",function(){
			if(self.defpage != 0){
				self.defpage-=self.movenum;
				if(self.defpage < 0){
					self.defpage = 0;
				}
				if(self.direction == "vertical"){
					var s = self.enterpagenum_v();
				}else{
					var s = self.enterpagenum();
				}
			}
		});
		
		$(this.nextlink).bind("click",function(){
			if(self.defpage != self.listnum-self.movenumber){
				self.defpage+=self.movenum;
				if(self.defpage > self.listnum-self.movenum){
					self.defpage = self.listnum-self.movenum;
				}
				if(self.direction == "vertical"){
					var s = self.enterpagenum_v();
				}else{
					var s = self.enterpagenum();
				}
			}
		});
	}
});