// TROLL LIKE A BOSS
// Copyrightings - muppetalert 2014
var rotation = 0, logodiv = false, cdt = 2, mcdt = 74, acdt = 20;
var trollololimg = ['awesome.png',
		'awesome_1.jpg',
		'awesome_2.jpg',
		'awesome_cat.jpg',
		'awesome_dog.jpg',
		'awesome_pig.jpg',
		'mail.jpg',
		'monacle_cat.jpg',
		'stretch_cat.jpg',
		'heyu.png',
		'troll.png',
		'awesome_pigeon.jpg',
		'meow.jpg',
		'marketing.jpg',
		'coffee.jpg',
		'marketing.jpg',
		'coffee.jpg',
		'awesome_meerkat.jpg'], curimg = -1, iter = 0;
trollololimg.sort(function() { return (Math.round(Math.random())-0.5); });
var getRandImg = function() {
	
	//while(typeof trollolol[rand] == 'undefined') rand = (Math.round((Math.random()*(trollolol.length-1))+1));
	curimg++;
	if(curimg > trollololimg.length-1) {curimg = 0;iter++;}
	if(iter==2) {iter = 0;trollololimg.sort(function(){return (Math.round(Math.random())-0.5);});}
	return 'http://rudiv.se/troll/' + trollololimg[curimg];
}
var spin = function() {
	if (!logodiv) {
		logodiv = document.createElement('img');
		logodiv.id = 'divvy';
		logodiv.style.position = 'absolute';
		logodiv.src = 'http://rudiv.se/troll.png';
		// Browser width?
		var width = document.body.clientWidth;
		logodiv.style.left = ((width / 2) - 300) + 'px';
		logodiv.style.top = '120px';
		document.body.appendChild(logodiv);
		done = true;
	}
	if (rotation == 360) rotation = 0;
	rotation += 3;
	logodiv.style.transform = 'rotate(' + rotation + 'deg)';
	logodiv.style.OTransform = 'rotate(' + rotation + 'deg)';
	logodiv.style.WebkitTransform = 'rotate(' + rotation + 'deg)';
	logodiv.style.MozTransform = 'rotate(' + rotation + 'deg)';
	logodiv.style.msTransform = 'rotate(' + rotation + 'deg)';
	setTimeout(spin, 50);
	console.log('spinning ' + rotation + 'deg');
}
var randCol = function() {
	var poss = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];
	var buildah = '';
	var rand = -1;
	for(var i = 0; i < 6; i++) {
		while(typeof poss[rand] == 'undefined') rand = (Math.round((Math.random()*(poss.length-1))+1));
		buildah += poss[rand];
		rand = -1;
	}
	return '#' + buildah;
}
var cd = function() {
	cdt--; mcdt--; acdt--;
	if (cdt <= 0) {
		cdt = 2;
		document.getElementById('divvy').src = getRandImg()
	}
	if (mcdt <= 0) {
		mcdt = 74;
		document.getElementById('trololol').style.display = 'none';
		setTimeout(function() { document.getElementById('trololol').style.display = 'block'; }, 250);
	}
	if (acdt == 0) {
		//alert('copyright 2014 muppetalert trollovations inc');
		(acdt > 9000); // ITS OVER NINE THOUSANDDDDDD!!!!!!!!!
	}
	logodiv.style.boxShadow = '0px 0px 40px ' + randCol();
	document.body.style.backgroundColor = randCol();
	setTimeout(cd, 2000);
}
document.addEventListener('DOMContentLoaded', function() { spin(); cd();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-417367-18']);
_gaq.push(['_trackPageview']);
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.src = 'http://www.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
}, false);
