// JavaScript Document
jQuery.fn.rollup=function(option){
	var setting={wo:Object,so:Object,stopBorder:false,speed:50,wait:100,quick:5,oldHeight:0,timer:null,flag:-1,ispause:false};
	if(option){$.extend(setting,option);}
	this.hover(function(){
					clearTimeout(setting.timmer);
					setting.timmer=null;
					setting.ispause=true;
					setting.timmer=setTimeout(function(){that.roll(1);},setting.speed);
				}
				,function(){
					clearTimeout(setting.timmer);
					setting.timmer=null;
					setting.ispause=false;
					setting.timmer=setTimeout(function(){that.roll();},setting.wait);
				});
	this.bind("mousemove",function(e){setting.flag=e.pageY-setting.wo.offset().top>setting.wo.height()/2?-1:1;});	
	setting.oldHeight=$(this).outerHeight();	
	$(this).append($(this).html());
	var that = this;	
	this.roll=function(ext){		
		if(ext||!setting.ispause){
			if(setting.timmer){
				clearTimeout(setting.timmer);
				setting.timmer=null;
			}			
			var t=getNum($(that).css('top'));			
			var d=new Date();			
				
			if(t>=setting.oldHeight*-1){
				if(ext&&setting.stopBorder){
					var h=$(setting.so).outerHeight();
					h += getNum($(setting.so).css("margin-top"))*1;
					h += getNum($(setting.so).css("margin-bottom"))*1;					
					if(t%h!=0){
						$(that).css("top",t-0+1*setting.flag+"px");
						setting.timmer=setTimeout(function(){that.roll(1);},setting.quick);
					}
				}else{
					$(that).css("top",t-1+"px");
					setting.timmer=setTimeout(function(){that.roll();},setting.speed);
				}
			}else{
				$(that).css("top","0px");
				that.roll();
			}
		}else{
			setting.timmer=setTimeout(function(){that.roll();},setting.speed);			
			return false;
		}
		function getNum(str){
			var tmp = str.replace(/px|PX|auto|AUTO/g,"");			
			return tmp==""?0:tmp;
		}
	}	
	this.roll();
	
}