var Ref = "0123456789abcdefghijklmnopqrstuvwxyz ;:.-~/\\(){}\"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

// The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See:  http://www.msc.cornell.edu/~houle/javascript/randomizer.html

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed / (233280.0);
};

function rand(number) {
        return (Math.ceil(rnd() * (number + 1)) - 1);
};

function permute(textstring) {
	result = "";
	skip = false;
	linksUsed = 0;
	linkClosed = true;
	tackLink = false;
	for (Count = 0; Count < textstring.length; Count++) {
		Char = textstring.substring (Count, Count + 1);
		if (Char == '<' || Char == '&' || Char == '_') {
			skip = true;
		}
		if (Char == '_') {
			tackLink = true;
		}
		if (skip == false) {
			Num = Ref.indexOf (Char);

			// Char not found: insert random instead.
			if (Num == -1) {
				Num = rand(Ref.length - 1);
			}

			// Randomize this character: base 1/20.
			if (rand(20 * mutationDecrease) == 1) {
				Num = rand(Ref.length - 1);
			}

			EncodeChar = Ref.substring(Num, Num + 1);

			// Delete this character: base 1/45.
			if (rand(45 * mutationDecrease) == 1) {
				EncodeChar = '';
			}

			// Insert an additional random character: base 1/30.
			if (rand(30 * mutationDecrease) == 1) {
				indexNum = rand(Ref.length - 1);
				result += Ref.substring(indexNum, indexNum + 1);
			}

			// Line break: base 1/300.
			if (lineBreakEnabled && rand(300 * mutationDecrease) == 1) {
				result += "\n";
			}
		}
		else {
			EncodeChar = Char;
		}

		result += EncodeChar;

		if (Char == '>' || Char == ';') {
			skip = false;
			if (tackLink) {
				if (linkClosed) {
					result += '<a href="' + links[linksUsed] + '">';
					linkClosed = false;
					linksUsed++;
				}
				else {
					result += '</a>';
					linkClosed = true;
				}
				tackLink = false;
			}
		}
	}
	return result;
}

function mutate() {
	document.all(fieldID).innerText = permute(document.all(fieldID).innerText);
	setTimeout("mutate();", 500 * mutationDecrease);
}


function randomLink() {
    var numberOfPages = 26;
    var randomlink = Math.round(Math.random() * (numberOfPages - 1));

    var page1 = "anomalousbehavior.html";
    var page2 = "loveletter.html";
    var page3 = "page01.html";
    var page4 = "page02.html";
    var page5 = "page025.html";
    var page6 = "page03.html";
    var page7 = "page04.html";
    var page8 = "page045.html";
    var page9 = "page05.html";
    var page10 = "poem.html";
    var page11 = "sourcecode.html";
    var page12 = "theend.html";
    var page13 = "abandon.html";
    var page14 = "agenda.html";
    var page15 = "dream.html";
    var page16 = "emanation.html";
    var page17 = "fornication.html";
    var page18 = "functionality.html";
    var page19 = "ghost.html";
    var page20 = "hardcoded.html";
    var page21 = "her.html";
    var page22 = "horsemen.html";
    var page23 = "newscast.html";
    var page24 = "page0425.html";
    var page25 = "stars.html";
    var page26 = "wyrm.html";

    if (randomlink == 0)
        window.location = page1;
    else if (randomlink == 1)
        window.location = page2;
    else if (randomlink == 2)
        window.location = page3;
    else if (randomlink == 3)
        window.location = page4;
    else if (randomlink == 4)
        window.location = page5;
    else if (randomlink == 5)
        window.location = page6;
    else if (randomlink == 6)
        window.location = page7;
    else if (randomlink == 7)
        window.location = page8;
    else if (randomlink == 8)
        window.location = page9;
    else if (randomlink == 9)
        window.location = page10;
    else if (randomlink == 10)
        window.location = page11;
    else if (randomlink == 11)
        window.location = page12;
    else if (randomlink == 12)
        window.location = page13;
    else if (randomlink == 13)
        window.location = page14;
    else if (randomlink == 14)
        window.location = page15;
    else if (randomlink == 15)
        window.location = page16;
    else if (randomlink == 16)
        window.location = page17;
    else if (randomlink == 17)
        window.location = page18;
    else if (randomlink == 18)
        window.location = page19;
    else if (randomlink == 19)
        window.location = page20;
    else if (randomlink == 20)
        window.location = page21;
    else if (randomlink == 21)
        window.location = page22;
    else if (randomlink == 22)
        window.location = page23;
    else if (randomlink == 23)
        window.location = page24;
    else if (randomlink == 24)
        window.location = page25;
    else if (randomlink == 25)
        window.location = page26;
}
