
function Scroller(name)
{
	var args = Scroller.arguments;

	// attributes - public
	this.type = 'scroller';
	this.name = name;
	this.width = 156;          if(args.length >= 2 && args[1] != null) this.width = args[1];
	this.height = 156;         if(args.length >= 3 && args[2] != null) this.height = args[2];
	this.velocity = -10;       if(args.length >= 4 && args[3] != null) this.velocity = args[3];
	this.delay = 2000;         if(args.length >= 5 && args[4] != null) this.delay = args[4];
	this.bgcolor = '#ebebeb';  if(args.length >= 6 && args[5] != null) this.bgcolor = args[5];
	this.background = '';      if(args.length >= 7 && args[6] != null) this.background = args[6];
	this.method = 'move';      if(args.length >= 8 && args[7] != null) this.background = args[7];
	this.contents = new Array();

	// attributes - private
	this.browser = 'n6';       if(document.layers) this.browser = 'n4'; if(document.all) this.browser = 'ie';
	this.index = 0;
	this.stopped = true;

	// functions - public
	this.draw = scroller_draw;
	this.start = scroller_start;
	this.set_velocity = scroller_set_velocity;
	this.stop = scroller_stop;
	this.prev = scroller_prev;
	this.next = scroller_next;

	// functions - private
	this.move = scroller_move;	
	this.swap = scroller_swap;	
}

function scroller_draw()
{
	if(this.browser == 'ie' || this.browser == 'n6')
	{
		if(this.browser == 'n6')
		{
			out = "<div id='"+this.type+"_"+this.name+"ref' style='position:relative; ";
			out += "width:"+this.width+"; ";
			out += "height:"+this.height+"; ";
			out += "background-color:"+this.bgcolor+"; ";
			out += "'><img src='images/spacer.gif' width="+this.width+" height="+this.height+" border=0></div>";
			document.write(out)
			ref = document.getElementById(this.type+"_"+this.name+"ref");
		}

		out = "<div id='"+this.type+"_"+this.name+"' style='";
		if(this.browser == 'ie') out += "position:relative; ";
		else out += "position:absolute; left:"+ref.offsetLeft+"; top:"+ref.offsetTop+"; ";
		out += "overflow:hidden; clip:rect(0, "+this.width+", "+this.height+", 0); ";
		out += "width:"+this.width+"; ";
		out += "height:"+this.height+"; ";
		out += "background-color:"+this.bgcolor+"; ";
		out += "background-image:url("+this.background+"); ";
		out += "'>";

		out += "<div id='"+this.type+"_"+this.name+"first' style=' position:absolute; left:0; top:1; width:"+this.width+";'>";
		out += this.contents[0];
		out += "</div>";

		out += "<div id='"+this.type+"_"+this.name+"second' style=' position:absolute; left:0; top:0; width:"+this.width+"; visibility:hidden'>";
		out += this.contents[1];
		out += "</div>";
		
		out += "</div>";

		if(this.browser == 'n6')
		{
			out += "<script>";
			out += "function "+this.type+"_"+this.name+"position(){";
			out += "ref = document.getElementById('"+this.type+"_"+this.name+"ref');";
			out += "obj = document.getElementById('"+this.type+"_"+this.name+"');";
			out += "obj.style.top = ref.offsetTop;";
			out += "obj.style.left = ref.offsetLeft;}";
			out += "setTimeout(\""+this.type+"_"+this.name+"position()\", 3000)";
			out += "</script>";
		}
		
		document.write(out)

		this.layer = document.getElementById(this.type+"_"+this.name);
		this.first = document.getElementById(this.type+"_"+this.name+"first");
		this.second = document.getElementById(this.type+"_"+this.name+"second");
	}
	if(this.browser == 'n4')
	{
		out = "<ilayer id='"+this.type+"_"+this.name+"' ";
		out += "width='"+this.width+"' ";
		out += "height='"+this.height+"' ";
		out += "bgcolor='"+this.bgcolor+"' ";
		out += "background='"+this.background+"' ";
		out += ">";

		out += "<layer id='first' left=0 width='"+this.width+"'>"
		out += this.contents[0]
		out += "</layer>"

		out += "<layer id='second' left=0 top=0 width='"+this.width+"' visibility=hide>"
		out += this.contents[1]
		out += "</layer>"

		out += "</ilayer><br>"
		
		document.write(out)

		this.layer = eval("document."+this.type+"_"+this.name);
		this.first = this.layer.document.first;
		this.second = this.layer.document.second;
	}
}

function scroller_start()
{
	if(this.contents.length > 2) this.index = 2
	if(this.contents.length < 2)
	{
		this.velocity = 0;
		this.method = 'swap';
	}
	this.stopped = false;

	if(this.method == 'swap')
	{
		if(this.browser == 'ie') this.first.style.pixelTop = 0
		if(this.browser == 'n4') this.first.top = 0
		if(this.browser == 'n6') this.first.style.top = 0
		this.swap()
		return
	}
	if(this.browser == 'ie')
	{
		this.first.style.pixelTop = -this.velocity
		this.move(this.name+'.first', this.name+'.second')
		this.second.style.pixelTop = (this.height + 5) * -(this.velocity / Math.abs(this.velocity))
		this.second.style.visibility = 'visible'
	}
	if(this.browser == 'n4')
	{
		this.layer.visibility = 'show'
		this.first.top = -this.velocity
		this.move(this.name+'.first', this.name+'.second')
		this.second.top = (this.height + 5) * -(this.velocity / Math.abs(this.velocity))
		this.second.visibility = 'show'
	}
	if(this.browser == 'n6')
	{
		this.first.style.top = -this.velocity
		this.move(this.name+'.first', this.name+'.second')
		this.second.style.top = (this.height + 5) * -(this.velocity / Math.abs(this.velocity))
		this.second.style.visibility = 'visible'
	}
}

function scroller_move(whichlayer, nextlayer)
{
	motion_delay = 50

	tlayer = eval(whichlayer)
	if(this.browser == 'ie')
	{
		top = tlayer.style.pixelTop;
		height = tlayer.offsetHeight;
	}
	if(this.browser == 'n4')
	{
		var top = tlayer.top;
		var height = tlayer.document.height;
	}
	if(this.browser == 'n6')
	{
		top = parseInt(tlayer.style.top);
		height = tlayer.offsetHeight;
	}
	if((this.velocity < 0 && top > 0 && top <= -this.velocity) || (this.velocity > 0 && top < 0 && top >= -this.velocity))
	{
		if(this.stopped)
		{
			setTimeout(this.name+".move('"+whichlayer+"', '"+nextlayer+"')", motion_delay);
			return;
		}
		if(this.browser == 'ie') tlayer.style.pixelTop = 0;
		if(this.browser == 'n4') tlayer.top = 0;
		if(this.browser == 'n6') tlayer.style.top = 0;
		this.waiting = true;
		setTimeout(this.name+".waiting = false;", this.delay)
		clearTimeout(this.first_event);
		clearTimeout(this.second_event);
		this.first_event = setTimeout(this.name+".move('"+whichlayer+"', '"+nextlayer+"')", this.delay)
		this.second_event = setTimeout(this.name+".move('"+nextlayer+"', '"+whichlayer+"')", this.delay)
	}
	else if((this.velocity < 0 && top >= -height) || (this.velocity > 0 && top < this.height))
	{
		if(this.browser == 'ie') tlayer.style.pixelTop = tlayer.style.pixelTop + this.velocity;
		if(this.browser == 'n4') tlayer.top = tlayer.top + this.velocity;
		if(this.browser == 'n6') tlayer.style.top = parseInt(tlayer.style.top) + this.velocity;
		setTimeout(this.name+".move('"+whichlayer+"', '"+nextlayer+"')", motion_delay)
	}
	else
	{
		if(this.index > this.contents.length - 1) this.index = 0
		if(this.index < 0) this.index = 1
		if(this.browser == 'ie') 
		{
			tlayer.style.pixelTop = this.height * -(this.velocity / Math.abs(this.velocity))
			tlayer.innerHTML = this.contents[this.index]
		}
		if(this.browser == 'n4') 
		{
			tlayer.top = this.height * -(this.velocity / Math.abs(this.velocity))
			tlayer.document.write(this.contents[this.index])
			tlayer.document.close()
		}
		if(this.browser == 'n6') 
		{
			tlayer.style.top = this.height * -(this.velocity / Math.abs(this.velocity))
			tlayer.innerHTML = this.contents[this.index];
		}
		if(this.velocity < 0)
		{
			if(this.index >= this.contents.length - 1) this.index = 0
			else this.index++
		}
		else
		{
			if(this.index <= 0) this.index = this.contents.length - 1
			else this.index--
		}
	}
}

function scroller_swap()
{
	if(this.browser == 'ie' || this.browser == 'n6') this.first.innerHTML = this.contents[this.index]
	if(this.browser == 'n4') 
	{
		this.first.document.write(this.contents[this.index])
		this.first.document.close()
	}
	if(this.velocity < 0)
	{
		if(this.index == this.contents.length - 1) this.index = 0
		else this.index++
	}
	else if(this.velocity > 0)
	{
		if(this.index == 0) this.index = this.contents.length - 1
		else this.index--
	}
	if(!this.stopped) setTimeout(this.name+".swap()", this.delay);
}

function scroller_next()
{
	if(this.index == this.contents.length - 1) this.index = 0
	else this.index++
	if(this.browser == 'ie' || this.browser == 'n6') this.first.innerHTML = this.contents[this.index]
	if(this.browser == 'n4') 
	{
		this.first.document.write(this.contents[this.index])
		this.first.document.close()
	}
}

function scroller_prev()
{
	if(this.index == 0) this.index = this.contents.length - 1
	else this.index--
	if(this.browser == 'ie' || this.browser == 'n6') this.first.innerHTML = this.contents[this.index]
	if(this.browser == 'n4') 
	{
		this.first.document.write(this.contents[this.index])
		this.first.document.close()
	}
}

function scroller_set_velocity(velocity)
{
	if(velocity == 0)
	{
		this.stop();
		return;
	}
	if(this.stopped)
	{
		this.stopped = false;
	}

	if(this.waiting)
	{
		clearTimeout(this.first_event);
		clearTimeout(this.second_event);
		this.waiting = false;
		this.move('this.first', 'this.second');
		this.move('this.second', 'this.first');
	}

	if(this.browser == 'ie')
	{
		topf = this.first.style.pixelTop;
		tops = this.second.style.pixelTop;
		heightf = this.first.offsetHeight;
		heights = this.first.offsetHeight;
	}
	if(this.browser == 'n4')
	{
		var topf = this.first.top;
		var tops = this.second.top;
		var heightf = this.first.document.height;
		var heights = this.second.document.height;
	}
	if(this.browser == 'n6')
	{
		topf = parseInt(this.first.style.top);
		tops = parseInt(this.second.style.top);
		heightf = this.first.offsetHeight;
		heights = this.first.offsetHeight;
	}

	if((velocity > 0 && ((topf < 0 && topf > -heightf) || (tops < 0 && tops > -heights))) ||
	   (velocity < 0 && ((tops > 0 && tops < this.height) || (topf > 0 && topf < this.height))))
	{
		if(this.velocity < 0 && velocity > 0)
		{
			this.index -= 3;
			if(this.index < 0) this.index = this.contents.length + this.index;
		}
		if(this.velocity > 0 && velocity < 0)
		{
			this.index += 3;
			if(this.index >= this.contents.length) this.index = this.contents.length - this.index;
		}
		this.velocity = velocity;
	}
	if(this.velocity != velocity) setTimeout(this.name+".set_velocity("+velocity+")", 51);
}

function scroller_stop()
{
	this.stopped = true;
}