if (isIE)
	document.write("<link rel='stylesheet' href='CSS/QIE.css' type='text/css' />");

var qTitle = null;
var qBox = null;
var source = null;
var buttons = null;
var hist = null;

function getKey(e) { // Here we use 'keydown'
	var key = (e) ? e.keyCode : window.event.keyCode; // DOM : IE
	var code = (window.Event) ? e.which : event.keyCode;
	if (code == 27) // ESC key is pressed; show smallImages
		goToView();
	if (String.fromCharCode(key) == '\%') // left arrow key is pressed
		prevQuote();
	else if (String.fromCharCode(key) == '\'') // right arrow key is pressed
		nextQuote('');
}

function disablebtnPrev() {
	getEl('btnPrev').style.display = 'none';
	}

function enablebtnNext() {
	getEl('btnNext').style.display = 'inline';
	}

function nextQuote(strCheckBegin) {
	if (strCheckBegin == 'Beginning') {hist.value = ''};
	var randomNumber = Math.floor(Math.random() * 293) + 1;
//	randomNumber = 289; // Universet er uendeligt...
	hist.value += '/' + randomNumber;
	getQuote(randomNumber); // From Quotes.js
	fillQuote();
	}

function prevQuote() {
	var Str = hist.value;
	var oldStr = Str.substr(0, Str.lastIndexOf('/'));
	hist.value = oldStr;
	getQuote(parseInt(oldStr.slice(oldStr.lastIndexOf('/') + 1))); // This shortens History!
	fillQuote();
	if (oldStr == '') {hist.value = ''};
	Str = hist.value;
	oldStr = Str.substr(0, Str.lastIndexOf('/'));
	if (oldStr == '') {disablebtnPrev()};
}

function fillQuote() {
	if (isIE) {
		qBox.style.visibility = 'hidden';
		source.style.visibility = 'hidden';
		qBox.filters['revealTrans'].transition = 12;
		source.filters['revealTrans'].transition = 12;
		qBox.filters.RevealTrans.apply();
		source.filters.RevealTrans.apply();
		qBox.style.visibility = 'visible';
		source.style.visibility = 'visible';
		qBox.filters.RevealTrans.play(.4);
		source.filters.RevealTrans.play(.4);
	}
	qBox.innerHTML = getFront(strQuote, '@@@');
	source.innerHTML = getEnd(strQuote, '@@@');
	getEl('btnPrev').style.display = 'inline';
}

function resizing() {
	liveWidth = getEl('RightMostPoint').offsetLeft + 2;
	qTitle.style.width = (liveWidth - 200) + 'px';
	qBox.style.width = (liveWidth - 200) + 'px';
	source.style.width = (liveWidth - 200) + 'px';
	buttons.style.width = (liveWidth - 200) + 'px';
}

function btnOver(elem) {elem.style.background = 'blue'};
function btnOut(elem) {elem.style.background = 'darkblue'};
function btnDown(elem) {elem.style.fontStyle = 'italic'};
function btnUp(elem) {elem.style.fontStyle = 'normal'};

function addListeners() {
	if (!document.getElementsByTagName) return;

	qTitle = getEl('QuoteTitle');
	qBox = getEl('QuoteBox');
	source = getEl('Source');
	buttons = getEl('Buttons');
	hist = getEl('History');

//	if (winWidth() > 1024)
//		document.body.style.backgroundImage = 'url(Images/Quotes1152.jpg)';

	nextQuote('Beginning');

	disablebtnPrev();

	enablebtnNext();

   resizing()

	addEvent(window, 'resize', resizing, false);
	addEvent(document, 'keydown', getKey, false);
	qTitle.style.visibility = 'visible';
	qBox.style.visibility = 'visible';
	source.style.visibility = 'visible';
	buttons.style.visibility = 'visible';
}

addEvent(window, 'load', addListeners, false);

