
var NewsScroller = Class.create({
  scrolling: true,
  timer: null,
  interval: 40,
  
  initialize: function(div)
  {
    this.container = Element.extend($(div));
    this.content = this.container.innerHTML;

    this.container.style.overflow = 'hidden';
    this.height = this.container.getHeight();

    this.addContent();

    this.addEvents();

    this.startScroll();

    //console.log(this);
    //console.log(this.container.scrollHeight)
  },

  startScroll: function()
  {
    this.timer = setInterval((function(){this.performScroll();}).bind(this), this.interval);
  },

  performScroll: function()
  {
    if (!this.scrolling) return;
    this.container.scrollTop += 1;
    //console.log(this.container.scrollTop + ' - ' + (this.container.scrollHeight - this.height));
    if(this.container.scrollTop >= (this.container.scrollHeight - this.height) )
    {
      this.addContent();
    }
  },

  addEvents: function()
  {
    //this.container.observe('mouseout', (function(e){ this.addContent(); }).bind(this));
    this.container.observe('mouseout', this.mouseOut.bind(this));
    this.container.observe('mouseover', this.mouseOver.bind(this));
  },

  mouseOut: function()
  {
    this.scrolling = true;
  },
  mouseOver: function()
  {
    this.scrolling = false;
  },

  addContent: function()
  {
    this.container.insert(this.content);
    this.repeatHeight += this.height;
  }


});

//var repeatHeight = $('highlights').scrollHeight;
//
//$('highlights').innerHTML = $('highlights').innerHTML + $('highlights').innerHTML + $('highlights').innerHTML + $('highlights').innerHTML;
//
//var stopScroll = 0;
//var x;
//function scrollMe()
//{
//	clearTimeout(x)
//	if(stopScroll==1) {
//		return
//	}
//	$('highlights').scrollTop = $('highlights').scrollTop + 1;
//
//	//alert($('highlights').scrollTop + '>=' + repeatHeight);
//
//	if($('highlights').scrollTop >= (repeatHeight - 20) )
//  {
//    //we have hit the wrap point
//	  $('highlights').innerHTML = $('highlights').innerHTML + $('highlights').innerHTML;
//	  repeatHeight = parseInt(repeatHeight) * 2;
//	}
//	x = setTimeout("scrollMe()",40)
//
//}
//x = setTimeout("scrollMe()",1000)
//// start scrolling after one second

