var intrepid_count = 0;
intrepid_add = function() {
	intrepid_count += 1;
	var intrepid_url = 'http://www.intrepidweb.com.au/';
	var div = document.createElement('div');
	div.style.position = 'fixed';
	
	var numType = 'px';
	var heightRandom = Math.random()*.75;
	var windowHeight = 768;
	var windowWidth = 1024;
	var height = 0;
	var width = 0;
	var de = document.documentElement;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;
	} else if(de && de.clientHeight) {
		windowHeight = de.clientHeight;
		windowWidth = de.clientWidth;
	} else {
		numType = '%';
		height = Math.round( height*100 )+'%';
	}
	
	div.onclick = intrepid_add;
	div.style.zIndex = 10;
	div.style.outline = 0;
	
	if( intrepid_count==15 ) {
		file = 'images/hgsdaksajfgdk.png';
		div.style.top = Math.max( 0, Math.round( (windowHeight-530)/2 ) )  + 'px';
		div.style.left = Math.round( (windowWidth-530)/2 ) + 'px';
		div.style.zIndex = 1000;
	} else {
		if( numType=='px' ) div.style.top = Math.round( windowHeight*heightRandom ) + numType;
		else div.style.top = height;
		div.style.left = Math.round( Math.random()*90 ) + '%';
	}
	
	var img = document.createElement('img');
	var currentTime = new Date();
	img.setAttribute('src','images/hgsdaksajfgdk.png');
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(div);
	div.appendChild(img);
	
	// Add stylesheet.
	if (intrepid_count == 5) {
		var cssExisting = document.getElementById('__intrepid_css');
		if (!cssExisting) {
			var head = document.getElementsByTagName("head")[0];
			var css = document.createElement('link');
			css.id = '__intrepid_css';
			css.type = 'text/css';
			css.rel = 'stylesheet';
			css.href = 'includes/style.css';
			css.media = 'screen';
			head.appendChild(css);
		}
	}	
}


/*
 * Adapted from http://www.snaptortoise.com/konami-js/
 */
var intrepid = {
	input:"",
	pattern:"38384040373937396665",
	clear:setTimeout('intrepid.clear_input()',5000),
	load: function() {
		window.document.onkeydown = function(e) {
			if (intrepid.input == intrepid.pattern) {
				intrepid_add();
				clearTimeout(intrepid.clear);
				return;
			}
			else {
				intrepid.input += e ? e.keyCode : event.keyCode;
				if (intrepid.input == intrepid.pattern) intrepid_add();
				clearTimeout(intrepid.clear);
				intrepid.clear = setTimeout("intrepid.clear_input()", 5000);
			}
		}
	},
	clear_input: function() {
		intrepid.input="";
		clearTimeout(intrepid.clear);
	}
}
intrepid.load();
