$(document).ready(function(){
	$("ul.content>li").attr('class', 'ieSux');
	$('a.skipIntro').click(function(){
		$("#pussyroller").parent().fadeOut("slow");
		$("#intro").fadeIn("slow");
	});
});


		var sRandomLine = "####################################################################################";
		var sSolidRandomLine = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
		var sEmptyLine = "                                                                                    ";
		var asRandom = [
			sRandomLine, sRandomLine, sRandomLine, sRandomLine, sRandomLine,
			sRandomLine, sRandomLine, sRandomLine, sRandomLine, sRandomLine,
			sRandomLine, sRandomLine, sRandomLine, sRandomLine, sRandomLine,
			sRandomLine, sRandomLine, sRandomLine, sRandomLine, sRandomLine,
			sRandomLine, sRandomLine, sRandomLine, sRandomLine, sRandomLine,
			sRandomLine, sRandomLine, sRandomLine, sRandomLine, sRandomLine,
			sRandomLine, sRandomLine, sRandomLine
		];
		var asSolidRandom = [
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine,
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine,
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine,
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine,
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine,
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine, sSolidRandomLine,
			sSolidRandomLine, sSolidRandomLine, sSolidRandomLine
		];
		
var asDekadFrame1 = [
sRandomLine,
"#######################        #####################################################",
"###################               ##################################################",
"#################                   ################################################",
"################                     ###############################################",
"##############                         #############################################",
"#############         #########         ############################################",
"############        #############        ###########################################",
"############       ###############       ###########################################",
"###########      ###################      ##########################################",
"##########      #####################      #########################################",
"##########      #####################      #########################################",
"     #####     #######################      ########################################",
"       ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##    ###########################    ########################################",
"###    ##    ####################    ###     #######################################",
"###    ##    ###################      ##     #######################################",
"###    ##    ###################       #     #######################################",
"###    ##    ###################   ##  #     #######################################",
"###    ##    ###################   ##  #     #######################################",
"###    ##    ###################       #    ########################################",
"###    ##    ####################     #     ########################################",
"###    ##    ##########################     ########################################",
"###    ##    ##########################     ########################################",
"###    ##    #########################     #########################################",
"###    ##    ########################      #########################################",
"###    ##    ########################     ##########################################",
"###                                       ##########################################",
"###                                      ###########################################",
sRandomLine,
sRandomLine
];
var asDekadFrame2 = [
sRandomLine,
"#######################        #####################################################",
"###################               ##################################################",
"#################                   ################################################",
"################                     ###############################################",
"##############                         #############################################",
"#############         #########         ############################################",
"############        #############        ###########################################",
"############       ###############       ###########################################",
"###########      ###################      ##########################################",
"##########      #####################      #########################################",
"##########      #####################      #########################################",
"     #####     #######################      ########################################",
"       ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##    ###########################    ########################################",
"###    ##    ####################    ###     #######################################",
"###    ##    ###################      ##     #######################################",
"###    ##    ###################       #     #       ###############################",
"###    ##    ###################   ##  #     #       ###############################",
"###    ##    ###################   ##  #     #  ####################################",
"###    ##    ###################       #    ##  ####################################",
"###    ##    ####################     #     ##  ####################################",
"###    ##    ##########################     ##      ################################",
"###    ##    ##########################     ##      ################################",
"###    ##    #########################     ###  ####################################",
"###    ##    ########################      ###  ####################################",
"###    ##    ########################     ####  ####################################",
"###                                       ####  ####################################",
"###                                      #####       ###############################",
sRandomLine,
sRandomLine,
];
var asDekadFrame3 = [
sRandomLine,
"#######################        #####################################################",
"###################               ##################################################",
"#################                   ################################################",
"################                     ###############################################",
"##############                         #############################################",
"#############         #########         ############################################",
"############        #############        ###########################################",
"############       ###############       ###########################################",
"###########      ###################      ##########################################",
"##########      #####################      #########################################",
"##########      #####################      #########################################",
"     #####     #######################      ########################################",
"       ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##    ###########################    ########################################",
"###    ##    ####################    ###     #######################################",
"###    ##    ###################      ##     #######################################",
"###    ##    ###################       #     #       #  ####   #####################",
"###    ##    ###################   ##  #     #       #  ###   ######################",
"###    ##    ###################   ##  #     #  ######  ###  #######################",
"###    ##    ###################       #    ##  ######  ##  ########################",
"###    ##    ####################     #     ##  ######  #  #########################",
"###    ##    ##########################     ##      ##     #########################",
"###    ##    ##########################     ##      ##     #########################",
"###    ##    #########################     ###  ######  ##  ########################",
"###    ##    ########################      ###  ######  ##   #######################",
"###    ##    ########################     ####  ######  ###  #######################",
"###                                       ####  ######  ####  ######################",
"###                                      #####       #  ####   #####################",
sRandomLine,
sRandomLine,
];
var asDekadFrame4 = [
sRandomLine,
"#######################        #####################################################",
"###################               ##################################################",
"#################                   ################################################",
"################                     ###############################################",
"##############                         #############################################",
"#############         #########         ############################################",
"############        #############        ###########################################",
"############       ###############       ###########################################",
"###########      ###################      ##########################################",
"##########      #####################      #########################################",
"##########      #####################      #########################################",
"     #####     #######################      ########################################",
"       ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##    ###########################    ########################################",
"###    ##    ####################    ###     #######################################",
"###    ##    ###################      ##     #######################################",
"###    ##    ###################       #     #       #  ####   ####  ###############",
"###    ##    ###################   ##  #     #       #  ###   ####    ##############",
"###    ##    ###################   ##  #     #  ######  ###  #####    ##############",
"###    ##    ###################       #    ##  ######  ##  ######    ##############",
"###    ##    ####################     #     ##  ######  #  ######  ##  #############",
"###    ##    ##########################     ##      ##     ######  ##  #############",
"###    ##    ##########################     ##      ##     ######  ##  #############",
"###    ##    #########################     ###  ######  ##  ####        ############",
"###    ##    ########################      ###  ######  ##   ###        ############",
"###    ##    ########################     ####  ######  ###  ###  ####  ############",
"###                                       ####  ######  ####  #  ######  ###########",
"###                                      #####       #  ####     ######  ###########",
sRandomLine,
sRandomLine,
];
var asDekadFinal = [
sRandomLine,
"#######################        #####################################################",
"###################               ##################################################",
"#################                   ################################################",
"################                     ###############################################",
"##############                         #############################################",
"#############         #########         ############################################",
"############        #############        ###########################################",
"############       ###############       ###########################################",
"###########      ###################      ##########################################",
"##########      #####################      #########################################",
"##########      #####################      #########################################",
"     #####     #######################      ########################################",
"       ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##     #########################     ########################################",
"###    ##    ###########################    ########################################",
"###    ##    ####################    ###     #######################################",
"###    ##    ###################      ##     #######################################",
"###    ##    ###################       #     #       #  ####   ####  #####       ###",
"###    ##    ###################   ##  #     #       #  ###   ####    ####  ###    #",
"###    ##    ###################   ##  #     #  ######  ###  #####    ####  #####  #",
"###    ##    ###################       #    ##  ######  ##  ######    ####  ######  ",
"###    ##    ####################     #     ##  ######  #  ######  ##  ###  ######  ",
"###    ##    ##########################     ##      ##     ######  ##  ###  ######  ",
"###    ##    ##########################     ##      ##     ######  ##  ###  ######  ",
"###    ##    #########################     ###  ######  ##  ####        ##  ######  ",
"###    ##    ########################      ###  ######  ##   ###        ##  ######  ",
"###    ##    ########################     ####  ######  ###  ###  ####  ##  #####  #",
"###                                       ####  ######  ####  #  ######  #  ####   #",
"###                                      #####       #  ####     ######  #        ##",
sRandomLine,
sRandomLine,
];

var asTheEnd = [
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
sEmptyLine,
];
		
		var asTimeLineData = [
			{time:  0.500, func:  asciiImageFader, arg:{fromImage:  	asTheEnd, toImage: asTheEnd, pow: 0.41}},
			{time:  1.000, func:  asciiImageFader, arg:{fromImage:  	asTheEnd, toImage: asRandom, pow: 1}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:     asRandom, toImage: asDekadFrame1, pow: 0.2}},
			{time:  1.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame1, toImage: asDekadFrame1, pow: 0.5}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame1, toImage: asDekadFrame2, pow: 0.1}},
			{time:  1.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame2, toImage: asDekadFrame2, pow: 3.1}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame2, toImage: asDekadFrame3, pow: 0.1}},
			{time:  1.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame3, toImage: asDekadFrame3, pow: 0.1}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame3, toImage: asDekadFrame4, pow: 0.1}},
			{time:  1.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame4, toImage: asDekadFrame4, pow: 0.1}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFrame4, toImage: asDekadFinal, pow: 0.1}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFinal, toImage: asDekadFinal, pow: 0.1}},
			{time:  2.000, func:  asciiImageFader, arg:{fromImage:  	asDekadFinal, toImage: asTheEnd, pow: 1}},
			{time:  3.000, func:  asciiImageFader, arg:{fromImage:  	asTheEnd, toImage: asTheEnd, pow: 1}},
			
		];
		var nLines = 33, nRows = 84;
		sChars = "  ``^^''\"\"*+-~=rcvunoeaszmwxgqypjt&dfhkb?27TYFPV3456890%$UOZRBNXWMQHGAKESDCJLI1li;:\\\\\\/////][)(}{|!!..,,__";
		sSolidChars = "3489ABDEGHKMNRSWXZ";
		var startDate = new Date();
		var sMandelbrotChars = "MWNNHHDDXXOOCC553311I1i?][()!*;:\"',.`  ";
		var iRadiusSquared = 4;
		var iIterations = 20;
		var nRotation = 0.5;
		var iFPS = 24;
		var iShiftPhase = 0;
		var nShift = 20;
		var nColorCycles = 1;
		var nMandelbrotWidth = 100, nMandelbrotHeight = 100, aMandelbrot = [];
		thread();
		function thread() {
			var nTime = (new Date() - startDate) / 1000; // Time sinds start
			var nTimeLineTime = 0;
			for (var i = 0; i < asTimeLineData.length; i++) {
				// If the elapsed time is smaller than the end time of our event, execute it.
				if (nTime < nTimeLineTime + asTimeLineData[i].time) {
					var iProgress = (nTime - nTimeLineTime) / asTimeLineData[i].time; // 0-1
					asTimeLineData[i].func(iProgress, asTimeLineData[i].arg);
					// Only execute one (the first) event.
					setTimeout(arguments.callee, 1000/iFPS);
					return;
				} else {
					// Calculate the time it would have taken to reach the events end.
					nTimeLineTime += asTimeLineData[i].time;
				}
			}
			//alert("done");
			$("#pussyroller").parent().slideUp("slow");
			$("#intro").fadeIn("slow");
		}			
		
		function shiftFader() {
			return nShift * Math.random() * Math.random() * Math.random() * Math.random() * Math.random();
		}
		function asciiImageFader(iProgress, aArgs) {
			var sContents = "";
			var nFader = Math.pow((1 - Math.cos(iProgress * Math.PI)) / 2, aArgs.pow); // 0-1 sine
			var iShiftFader = shiftFader();
			iShiftPhase += shiftFader();
			var nRandom = (1 - Math.cos(iProgress * 2 * Math.PI)) / 2; // 0-1-0 sine
			for (var line = 0; line < nLines; line++) {
				iShift = iShiftFader * Math.cos(Math.PI * 2 * line / nLines + iShiftPhase);
				for (var row = 0; row < nRows; row++) {
					var nShiftRow = (row + nRows + iShift) % nRows;
					var nCharFrom = getChar(aArgs.fromImage, line, nShiftRow);
					var nCharTo   = getChar(aArgs.toImage, line, nShiftRow);
					var nChar     = nCharFrom + (nCharTo - nCharFrom) * nFader;
//					nChar        += (Math.random() - 0.5 ) * sChars.length * nRandom;
					// Displayed character = random static + real character
					while (nChar < 0) nChar += sChars.length;
					sContents += sChars.charAt(nChar % sChars.length);
				}
				sContents += "<br/>";
			}
			document.getElementById('pussyroller').innerHTML = '<pre>' + sContents + '</pre>';
			//document.body.innerHTML = "<PRE>" + sContents + "</PRE>";
		}
		function getChar(asSourceImage, line, row) {
			sChar = asSourceImage[line].charAt(row);
			switch (sChar) {
				case "#": // Random
					sChar = sChars.charAt(Math.floor(Math.random() * sChars.length));
					break;
				case "@": // Random solid char
					sChar = sSolidChars.charAt(Math.floor(Math.random() * sSolidChars.length));
					break;
			}
			var nChar = (sChars.indexOf(sChar) + sChars.lastIndexOf(sChar)) / 2;
			if (Math.random()<0.05) nChar += Math.random() * 5 - 2.5;
			else nChar += Math.random() - 0.5;
			return nChar;
		}

