(function(){
/*
*滑动组件：左←→右
*依赖库：
*------jQuery JavaScript Library v1.4.2
*
*使用模板：


.portfolio {
	width:390px;
	height:48px;
	position:absolute;
	top:60px;
	left:533px;
	text-align:left;
}
.portfolio #slider_protfolio {
	width:380px;
	height:48px;
	position:absolute;
	left:6px;
	overflow:hidden;
}
.portfolio #slider_protfolio #container a img {
	margin-right:1px;
}
.portfolio .pre, .portfolio .next {
	top:19px;
	width:6px;
	height:8px;
	cursor:pointer;
}
.portfolio .pre {
	position:absolute;
	left:0px;
}
.portfolio .next {
	position:absolute;
	right:0px;
}



<div class="portfolio">
  <div class="pre" id="slider_pre"></div>
  <div class="next" id="slider_next"></div>
  <div id="slider_protfolio">
    <div id="container"><a href="#"><img src="images/index_17.gif" width="75" height="48" /></a><a href="#"><img src="images/index_19.gif" width="75" height="48" /></a><a href="#"><img src="images/index_19.gif" width="75" height="48" /></a><a href="#"><img src="images/index_21.gif" width="75" height="48" /></a><a href="#"><img src="images/index_25.gif" width="75" height="48" /></a><a href="#"><img src="images/index_17.gif" width="75" height="48" /></a><a href="#"><img src="images/index_19.gif" width="75" height="48" /></a><a href="#"><img src="images/index_19.gif" width="75" height="48" /></a></div>
  </div>
</div>

**/
window.slider=slider;
function slider(fn){
	var config={
		container:"container",
		containerTag:"a",
		pre:"slider_pre",
		next:"slider_next",
		margin:1,
		list:5
	}

	if(fn!=null&&fn.margin!=undefined&&fn.margin!=null){
		config.margin=fn.margin;
	}
	
	if(fn!=null&&fn.list!=undefined&&fn.list!=null){
		config.list=fn.list;
	}
	
	


	var v=0,timer,lock=true,temp=true,j=0;
	var container=$("#"+config.container+"");
	var el=$("#"+config.container+" "+config.containerTag+"");
	var singleWidth=el.outerWidth()+config.margin;
	$("#"+config.container+"").css("width",singleWidth*el.length+"px");
	//步调值计算
	function sliderValue(cureentValue,endValue,steupBegin,action){
		var difference=endValue-cureentValue;
		 
		if(action=="+"){
			if(difference>steupBegin){
			  for(i=steupBegin;i>0;i--){
				  if(difference/i>1){		 
						cureentValue+=i;
					  return cureentValue;
				  }
			  }
			}else{
				cureentValue++;
				return cureentValue;
			}
		}else if(action=="-"){
			difference=cureentValue-endValue;
			if(difference>steupBegin){
			  for(i=steupBegin;i>0;i--){
				  if(difference/i>1){		 
						cureentValue-=i;
					  return cureentValue;
				  }
			  }
			}else{
				cureentValue--;
				return cureentValue;
			}
		}
		
		
		
	}
	//
	function fist(){
		v=0;
		container.css("marginLeft","-"+v+"px");
		
	}
	
	//动作控制
	function action(act){
		var begin=v;
		var end=begin+singleWidth;
		var step=null;
		 if(act=="fist"){
			fist();	
			return;
		 }
		 
		 if(arguments.length>0&&step==null){
			   temp=true;
				var l=arguments[1];
		 		step=l;
				if(j>=l){
					j=0;
					temp=false;
					step=null;
					clearInterval(timer);
					return ;
				}else{
					j++;
				}
			}
		function slider(act){
			 
			
			if(act=="+"){
				v=sliderValue(v,end,10,"+");
			}else{
				v=sliderValue(v,begin-singleWidth,10,"-");;
			}
			//$("#h").text(v);
			if(v>end&&act=="+"){
				v=end;
				clearInterval(timer);
				lock=true;
			 
				if(temp){
				action("+",step);
				}
				 
			};
			
			if(v>(el.length-config.list)*singleWidth){
				v=(el.length-config.list)*singleWidth;
				clearInterval(timer);
				lock=true;
				 
				
			}
			
			if(v<begin-singleWidth){
				v=begin-singleWidth;
				clearInterval(timer);
		  
				lock=true;
				if(temp){
				action("-",step);
				}
			 
			}
			
			if(v<=0){
				v=0;
				clearInterval(timer);
				
			 
				lock=true;
			 
			}
			container.css("marginLeft","-"+v+"px");
		}
		if(lock){
			lock=false;
			 
			timer=setInterval(function(){slider(act)},40);
		 
		}
	
	}
	$("#"+config.pre).bind("mousemove",function(){
										 			temp=true;
													action("-")
															 
											}
											)
	
	$("#"+config.pre).bind("mouseout",function(){
											 	temp=false;
															 
											}
											)
	
	$("#"+config.next).bind("mousemove",function(){
														temp=true;
												   		action("+")
												 
												})
	
	
	$("#"+config.next).bind("mouseout",function(){
											 	temp=false;
															 
											}
											)

return action;
}
 
})();
