var showtime;
var nowX;
var nowY;

//window.onresize = resize;

function resize()
{
	var c = document.getElementById('canvas');
	var ctx = c.getContext('2d');
	//c.width =  document.body.clientWidth - 40;
	//c.width = c.width;
	//draw();
}

//document.getElementById('canvas').onClick = doRefresh;

function doPause(e){
	if (!complete){
		if (!pauseon){
			clearInterval(showtime);
			pauseon = true;
			if (!complete){
				var c = document.getElementById('featureTip');
				c.innerHTML = "<strong>paused</strong><br/>"+playMsg+redrawMsg;
			}
		} else {
			pauseon = false;
			showtime = setInterval( update, 25);
			var c = document.getElementById('featureTip');
			c.innerHTML = "<strong>running</strong><br/>"+pauseMsg+redrawMsg;
		}
	} else{
		clearInterval(showtime);
		complete = false;
		pauseon = false;
		i = 0;
		draw();
	}
}
function doRestart(){
	clearInterval(showtime);
	complete = false;
	pauseon = false;
	i = 0;
	draw();
}

function draw() {
	$(document).mousemove(function(e){
		nowX = Math.round((e.pageX/document.body.clientWidth)*1200,1);
		nowY = Math.round((e.pageY/document.body.clientHeight)*600,1);
	});
	showtime = setInterval(update, 250);
}

function update() {
	var canvas = document.getElementById('canvas');

	// use getContext to use the canvas for drawing
	var ctx = canvas.getContext('2d');
	
	//canvas.style.backgroundImage="url('http://farm5.static.flickr.com/4018/5123692581_e2233eef8b_o_d.jpg')";
	canvas.style.backgroundImage="url('/images/clear.gif')";
	
	ctx.clearRect(0,0,canvas.width,canvas.height);
	
	

	
	//ctx.strokeStyle = "rgba(0,0,0,0.25)";
	
	
	var distance = 34*(.1*(nowX/nowY))+10;
	
	var i=0;
	var totalr = 25;
	ctx.lineWidth = 64*(nowX/nowY);
	
	for(i=0; i<(totalr+1);i++){
		ctx.beginPath();
		ctx.arc(450,300,distance*i,0,Math.PI*2,true);
		
		var vgrn = 10;//Math.round(Math.sin(((i)/(totalr*2))*Math.PI)*255,1);
		var vred = 10;//Math.round(Math.sin(((i-(totalr/2))/(totalr))*Math.PI)*250,1);
		var vblu = 10;//Math.round(Math.sin((((totalr)-i)/(totalr*2))*Math.PI)*255,1);
		
		ctx.strokeStyle = "rgba("+vred+","+vgrn+","+vblu+",0.03)";
		ctx.stroke();
	}
	
	
	for(i=0; i<(totalr+1);i++){
		ctx.beginPath();
		ctx.arc(450,300,distance*i,Math.PI*((nowY*i)/300),Math.PI*((nowY*i)/200),true);
		
		var vgrn = Math.round(Math.sin(((i)/(totalr*2))*Math.PI)*255,1);
		var vred = Math.round(Math.sin(((i-(totalr/2))/(totalr))*Math.PI)*250,1);
		var vblu = Math.round(Math.sin((((totalr)-i)/(totalr*2))*Math.PI)*255,1);
		
		ctx.strokeStyle = "rgba("+vred+","+vgrn+","+vblu+",0.95)";
		ctx.stroke();
	}
	
	
	
}

function postFunctions(){
	//alert(Math.round(Math.sin((.5)*Math.PI)*255),1);
	draw();

}
