
var $ = function (id) {
     return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
   create: function() {
     return function() {
       this.initialize.apply(this, arguments);
     }
   }
}
Object.extend = function(destination, source) {
for (var property in source) {
   destination[property] = source[property];
}
return destination;
}
function addEventHandler(oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
   oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
   oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
   oTarget["on" + sEventType] = fnHandler;
}
};

var Scroller = Class.create();
Scroller.prototype = {
   initialize: function(idScroller, idScrollMid, options) {
     var oScroll = this, oScroller = $(idScroller), oScrollMid = $(idScrollMid);

this.SetOptions(options);
this.Scroller = oScroller; 
this.Speed = this.options.Speed;
this.timer = null;
this.Pause = 0;


this.heightScroller = parseInt(oScroller.style.height) || oScroller.offsetHeight;
this.heightList = oScrollMid.offsetHeight;


this.widthScroller = parseInt(oScroller.style.width) || oScroller.offsetWidth;
this.widthList = oScrollMid.offsetWidth;


oScroller.style.overflow = "hidden";
oScrollMid.appendChild(oScrollMid.cloneNode(true));


switch (this.options.Side.toLowerCase()) {
   case "right" :
   if(this.widthList <= this.widthScroller) return;
   this.Scroll = this.ScrollLeftRight;
   this.side = -1;
   break;
   case "left" :
   if(this.widthList <= this.widthScroller) return;
   this.Scroll = this.ScrollLeftRight;
   this.side = 1;
   break;
   case "down" :
   if(this.heightList <= this.heightScroller) return;
   this.Scroll = this.ScrollUpDown;
   this.side = -1;
   break;
   case "up" :
   default :
   if(this.heightList <= this.heightScroller) return;
   this.Scroll = this.ScrollUpDown;
   this.side = 1;
}

addEventHandler(oScroller, "mouseover", function() { oScroll.Stop(); });
addEventHandler(oScroller, "mouseout", function() { oScroll.Start(); });

this.Start();
   },
  
   SetOptions: function(options) {
     this.options = {
   Step:   2,
   Speed:  10,
   Side:   "up",
   PauseHeight: 0,
   PauseWidth: 0,
   PauseStep: 1500
     };
     Object.extend(this.options, options || {});
   }, 

   ScrollUpDown: function() {
this.Scroller.scrollTop = this.GetScroll(this.Scroller.scrollTop, this.heightScroller, this.heightList, this.options.PauseHeight);

var oScroll = this;
this.timer = window.setTimeout(function(){ oScroll.Scroll(); }, this.Speed);
   },
   
   ScrollLeftRight: function() {

this.Scroller.scrollLeft = this.GetScroll(this.Scroller.scrollLeft, this.widthScroller, this.widthList, this.options.PauseWidth);

var oScroll = this;
this.timer = window.setTimeout(function(){ oScroll.Scroll(); }, this.Speed);
   },

   GetScroll: function(iScroll, iScroller, iList, iPause) {
var oScroll = this, iStep = this.options.Step * this.side;

if(this.side > 0){
   if(iScroll >= (iList * 2 - iScroller)){ iScroll -= iList; }
} else {
   if(iScroll <= 0){ iScroll += iList; }
}

this.Speed = this.options.Speed;
if(iPause > 0){
   if(Math.abs(this.Pause) >= iPause){
   this.Speed = this.options.PauseStep; this.Pause = iStep = 0;
   } else {
   this.Pause += iStep;
   }
}

return (iScroll + iStep);
   },

   Start: function() {
this.Scroll();
   },
 
   Stop: function() {
clearTimeout(this.timer);
   }
};
window.onload = function(){
new Scroller("scr", "scro",{ Side:"up", PauseHeight:60 });

}
