
jQuery.fn.Scroll = function(params){
	var p = params || {
		next:"NextBtn", 
		prev:"PrevBtn", 
		picdiv:"wDiv", 
		child:"div",		
		time:3000,		
		auto:true,		
		scollNum:1,		
		showNum:3,      
		position:"right" 
	}; 
	var _btnNext = $("#"+ p.next);  
	var _btnPrev = $("#"+ p.prev); 
	var _imgpicdiv = $("#"+ p.picdiv); 
	var _child = p.child;			
	var _time=p.time; 				
	var _auto = p.auto;				
	var _scollNum=p.scollNum;			
	var _position=p.position;		
	var _showNum=p.showNum;         
	var _scollWidth=_imgpicdiv.find(_child).width(); 
	var _scollHeight=_imgpicdiv.find(_child).height(); 
	var _imgCount=_imgpicdiv.find(_child).length;   
	//alert($(this).css('height')); 
	if(_position.toLowerCase()=="left"||_position.toLowerCase()=="right")
	{
	    $(this).css({"height":_scollHeight,"width":_scollWidth*_showNum,"clear":"both", "overflow":"hidden", "margin":"0px"});
	    _imgpicdiv.css('width',_scollWidth*_imgCount); 
	}
	else
	{
	    $(this).css({"height":_scollHeight*_showNum,"width":_scollWidth,"clear":"both", "overflow":"hidden", "margin":"0px"});
	    _imgpicdiv.css('height',_scollHeight*_imgCount); 
	}
	var _itv; 
	var turnLeft = function(){
		_btnPrev.unbind("click",turnLeft);
	if(_auto) autoStop(); //单击的时候先停止自动播放
		_imgpicdiv.animate( {marginLeft:-(_scollWidth*_scollNum)}, 'fast', function(){  
			_imgpicdiv.find(_child+":lt("+_scollNum+")").appendTo( _imgpicdiv ); 
			_imgpicdiv.css("marginLeft",0);
			_btnPrev.bind("click",turnLeft);
			if(_auto) autoPlay();
		});
	};
	var turnRight = function(){
		_btnNext.unbind("click",turnRight);
		if(_auto) autoStop();
		_imgpicdiv.find(_child+":gt("+(_imgCount-_scollNum-1)+")").clone().show().prependTo( _imgpicdiv );
		_imgpicdiv.css("marginLeft",-(_scollWidth*_scollNum));
		_imgpicdiv.animate( {marginLeft:0},'fast', function(){
			_imgpicdiv.find(_child+":gt("+(_imgCount-1)+")").remove();
			_btnNext.bind("click",turnRight);
			if(_auto) autoPlay(); 
		});
	};
	var turnTop=function(){
	_btnNext.unbind("click",turnTop);
		if(_auto) autoStop();
			_imgpicdiv.animate( {marginTop:-(_scollHeight*_scollNum)}, 'fast', function(){  
			_imgpicdiv.find(_child+":lt("+_scollNum+")").appendTo( _imgpicdiv ); 
			_imgpicdiv.css("marginTop",0);
			_btnPrev.bind("click",turnTop);
			if(_auto) autoPlay();
		});
	};
	var turnBottom=function(){
	_btnPrev.unbind("click",turnBottom);
		if(_auto) autoStop(); 
		_imgpicdiv.find(_child+":gt("+(_imgCount-_scollNum-1)+")").clone().show().prependTo( _imgpicdiv );
		_imgpicdiv.css("marginTop",-(_scollHeight*_scollNum));
		_imgpicdiv.animate( {marginTop:0},'fast', function(){
			_imgpicdiv.find(_child+":gt("+(_imgCount-1)+")").remove();
			_btnNext.bind("click",turnBottom);
			if(_auto) autoPlay(); 
		});
	};
	if(_position.toLowerCase()=="left"||_position.toLowerCase()=="right")
	{
		_btnNext.css("cursor","hand").click( turnRight );
		_btnPrev.css("cursor","hand").click( turnLeft );
	}
	else
	{
		_btnNext.css("cursor","hand").click( turnBottom );
		_btnPrev.css("cursor","hand").click( turnTop );
	}
	var autoPlay = function(){

		if(_position.toLowerCase()=="top")
		{
			_itv = window.setTimeout(turnTop,_time);
		}
		else if(_position.toLowerCase()=="left")
		{
			_itv = window.setTimeout(turnLeft,_time);
		}
		else if(_position.toLowerCase()=="bottom")
		{
			_itv = window.setTimeout(turnBottom,_time);
		}
		else
		{
			_itv = window.setTimeout(turnRight,_time);
		}
	};
	var autoStop = function(){

		window.clearTimeout(_itv);

	};
	if(_auto)	autoPlay();

	_imgpicdiv.find(_child).mouseover(function(){
	_auto=false;
	    autoStop();
	}).mouseout(function(){
		_auto=true;
	  autoPlay();
	});
	



	jQuery('#LeftBotton').mouseover(function(){
	_auto=false;
	    autoStop();
	}).mouseout(function(){
	_auto=true;
   autoPlay();
	});
		jQuery('#RightBotton').mouseover(function(){
			_auto=false;
	    autoStop();
	}).mouseout(function(){
		_auto=true;
    autoPlay();
	});
	
		
};
