// JavaScript Document

function $(v) { return document.getElementById(v) }
String.prototype.isEmpty = function() { return this.length==0 }
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"") }

var Marquee = {
	p1:0,p2:0,w:0,l:0,lw:0,t:0,f:0,id:'',
	pos:0,scrollY:0,scrollID:'',
	scrollamount:1,scrolldelay:20,
	run: function() {
		if(this.l<=-this.lw) {this.l=this.l+this.lw; var p=this.p1;this.p1=this.p2;this.p2=p}
		this.l-=this.scrollamount;
		this.p1.style.left=this.l+'px';
		if(this.l+this.lw<this.w) this.p2.style.left=(this.l+this.lw)+'px';
	},
	create: function(id) {
		this.id=id;
		$(id+'d').innerHTML=$(id+'c').innerHTML;
		if( typeof(window.onload)=='function' ) {
			this.f = window.onload;
			window.onload = function() { Marquee.f(); Marquee.init(Marquee.id) }
		} else window.onload = function() { Marquee.init(Marquee.id) }
	},
	init: function(id) {
		this.w=$(id+'contener').offsetWidth;
		this.p1=$(id+'1'); this.p2=$(id+'2');
		this.lw=$(id+'c').offsetWidth; 
		this.p2.style.top=(-this.p1.offsetHeight)+'px';
		this.p2.style.left=this.w; this.l=0;
		this.p2.onmouseover=this.p1.onmouseover=function() { Marquee.stop() }
		this.p2.onmouseout=this.p1.onmouseout=function() { Marquee.start() }
		if( !this.scrollID.isEmpty() ) {
			this.pos=$(this.scrollID).offsetTop;
			this.scroll();
			window.onscroll=function() { Marquee.scroll() }
		} else this.start();
	},
	scroll: function() {
		var sY;
		if(Browser.IE) sY=document.body.scrollTop+document.body.clientHeight;
		else sY=window.pageYOffset+window.innerHeight;
		if(sY==this.scrollY) return;
		if(sY>=this.pos) this.start();
		else this.stop();
		this.scrollY=sY;
	},
	stop: function() { clearInterval(this.t); this.t=0 },
	start: function() { if(this.t==0) this.t=setInterval("Marquee.run()",this.scrolldelay) }
}

