﻿var mat = new function() {
	// Data for quotes (private)
	var quoteData = [
		"Hmm. The Welsh I think. Yes, definitely the Welsh. Or a car.",
		"No - wine only came out of his nose about 10 minutes later",
		"Ok, maybe for £500. What kind of monkey is it?",
		"You see son: When a man and a woman love each other very much... they go at it like rabbits.",
		"She really felt her face was out of proportion, until she had her eyes enlarged",
		"It wasn't really fair, the flames had reached the goalkeeper by that point",
		"A beachball obviously, otherwise how the hell would I eat anything?",
		"I really don't know why you're looking at me like that. Oh! Really? Glass eye you say?",
		"Dress to impress. Impress to undress. Yeah. Clever ain't I?",
		"Ok ok, I admit it. It was a stupid idea. But I really though it would float",
		"So it won't burn, sink or dissolve in acid. Hmm. We need a manatee.",
		"Did you see Popbitch? Apparently Cliff Richard's got one on his back.",
		"How? How can I possibly do that? I've got three frickin' arms now!"
	];
	
	// Adds random quote to bottom of page (public)
	this.addQuote = function() {
		if( !document.createElement || !document.getElementsByTagName ){ return true; }
		var chosenQuote = '<em>"' + quoteData[ Math.floor( Math.random() * quoteData.length ) ] + '"</em>';
		var quoteP = document.createElement('p');
		quoteP.setAttribute('id', 'quote');
		quoteP.innerHTML = chosenQuote;
		document.getElementsByTagName('body')[0].appendChild(quoteP);
	}
	
	// Swops out obfuscated email for cleartext
	this.emailInit = function() { 
		if ( 
			!document.getElementById || 
			!document.getElementById('emailAddress') || 
			!document.getElementById('emailAddress')
		){
			return true; 
		}
		var at = "@"
		var dot = "."
		var mail = "personalsite" + at + "hampson" + dot + "org" + dot + "uk";
		document.getElementById('emailAddress').innerHTML='<a href="mailto:'+mail+'">'+mail+'</a>';
		document.getElementById('emailExplanation').style.display="none";
	}
	
	// General purpose multiple onload handler (public)
	this.addLoadEvent = function(func) { 
		var oldonload = window.onload; 
		if (typeof window.onload != 'function') { 
			window.onload = func; 
		} else { 
			window.onload = function() { 
				if (oldonload) { 
					oldonload(); 
				}  
				func(); 
			} 
		} 
	} 
}
mat.addLoadEvent(mat.addQuote);
