// Manage window.onload scripts
var onloadScripts = new Array();

function onloadProcess()
{
    for(var i = 0;i < onloadScripts.length;i++) {
        eval(onloadScripts[i]);
    }
}

function onloadAdd(func){
    onloadScripts[onloadScripts.length] = func;
}

// Add onload
window.onload = onloadProcess;

// Set the initial quote
onloadAdd('document.getElementById("quotetext").innerHTML = "<p>" + quotearray[currentQuote][0] + "</p>"');
onloadAdd('document.getElementById("quotesource").innerHTML = "<p>" + quotearray[currentQuote][1] + "</p>"');

// Initialise fading
onloadAdd('window.setTimeout(swapQuote, 10000)');

// Search box
function initialisesearch(o) {
	if (o.value == "Search") {
		o.value = "";
	}
}
 
/* 
	Fader
*/

var currentQuote = Math.floor(quotearray.length*Math.random());
var currentOpacity = 100;
var fadeDirection = "down";
var timerID; 

function swapQuote() {
	if (fadeDirection == "down" && currentOpacity > 0) {
		// Reduce opacity
		currentOpacity -= 10;
		document.getElementById("quote").className = "fade" + currentOpacity;
		
		window.setTimeout(swapQuote, 50);
	}
	else if (fadeDirection == "up" && currentOpacity < 100) {
		// Increase opacity
		currentOpacity += 10;
		document.getElementById("quote").className = "fade" + currentOpacity;
		
		window.setTimeout(swapQuote, 50);
	}
	else if (currentOpacity  == 0) {
		// Change to fading up
		fadeDirection = "up";
		// Set new text
		if (currentQuote == quotearray.length - 1) {
			currentQuote = 0;
		}
		else {
			currentQuote += 1;
		}
		document.getElementById("quotetext").innerHTML = "<p>" + quotearray[currentQuote][0] + "</p>";
		document.getElementById("quotesource").innerHTML = quotearray[currentQuote][1];
		
		window.setTimeout(swapQuote, 50);
	}
	else {
		// Change to fading down
		fadeDirection = "down";
		
		window.setTimeout(swapQuote, 10000);
	}
}

/*
	Search box
*/
function hidetitle(o) {
	if (o.value == "SEARCH") {
		o.value = "";
	}
}

function showtitle(o) {
	if (o.value == "") {
		o.value = "SEARCH";
	}
}
