// CREDITS:
// Cursor Scroller
// by Urs Dudli and Peter Gehrig 
// Copyright (c) 2001 Peter Gehrig and Urs Dudli. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.24fun.com.
// info@24fun.com
// 2/15/2001

// IMPORTANT: 
// If you add this script to a script-library or script-archive 
// you have to add a link to http://www.24fun.com on the webpage 
// where the scrips will be running.

// CONFIGURATION:
// Go to www.24fun.com, open category 'text' and download 
// the full-version of this script as ZIP-file containing
// step-by-step instructions and copy-and-paste installation for non-programmers.

var starttime
var nowtime
var stoptime
var timetohidescroller=false
var textmovedtoleft=0

var x=0
var y=0
var scrollerleft
var scrollertop
var screenwidth
var clipleft,clipright,cliptop,clipbottom
var i_message=0
var timer
var textwidth
var textcontent=""
var bgcontent=""
if (fntweight==1) {fntweight="700"}
else {fntweight="100"}

function init() {
	getbgcontent()
	gettextcontent()
	startnewtime()
    if (document.all) {
		scrollertop=y
		scrollerleft=x
		text.innerHTML=textcontent
		bgscroller.innerHTML=bgcontent
		textwidth=text.offsetWidth
		document.all.bgscroller.style.posTop=scrollertop-cellpad
        document.all.bgscroller.style.posLeft=scrollerleft-cellpad
		document.all.text.style.posTop=scrollertop
        document.all.text.style.posLeft=scrollerleft+scrollerwidth
		clipleft=0
		clipright=0
		cliptop=0
		clipbottom=scrollerheight
		document.all.text.style.clip ="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
       scrolltext()
    }
	if (document.layers) {
		scrollertop=y
		scrollerleft=x
		document.text.document.write(textcontent)
		document.text.document.close()
		document.bgscroller.document.write(bgcontent)
		document.bgscroller.document.close()
		textwidth=document.text.document.width
		document.bgscroller.top=scrollertop-cellpad
        document.bgscroller.left=scrollerleft-cellpad
		document.text.top=scrollertop
		document.text.left=scrollerleft+scrollerwidth	
		document.text.clip.left=0
		document.text.clip.right=0
		document.text.clip.top=0
		document.text.clip.bottom=scrollerheight
		scrolltext()
    }
}

function scrolltext() {
    if (document.all) {
		if (document.all.text.style.posLeft>=scrollerleft-textwidth) {
			textmovedtoleft+=step
			document.all.text.style.posLeft=(scrollerleft+scrollerwidth)-textmovedtoleft
			clipright+=step
			if (clipright>scrollerwidth) {
				clipleft+=step
			}
			document.all.text.style.clip ="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
			scrollertop=y
			scrollerleft=x
			document.all.bgscroller.style.posTop=scrollertop-cellpad
			document.all.bgscroller.style.posLeft=scrollerleft-cellpad
			document.all.text.style.posTop=scrollertop
			var timer=setTimeout("scrolltext()",pause)
		}
		else {
			changetext()
		}
	}
   if (document.layers) {
		if (document.text.left>=scrollerleft-textwidth) {
			textmovedtoleft+=step
			document.text.left=(scrollerleft+scrollerwidth)-textmovedtoleft
			document.text.clip.right+=step
			if (document.text.clip.right>scrollerwidth) {
				document.text.clip.left+=step
			}
			scrollertop=y
			scrollerleft=x
			document.bgscroller.top=scrollertop-cellpad
			document.bgscroller.left=scrollerleft-cellpad
			document.text.top=scrollertop
			var timer=setTimeout("scrolltext()",pause)
		}
		else {
			changetext()
		}
	}
}

function changetext() {
    i_message++
	if (i_message>message.length-1) {i_message=0}
	gettextcontent()
	if (document.all) {
		text.innerHTML=textcontent
		textwidth=text.offsetWidth
        document.all.text.style.posLeft=x+scrollerwidth
		textmovedtoleft=0
		clipleft=0
		clipright=0
		document.all.text.style.clip ="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
		checktime()
		if (!timetohidescroller) {scrolltext()}
		else {hidescroller()}
	}

	if (document.layers) {
   		document.text.document.write(textcontent)
		document.text.document.close()
		textwidth=document.text.document.width
		document.text.left=x+scrollerwidth
		textmovedtoleft=0
		document.text.clip.left=0
		document.text.clip.right=0
		checktime()
		if (!timetohidescroller) {scrolltext()}
		else {hidescroller()}
	}
}

function gettextcontent() {
	textcontent="<span style='position:relative;font-size:"+fntsize+"pt;font-family:"+fntfamily+";font-weight:"+fntweight+";overflow-x:hidden'>"
	textcontent+="<nobr><font color="+messagecolor+">"+message[i_message]+"</font></nobr></span>"
}

function getbgcontent() {
	var bgwidth=scrollerwidth+2*cellpad
	var bgheight=scrollerheight+2*cellpad
	bgcontent="<table border="+borderwidth+" width="+bgwidth+"  height="+bgheight+" cellpadding=0 cellspacing=0>"
	bgcontent+="<tr><td bgcolor="+backgroundcolor+">&nbsp;"
	bgcontent+="</td></tr></table>"
}

function startnewtime() {
	starttime= new Date()
	starttime=starttime.getTime()
}

function checktime() {
	    nowtime=new Date()
	    nowtime=nowtime.getTime()
        nowtime=(nowtime-starttime)/1000
		if (nowtime>stoptime) {timetohidescroller=true}
}

function hidescroller() {
    if (document.all) {
		document.all.bgscroller.style.visibility="hidden"
		document.all.text.style.visibility="hidden"
    }
	if (document.layers) {
		document.bgscroller.visibility="hidden"
		document.text.visibility="hidden"
    }
}

function handlerMM(e){
	x = (document.layers) ? e.pageX : document.body.scrollLeft+event.clientX
	y = (document.layers) ? e.pageY : document.body.scrollTop+event.clientY
	x=x+20
	y=y+20
}

if (document.layers){
	document.captureEvents(Event.MOUSEMOVE);
}

if (document.all || document.layers) {
	document.onmousemove = handlerMM;
}
window.onresize=init;
window.onload=init;

