﻿Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.call(object, arguments);
  }
}
function Scroll(marqueesId, step){
	this.oMarquees = document.getElementById(marqueesId);
	this.step = step;
	this.stopScroll = false;
	this.preTop = 0;
	this.marqueesHeight = 0;
	this.oTempLayer = null;
	
	this.initialize();
};
Scroll.prototype.initialize = function(){
	with(this.oMarquees){
		this.marqueesHeight = offsetHeight;
		style.height = this.marqueesHeight;
		style.overflowX = "visible";
		style.overflowY = "hidden";
		noWrap = true;
		onmouseover = this.switchScroll.bind(this);
		onmouseout = this.switchScroll.bind(this);
	}
	this.oTempLayer = document.createElement("div");
	this.oMarquees.parentElement.appendChild(this.oTempLayer);
	with(this.oTempLayer){
		id = "tempLayer";
		style.position = "absolute";
		style.left = "0px";
		style.zIndex = "1";
		style.visibility = "hidden";
	}
	this.oTempLayer.innerHTML = "";
	while(this.oTempLayer.offsetHeight < this.marqueesHeight){
		this.oTempLayer.innerHTML += this.oMarquees.innerHTML + "<div style='height: 10px;'></div>";
	}
	this.oMarquees.innerHTML = this.oTempLayer.innerHTML + this.oTempLayer.innerHTML;
	this.setupScroll();
};
Scroll.prototype.switchScroll = function(){
    this.stopScroll = !this.stopScroll;
};
Scroll.prototype.setupScroll = function(){
    setInterval(this.scrolling.bind(this), this.step);
};
Scroll.prototype.scrolling = function(){
	if(this.stopScroll == true) return;
	this.preTop = this.oMarquees.scrollTop;
	this.oMarquees.scrollTop += 1;
	if(this.preTop == this.oMarquees.scrollTop){
		this.oMarquees.scrollTop = this.oTempLayer.offsetHeight - this.marqueesHeight;
		this.oMarquees.scrollTop += 1;
	}
};
function addOnload(func){
   var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
    	window.onload = func;
	} 
	else 
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}
