
var $j = jQuery.noConflict();

Scrollable = function (container, child){
  this.container = container;
  this.child = child;
  this.container_height = container.height();
  this.child_height = child.height();
//  this.div_pos = 0;
  this.div_pos = -this.container_height
  this.scroll_increment = 1;
  this.scroll_delay = 20;

  this.container.css('overflow','hidden');
  this.container.css('position','relative');
  this.child.css('position','relative');

//    this.container.css('border','1px solid red');
//    this.container.height('200px');

  this.StartScroller();

  var Obj = this;

  this.container.hover(  function() { Obj.StopScroller(); },
                         function() { Obj.StartScroller(); } );
}

Scrollable.prototype.ChildScroller = function () {
//    this.div_pos = ( this.div_pos + this.scroll_increment ) % this.container_height;
  this.div_pos = ( this.div_pos + this.scroll_increment );
//  if (this.div_pos >= this.container_height) {
  if (this.div_pos >= this.child_height) {
//    this.div_pos = 0;
  this.div_pos = -this.container_height
    this.child.fadeIn("slow");
  }
  this.child.css('top',-this.div_pos);
}

Scrollable.prototype.StopScroller = function () {
  clearInterval(this.scroll_interval);
}

Scrollable.prototype.StartScroller = function () {
  var Obj = this;
  this.scroll_interval = setInterval(function() {Obj.ChildScroller();},this.scroll_delay); //time in milliseconds
}

$j(document).ready(function(){

  // Do something with jQuery
  $j(".scrollable").each(function(i){
    var O = new Scrollable($j(this),$j(this).children());
  });

/*
var x=$(document).getElementsByTagName('div');
for(i=0;i<x.length;i++)
  {
  var elementDIV=x.item(i)
  if (elementDIV.className == "scrollable" ){
      var O = new Scrollable(elementDIV,elementDIV.childNodes[0]);  
  }
  }
  */
  
});


