//  Variables you can change
var typeWriterWait=120	// Delay in ms for the typewriting headliner
var blinkTextWait=1000	// Delay in ms for the blinking headliner
var blinkSpacesWait=300	// Delay in ms between sets of blinking headliner
var blinkMax=6				// Number of times to blink
var expandWait=100		// Delay in ms per character - expanding headliner
var scrollWait=90		// Delay in ms per character - scrolling headliner
var scrollWidth=34		// Number of characters in scrolling headliner
var randomLines=false	// Should the lines be chosen randomly (true or false)
var lineMax=10		// Number of lines of text, as much as you want

lines=new Array(lineMax)

// Text to display, url or mailto, frame name, which effect, postdelaytime
// Static,Blink,Scroll,TypeWriter,Expand -- Headliner.txt for more info

lines[1]=new Line("AskWhy! Books", "http://www.askwhy.co.uk/books/bkcontents.htm", "_top", Blink, 1000)
lines[2]=new Line("The Goddess and Nature", "http://www.askwhy.co.uk/adelphiasophism/index.php", "_top", Scroll, 2000)
lines[3]=new Line("Barabbas", "http://www.askwhy.co.uk/christianity/index.php", "_top", Expand, 2000)
lines[4]=new Line("The Hidden Jesus $30... The Mystery of Barabbas $20... Who Lies Sleeping? $20...", "http://www.askwhy.co.uk/books/aworderform.html", "_top", Scroll, 1000)
lines[5]=new Line("E-mail AskWhy!", "mailto:mike@askwhy.freeserve.co.uk?subject=Website&cc=mike@askwhy.freeserve.co.uk", "", TypeWriter, 1500)
lines[6]=new Line("God's Truth... Pious Lies!", "http://www.askwhy.co.uk/truth/index.php", "_top", Scroll, 2000)
lines[7]=new Line("Science", "http://www.askwhy.co.uk/science/index.php", "_top", Expand, 2000)
lines[8]=new Line("Frome Town", "http://www.askwhy.co.uk/awfrome/index.php", "_top", Expand, 2000)
lines[9]=new Line("Who Lies Sleeping: The Dinosaur Heritage and the Extinction of Man", "http://www.askwhy.co.uk/anthroposaurus/index.php", "_top", Scroll, 2000)
lines[10]=new Line("Analogies and Conjectures", "http://www.askwhy.co.uk/analogiesandconjectures/index.php", "-top", Scroll, 3500)

// Do not change these variables
var lineText=""
var timerID=null
var timerRunning=false
var spaces=""
var charNo=0
var charMax=0
var charMiddle=0
var lineNo=0
var lineWait=0

// ************************************************************
// The functions to get things going
// ************************************************************

// Some other variables (just do not change)
lineText=""
timerID=null
timerRunning=false
spaces=""
charNo=0
charMax=0
charMiddle=0
lineNo=0
lineWait=0

// ************************************************************
// The functions to get things going
// ************************************************************

// Define a line object
function Line(text, url, frame, type, wait) {
	this.text=text
	this.url=url
	this.frame=frame
	this.Display=type
	this.wait=wait
}

// Fill a string with n chars c
function StringFill(c, n) {
	var s=""
	while (--n >= 0) {
		s+=c
	}
	return s
}

// Returns a integer number between 1 and max that differs from the old one
function getNewRandomInteger(oldnumber, max)
{
	var n=Math.floor(Math.random() * (max - 1) + 1)
	if (n >= oldnumber) {
		n++
	}
	return n
}

// Returns a integer number between 1 and max
function getRandomInteger(max)
{
	var n=Math.floor(Math.random() * max + 1)
	return n
}

// Jump to the specified url in the specified frame
function GotoUrl(url, frame) {
	if (frame != '') {
		if (frame == 'self') self.location.href=url
		else if (frame == 'parent') parent.location.href=url
		else if (frame == 'top') top.location.href=url
		else {
			s=eval(top.frames[frame])
			if (s != null) top.eval(frame).location.href=url
			else window.open(url, frame, "toolbar=yes,status=yes,scrollbars=yes")
		}
	}
	else window.location.href=url
}

function Static() {
	document.formDisplay.buttonFace.value=this.text
	timerID=setTimeout("ShowNextLine()", this.wait)
}

function TypeWriter() {
	lineText=this.text
	lineWait=this.wait
	charMax=lineText.length
	spaces=StringFill(" ", charMax)
	TextTypeWriter()
}

function TextTypeWriter() {
	if (charNo <= charMax) {
		document.formDisplay.buttonFace.value=lineText.substring(0, charNo)+spaces.substring(0, charMax-charNo)
		charNo++
		timerID=setTimeout("TextTypeWriter()", typeWriterWait)
	}
	else {
		charNo=0
		timerID=setTimeout("ShowNextLine()", lineWait)
	}
}

function Blink() {
	lineText=this.text
	charMax=lineText.length
	spaces=StringFill(" ", charMax)
	lineWait=this.wait
	TextBlink()
}

function TextBlink() {
	if (charNo <= blinkMax * 2) {
		if ((charNo % 2) == 1) {
			document.formDisplay.buttonFace.value=lineText
			blinkWait=blinkTextWait
		}
		else {
			document.formDisplay.buttonFace.value=spaces
			blinkWait=blinkSpacesWait
		}
		charNo++
		timerID=setTimeout("TextBlink()", blinkWait)
	}
	else {
		charNo=0
		timerID=setTimeout("ShowNextLine()", lineWait)
	}
}

function Expand() {
	lineText=this.text
	charMax=lineText.length
	charMiddle=Math.round(charMax / 2)
	lineWait=this.wait
	TextExpand()
}

function TextExpand() {
	if (charNo <= charMiddle) {
		document.formDisplay.buttonFace.value=lineText.substring(charMiddle - charNo, charMiddle + charNo)
		charNo++
		timerID=setTimeout("TextExpand()", expandWait)
	}
	else {
		charNo=0
		timerID=setTimeout("ShowNextLine()", lineWait)
	}
}

function Scroll() {
	spaces=StringFill(" ", scrollWidth)
	lineText=spaces+this.text
	charMax=lineText.length
	lineText+=spaces
	lineWait=this.wait
	TextScroll()
}

function TextScroll() {
	if (charNo <= charMax) {
		document.formDisplay.buttonFace.value=lineText.substring(charNo, scrollWidth+charNo)
		charNo++
		timerID=setTimeout("TextScroll()", scrollWait)
	}
	else {
		charNo=0
		timerID=setTimeout("ShowNextLine()", lineWait)
	}
}

function StartHeadliner() {
	if (timerRunning) StopHeadliner()
	timerID=setTimeout("ShowNextLine()", 500)
	timerRunning=true
}

function StopHeadliner() {
	if (timerRunning) {
		clearTimeout(timerID)
		timerRunning=false
	}
}

function ShowNextLine() {
	if (randomLines) lineNo=getNewRandomInteger(lineNo, lineMax)
	else (lineNo < lineMax) ? lineNo++ : lineNo=1
	lines[lineNo].Display()
}

function LineClick(lineNo) {
	document.formDisplay.buttonFace.blur()
	if (lineNo > 0) GotoUrl(lines[lineNo].url, lines[lineNo].frame)
     else StartHeadliner()
}


