function applyIf(C,A){
  if(C&&A&&typeof A=="object")  {
    for(var B in A){
      if(!YAHOO.lang.hasOwnProperty(C,B)){
        C[B]=A[B]
      }
    }
  }
  return C
}
function apply(C,A){
  if(C&&A&&typeof A=="object"){
    for(var B in A){
      C[B]=A[B]
    }
  }
  return C
}
var hotRoll = new Object();


  hotRoll.defConfig={delay:2,speed:20,startDelay:2,direction:"vertical",disableAutoPlay:false,distance:"auto",scrollItemCount:1};
  hotRoll.roll=function(container,config)
  {
    container=$(container);
    config=applyIf(config||{},hotRoll.defConfig);
    var step=2;
    if(config.speed<20)
    {step=5}
    if(config.lineHeight){config.distance=config.lineHeight}
    var scrollTimeId=null,startTimeId=null,startDelayTimeId=null;
    var isHorizontal=(config.direction.toLowerCase()=="horizontal")||(config.direction.toLowerCase()=="h");
    var handle={};
    handle._distance=0;
    handle.scrollable=true;
    handle.distance=config.distance;
    handle._distance=0;
    handle.suspend=false;
    handle.paused=false;
    var _onScrollEvent=new YAHOO.util.CustomEvent("_onScroll",handle,false,YAHOO.util.CustomEvent.FLAT);
    _onScrollEvent.subscribe(
      function(){
        var curLi=container.getElementsByTagName("li")[0];
        if(!curLi){this.scrollable=false;return}
        this.distance=(config.distance=="auto")?curLi[isHorizontal?"offsetWidth":"offsetHeight"]:config.distance;
        with(container)
        {
          if(isHorizontal)
          {
            this.scrollable=(scrollWidth-scrollLeft-offsetWidth)>=this.distance
          }else{
            this.scrollable=(scrollHeight-scrollTop-offsetHeight)>=this.distance
          }
        }
      }
    );
    var onScrollEvent=new YAHOO.util.CustomEvent("onScroll",handle,false,YAHOO.util.CustomEvent.FLAT);
    if(config.onScroll){
      onScrollEvent.subscribe(config.onScroll)
    }else{
      onScrollEvent.subscribe(
        function(){
          for(var i=0;i<config.scrollItemCount;i++){
            container.appendChild(container.getElementsByTagName("li")[0])
          }
          container[isHorizontal?"scrollLeft":"scrollTop"]=0
        }
      )
    }
    var scroll=function(){
      if(handle.suspend)
      {return}
      handle._distance+=step;
      var _d;
      if((_d=handle._distance%handle.distance)<step){
        container[isHorizontal?"scrollLeft":"scrollTop"]+=(step-_d);
        clearInterval(scrollTimeId);
        onScrollEvent.fire();
        _onScrollEvent.fire();
        startTimeId=null;
        if(handle.scrollable&&!handle.paused)
        {handle.play()}
      }else{
        container[isHorizontal?"scrollLeft":"scrollTop"]+=step
      }
    };
    var start=function(){
      if(handle.paused){return}
      handle._distance=0;
      scrollTimeId=setInterval(scroll,config.speed)
    };
    YAHOO.util.Event.on(container,"mouseover",function(){handle.suspend=true});
    YAHOO.util.Event.on(container,"mouseout",function(){handle.suspend=false});
    apply(handle,{
      subscribeOnScroll:function(func,override){
        if(override===true&&onScrollEvent.subscribers.length>0){
          onScrollEvent.unsubscribeAll()
        }
        onScrollEvent.subscribe(func)
      },pause:function(){
        this.paused=true;
        clearTimeout(startTimeId);
        startTimeId=null
      },play:function(){
        this.paused=false;
        if(startDelayTimeId){
          clearTimeout(startDelayTimeId)
        }
        if(!startTimeId){
          startTimeId=setTimeout(start,config.delay*1000)
        }
      }
    });
    handle.onScroll=handle.subscribeOnScroll;
    _onScrollEvent.fire();
    if(!config.disableAutoPlay){
      startDelayTimeId=setTimeout(function(){
        handle.play()
      },config.startDelay*1000)
    }
    return handle
  }


