/*
	(c)2007-2009 by gaspar.sukk@gmail.com
*/
var num=6;
var x=50,y=-50;
var count;
var thesun = document.getElementById('thesun');
function prepareTheSun() {
	if(!document.getElementById) {
		return;
	}
	/*var img = document.createElement('img');
	img.setAttribute('src','images/sun.png');
	img.setAttribute('border',0);
	img.setAttribute('alt','Päike');*/
	
	for (i=0;i<num;i++) {
		var sun = document.createElement('img');
		sun.setAttribute('src','images/sun.png');
		sun.setAttribute('border',0);
		sun.setAttribute('alt','Päike');
		sun.setAttribute('id','note'+i);
		style = 'position:absolute;left:'+(x*i)+'px;top:'+y+'px;';
		sun.setAttribute('style',style);
		sun.style.cssText = style; // IE?
		thesun.appendChild(sun);
	}
}
prepareTheSun();
window.document.onclick=playSound;
if (window.addEventListener) {
	window.addEventListener("mousedown", updatePos, false);
}
else if(document.all) {
	window.document.onmousedown = updatePos;
}
else if(window.captureEvents) {
	window.captureEvents(Event.MOUSEDOWN);
	window.onMouseDown = updatePos;
}
function updatePos(e) {
	if(e) {
		x = e.pageX;
		y = e.pageY;
	} else if(document.all) {
		x = event.clientX+document.body.scrollLeft;
		y = event.clientY+document.body.scrollTop;
	}
}
function playSound() {
	count=0;
	animation();
}
function animation() {
	if(document.getElementById) {
		if(count<5) {
			for(i=0;i<num;i++) {
				document.getElementById("note"+i).style.left = (x+Math.sin(i*Math.PI*2/num)*20*count)+'px';
				document.getElementById("note"+i).style.top = (y+Math.cos(i*Math.PI*2/num)*20*count)+'px';
				/*debug += i+'-'+document.getElementById("note"+i).style.left+':'+document.getElementById("note"+i).style.top+"\n";*/
			}
			setTimeout('animation()',50);
		} else {
			for(i=0;i<num;i++) {
				document.getElementById("note"+i).style.left= (-50)+'px';
				document.getElementById("note"+i).style.top= (-50)+'px';
			}
		 }
	}
	count++;
}
