﻿/********************************************************************************
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=60

//The height of the container (change this when it scrolls to much or to little)
contHeight1=180

defPause=100
pauseTim1=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 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 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 nextScroll1(speed) {
}

function previousItem1(){
	clearTimeout(scrollTim1)
	scrollTim1=setTimeout("prevScroll1(2)",timSpeed1)
}

function nextItem1() {
	clearTimeout(scrollTim1)
	scrollTim1=setTimeout("autoScroll1(2)",timSpeed1)
}

/*********************************************************************************
Initilizes the page, makes a oScroll Array and calls the object constructor.
Here you can add as many scrollObjects as you want
*********************************************************************************/
function scrollInit(){
	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'>")
	for (var i=0;i<news_data.length;i++) {
		document.writeln("<DIV ID='news" + (i+1) + "' CLASS='clScroll'>")
		
		document.writeln('<font color=grey>' + news_data[i][1]+'</font><br>')
		document.writeln('<b>'+ news_data[i][2]+'</b><br>')
		document.writeln('<br>')
		if(news_data[i][0]=="")
		{
			document.writeln('<font color=#B5E9D5>' + news_data[i][3] + '</font>')
		}
		else
		{
			document.writeln('<a href="'+news_data[i][0]+'" target=_blank>'+news_data[i][3]+'</a>')
		}
		
		document.writeln("</DIV>")
	}
	document.writeln("</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)", 1000)	
}
