/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
/*********************************************************************************
These are the variables you have to set:
*********************************************************************************/


//The speed of the timeout between each scroll.
//timSpeed1=70
timSpeed1=50
//timSpeed2=70
timSpeed2=50

//The height of the container (change this when it scrolls to much or to little)
contHeight1=60
contHeight2=65

//defPause=100
defPause=100
//pauseTim1=100
pauseTim1=100
//pauseTim2=100
pauseTim2=100

//Variables
var scrollTim1, scrollTim2;
var maxitems1, active1, next1, previous1;
var maxitems2, active2, next2, previous2;

/*********************************************************************************
This is the object constructor function, which applies 
methods and properties to the Cross-browser layer object
*********************************************************************************/
//Getting the top for the top method
function b_gettop() {
//	return (bw.ns4 || bw.ns5)?eval(this.css.top):eval(this.css.pixelTop);
	return (bw.ns4 || bw.ns5)?parseInt(this.css.top):parseInt(this.css.pixelTop);
}
function makeScrollObj(obj,nest){
	nest=(!nest) ? '':'document.'+nest+'.'										
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;		
	this.height=bw.ns4?this.css.document.height:this.el.offsetHeight;
	this.top=b_gettop;
	return this;
}

function pauseScroll1(speed) {
	clearTimeout(scrollTim1)
	if (pauseTim1 > 0) {
		pauseTim1 = pauseTim1 - 1
		scrollTim1=setTimeout("pauseScroll1("+speed+")", timSpeed1)
	}
	else {
		pauseTim1 = defPause
		scrollTim1=setTimeout("autoScroll1("+speed+")",timSpeed1)		
	}
	
}

function pauseScroll2(speed) {
	clearTimeout(scrollTim2)
	if (pauseTim2 > 0) {
		pauseTim2 = pauseTim2 - 1
		scrollTim2=setTimeout("pauseScroll2("+speed+")", timSpeed2)
	}
	else {
		pauseTim2 = defPause
		scrollTim2=setTimeout("autoScroll2("+speed+")",timSpeed2)		
	}

}

function autoScroll1(speed){
	clearTimeout(scrollTim1)
	if(oScroll1[active1].top()>-contHeight1){
		oScroll1[previous1].css.top = oScroll1[previous1].top()-speed
		oScroll1[active1].css.top = oScroll1[active1].top()-speed
		oScroll1[next1].css.top = oScroll1[next1].top()-speed
		scrollTim1=setTimeout("autoScroll1("+speed+")",timSpeed1)
	}
	else {
		oScroll1[previous1].css.top = -contHeight1 * 2
		oScroll1[previous1].css.visibility='hidden'
		oScroll1[active1].css.top = -contHeight1
		oScroll1[next1].css.top = 0
		previous1 = active1
		active1 = next1		
		next1 = (next1+1)>maxitems1?0:(next1+1)
		oScroll1[next1].css.top = oScroll1[active1].top() + contHeight1
		oScroll1[next1].css.visibility='visible'
		scrollTim1=setTimeout("pauseScroll1("+speed+")",timSpeed1)
	}
}

function autoScroll2(speed){
	clearTimeout(scrollTim2)
	if(oScroll2[active2].top()>-contHeight2){
		oScroll2[previous2].css.top = oScroll2[previous2].top()-speed
		oScroll2[active2].css.top = oScroll2[active2].top()-speed
		oScroll2[next2].css.top = oScroll2[next2].top()-speed
		scrollTim2=setTimeout("autoScroll2("+speed+")",timSpeed2)
	}
	else {
		oScroll2[previous2].css.top = -contHeight2 * 2
		oScroll2[previous2].css.visibility='hidden'
		oScroll2[active2].css.top = -contHeight2
		oScroll2[next2].css.top = 0
		previous2 = active2
		active2 = next2		
		next2 = (next2+1)>maxitems2?0:(next2+1)
		oScroll2[next2].css.top = oScroll2[active2].top() + contHeight2
		oScroll2[next2].css.visibility='visible'
		scrollTim2=setTimeout("pauseScroll2("+speed+")",timSpeed2)
	}
}

function prevScroll1(speed) {
	clearTimeout(scrollTim1)
	if(oScroll1[active1].top()<contHeight1){
		oScroll1[previous1].css.top = oScroll1[previous1].top()+speed
		oScroll1[active1].css.top = oScroll1[active1].top()+speed
		oScroll1[next1].css.top = oScroll1[next1].top()+speed
		scrollTim1=setTimeout("prevScroll1("+speed+")",timSpeed1)
	}
	else {
		oScroll1[previous1].css.top = 0
		oScroll1[active1].css.top = contHeight1
		oScroll1[next1].css.top = contHeight1 * 2
		oScroll1[next1].css.visibility = 'hidden'
		next1 = active1
		active1 = previous1
		previous1 = (previous1-1)<0?maxitems1:(previous1-1)
		oScroll1[previous1].css.top = -contHeight1 
		oScroll1[previous1].css.visibility='visible'
		scrollTim1=setTimeout("pauseScroll1("+speed+")",timSpeed1)
	}
}

function prevScroll2(speed) {
	clearTimeout(scrollTim2)
	if(oScroll2[previous2].top()<0){
		oScroll2[previous2].css.top = oScroll2[previous2].top()+speed
		oScroll2[active2].css.top = oScroll2[active2].top()+speed
		oScroll2[next2].css.top = oScroll2[next2].top()+speed
		scrollTim2=setTimeout("prevScroll2("+speed+")",timSpeed2)
	}
	else {
		oScroll2[previous2].css.top = 0
		oScroll2[active2].css.top = contHeight2
		oScroll2[next2].css.top = contHeight2 * 2
		oScroll2[next2].css.visibility = 'hidden'
		next2 = active2
		active2 = previous2
		previous2 = (previous2-1)<0?maxitems2:(previous2-1)
		oScroll2[previous2].css.top = -contHeight2 
		oScroll2[previous2].css.visibility='visible'
		scrollTim2=setTimeout("pauseScroll2("+speed+")",timSpeed2)
	}
}

function nextScroll1(speed) {
}

function nextScroll2(speed) {
}

function previousItem1(){
	clearTimeout(scrollTim1)
	scrollTim1=setTimeout("prevScroll1(2)",timSpeed1)
}

function previousItem2(){
	clearTimeout(scrollTim2)
	scrollTim2=setTimeout("prevScroll2(2)",timSpeed2)
}

function nextItem1() {
	clearTimeout(scrollTim1)
	scrollTim1=setTimeout("autoScroll1(2)",timSpeed1)
}

function nextItem2() {
	clearTimeout(scrollTim2)
	scrollTim2=setTimeout("autoScroll2(2)",timSpeed2)
}

/*********************************************************************************
Initilizes the page, makes a oScroll Array and calls the object constructor.
Here you can add as many scrollObjects as you want
*********************************************************************************/
function scrollInit1(){
	oScroll1=new Array()
	if (news_data.length == 0) {
		news_data[0] = new Array("", "");
		news_data[1] = new Array("", "");
		news_data[2] = new Array("", "");
	}
	else if (news_data.length == 1) {
		news_data[1] = news_data[0];
		news_data[2] = news_data[0];
	}
	else if (news_data.length == 2) {
		news_data[2] = news_data[0];
		news_data[3] = news_data[1];	
	}
	document.writeln("<DIV ID='newsCont'><DIV ID='newsContIn'>")
	for (var i=0;i<news_data.length;i++) {
		document.writeln("<DIV ID='news" + (i+1) + "' CLASS='clScroll'>")
		//document.writeln('<a href="'+news_data[i][0]+'">'+news_data[i][1]+'</a>')
		document.writeln(news_data[i]);
		document.writeln("</DIV>")
	}
	document.writeln("</DIV></DIV>")
	for (var i=0;i<news_data.length;i++) {
		oScroll1[i]=new	 makeScrollObj('news' + (i+1),'newsCont')
	}
	oScroll1[0].css.top = 0
	oScroll1[1].css.top = oScroll1[0].top() + contHeight1
	oScroll1[news_data.length-1].css.top = oScroll1[0].top() - contHeight1
	oScroll1[0].css.visibility='visible'
	oScroll1[1].css.visibility='visible'
	oScroll1[news_data.length-1].css.visibility='visible'
	active1 = 0;
	next1 = 1;
	previous1 = news_data.length-1;
	maxitems1 = news_data.length-1;
	setTimeout("autoScroll1(2)", 3000);
}

function scrollInit2(){
	oScroll2=new Array()
	if (event_data.length == 0) {
		event_data[0] = new Array("", "");

		event_data[1] = new Array("", "");
		event_data[2] = new Array("", "");
	}
	else if (event_data.length == 1) {
		event_data[1] = event_data[0];
		event_data[2] = event_data[0];
	}
	else if (event_data.length == 2) {
		event_data[2] = event_data[0];
		event_data[3] = event_data[1];	
	}
	document.writeln("<DIV ID='eventsCont'><DIV ID='eventsContIn'>")
	for (var i=0;i<event_data.length;i++) {
		document.writeln("<DIV ID='events" + (i+1) + "' CLASS='clScroll'>")
		//document.writeln('<a href="'+event_data[i][0]+'">'+event_data[i][1]+'</a>');
		document.writeln(event_data[i]);
		document.writeln("</DIV>")			
	}
	document.writeln("</DIV></DIV>")
	for (var i=0;i<event_data.length;i++) {
		oScroll2[i]=new	 makeScrollObj('events' + (i+1),'eventsCont')
	}
	oScroll2[0].css.top = 0
	oScroll2[1].css.top = oScroll2[0].top() + contHeight2
	oScroll2[event_data.length-1].css.top = oScroll2[0].top() - contHeight2
	oScroll2[0].css.visibility='visible'
	oScroll2[1].css.visibility='visible'
	oScroll2[event_data.length-1].css.visibility='visible'
	active2 = 0;
	next2 = 1;
	previous2 = event_data.length-1;
	maxitems2 = event_data.length-1;


  setTimeout("autoScroll2(2)", 6500);
	//pauseScroll2(2);
}
