// JavaScript Document

function headAnimation(cssAdd) {
	var nrStars = 200;
	var repeat = 1000;
	var glow = 1000;
	var pipes = 10;
	var repeat = 2;
	
	var head = document.getElementById("head");
	for (var i = 0; i < nrStars; i++) {
		var img = document.createElement("img");
		img.setAttribute("src", cssAdd + "img/png/glimmer.png");
		var id = "star"+i;
		img.setAttribute("id", id);
		glimmer.push(id);
		img.className = "glimmer";
		img.style.position = "absolute";
		img.style.top = Math.round(Math.random()*180) + "px";
		img.style.left = Math.round(Math.random()*950) + "px";
		img.style.display = "none";
		head.appendChild(img);		
	}
	window.setTimeout("glow('a', " + pipes  + ", " + glow  + ", " + repeat  + ")", glow);
	window.setTimeout("changePic()", 1000);
	
	
}

function glow(fp, pipes, glow, r) {
	//window.alert(r);
	var pos = Math.round(Math.random()*glimmer.length);
	for(var i = 0; i < pipes; i++) {
		var pos = Math.round(Math.random()*(glimmer.length-1));
		scope = fp + "pipe" + i;
		var d = (Math.round(Math.random()*parseInt(glow)))/1000;
		Effect.Appear(glimmer[pos],
			{
				duration: d,
				from: 0,
				to: 1,
				queue: {position: 'end', scope: scope}
			}
		);
		Effect.Appear(glimmer[pos],
			{
				duration: d,
				from: 1,
				to: 0,
				queue: {position: 'end', scope: scope}
			}
		);
	}
	if (parseInt(r) >= 0)
		window.setTimeout("glow('" + fp + "', " + pipes  + ", " + glow  + ", " + (r-1)  + ")", 2*glow);
}

function changePic() {
	if (headpic != "") {
		Effect.Fade(headpic,
			{
				duration: 1,
				from: 1,
				to: 0,
				queue: {position: 'end', scope: 'scope'}
			}
		);
	}
	var newhp = headpic;
	while(headpic == newhp) 
		newhp = picImg[Math.round(Math.random()*(picImg.length-1))];
	
	headpic = newhp;
	Effect.Appear(headpic,
		{
			duration: 2,
			from: 0,
			to: 1,
			queue: {position: 'end', scope: 'scope'}
		}
	);	
	window.setTimeout('headAnimation()', 7500);
}
