delta = 5;
constRot = 10;
doIt = function() {
	i++;
	coff = (1.01*i);
	rot = i*delta;
	if(delta==0) {
		rot = constRot;
	}
	s = 'rotate('+ rot +') scale('+ coff*Math.exp(i/50) +')';
	if(i == 600) { // i == 600
		console.log(s);
		i = 122;
	}
	e.setAttribute('transform',s);	
}
toBw = function() {
	console.log('to bw');
	rect.setAttribute('fill','#fff');
	circle.setAttribute('fill','#000');
	path.setAttribute('stroke','#fff');
}
toColor = function() {
	console.log('to color');
	rect.setAttribute('fill','#b00');
	circle.setAttribute('fill','#fff');
	path.setAttribute('stroke','#000');	
}
bwFlash = function() {
	//console.log('flash');
	flash.setAttribute('opacity',1);
	oi = 11;
	oscOpacityInterval = setInterval(oscOpacity, 20);
}
oscOpacity = function() {
	oi--;
	if(oi<0) {
		clearInterval(oscOpacityInterval);
	}
	flash.setAttribute('opacity',oi/11);
}
kick = function() {
	console.log('kick');
	delta = 12;
	setTimeout(function() {
		delta = 5;
	}, 280);
}
swirl = function() {
	console.log('swirl');
	delta = -20;
	setTimeout(function() {
		delta = 5;
	}, 2500);
}
longswirl = function() {
	console.log('long swirl');
	delta = -20;
	animate = document.getElementById('animate');
	deltaInterval = setInterval(function() {
		delta=delta-0.275;
		animate.setAttribute('opacity',100-Math.abs(delta*3.2));
	}, 125);
	setTimeout(function() {
		clearInterval(deltaInterval);
		delta = 5;
	}, 8000);
}
stop = function() {
	console.log('stop');
	delta = -5;
	setTimeout(function() {
		delta = 5;
	}, 440);
}
none = function() {
	// do nothing
}
effect = function() {
	console.log('effect')
	delta = 0;
	toBw();
	setTimeout(function() {
		delta = 5;
		clearInterval(set2);
		toColor();
	}, 1760);
	constRot = Math.floor(Math.random()*360);
	set1 = setInterval(function() {
		constRot = Math.floor(Math.random()*360);
	}, 350);
	setTimeout(function() {
		constRot = Math.floor(Math.random()*360);
		clearInterval(set1);
		set2 = setInterval(function() {
			constRot = Math.floor(Math.random()*360);
		}, 90);
	}, 1400);
}
function init(evt) {
	console.log('swastika runner');
	i = 0;
	factor = 0.64;
	e = document.getElementById('animate');
	rect = document.getElementById('rect');
	circle = document.getElementById('circle');
	path = document.getElementById('path');
	flash = document.getElementById('flash');
	setInterval(doIt,20);
	// timeout tables for pattern changing
	bwFlash();
	kick();
	pattern = new Array(stop,kick,stop,kick,stop,kick,kick,kick,stop,kick,stop,kick,stop,kick,kick,kick,stop,kick,stop,kick,stop,kick,kick,kick,stop,kick,stop,kick,kick,kick,kick,kick,stop,kick,stop,kick,stop,kick,kick,kick,stop,kick,stop,kick,stop,kick,kick,kick,stop,kick,stop,kick,stop,kick,kick,kick,kick,kick,swirl,none,none,none,none,kick,none,none,none,kick,none,none,none,kick,none,none,none,effect,none,none,none,kick,none,none,none,kick,none,none,none,kick,none,none,none,effect,none,none,none,kick,none,none,none,kick,none,none,none,kick,none,none,none,effect,none,none,none,kick,none,none,none,kick,none,none,none,kick,kick,kick,kick,kick,longswirl,none,none,none,none);
	pi = 0;
	setInterval(function() {
		if(pattern[pi] !== 'undefined') {
			pattern[pi]();
		}
		bwFlash();
		pi++
	}, 466);
}
