uuClass.Canvas.ready(function() {

	var navi = $('#navi');
	var msg = $('#msg');

	$('#logo').hover(function() {
		if(navi.css('display') == 'none')
			$('#navi').show('drop', { direction: 'down' });
	});
	

	$('#tnantoka').click(function(e) {
		e.stopPropagation();
	});

	$('body').click(function() {
//	$('canvas').click(function() {

		if(navi.css('display') != 'none')
			$('#navi').hide('drop', { direction: 'down' });

		if(msg.css('display') != 'none')
			msg.hide();
	});

	$('#navi').hover(function(e) {
		if(msg.css('display') == 'none')
			msg.show('fold', {}, 500); //なんか時間指定しないと動かない。
	});	

	$('#blog').hover(function(e) {
		msg.html('<a href="http://blog.bornneet.com/">Born Neet<br />- The Emotional Programmer -</a><br /><br /><a href="http://blog.ninja.co.jp/"><em>@Ninja-Blog</em></a>');
	});

	$('#profile').hover(function(e) {
		msg.html('<a href="http://iddy.jp/profile/tnantoka/">tnantoka\'s profile</a><br /><br /><a href="http://iddy.jp/"><em>@iddy</em></a>');
	});

	$('#works').hover(function(e) {
		msg.html('<a href="http://www.bornneet.com/">@bornneet.com</a><br /><br /><a href="http://www.bornneet.com/trash.html"><em>See Also Trash Box</em></a>');
	});

	var canvas = document.getElementsByTagName('canvas')[0];
    var ctx = canvas.getContext('2d');

	var twinkle = function() {
	
		var r = random(5, true) + 1;
		
		var x = random(canvas.width);
		var y = random(canvas.height);
		
		var grd = ctx.createRadialGradient(x, y, 1, x, y, r);

		ctx.fillStyle = color(grd);
		ctx.fillRect(x - r, y - r, r * 2, r * 2);

		var interval = random(1000, true) + 1000;
//		var interval = random(0, true) + 100; //test

		setTimeout(function() { twinkle(); }, interval);
	};
	
	var random = function(s, r) {
	
		if(!r) return Math.floor(Math.random() * s);
		else return Math.ceil(Math.random() * s);
	};

	var color = function(grd) {

		// IEは半透明グラデーションができない？？
		if(uuClass.Detect.ie) {
		
			var a = ['f', 'f', 'f'];
			if(random(10) == 0)	a[random(a.length)] = random(16).toString(16);
		
			grd.addColorStop(0, '#' + a.join(''));
			grd.addColorStop(1, '#000');

		
		} else {

			var a = [255, 255, 255, Math.random()];
			if(random(10) == 0)	a[random(a.length)] = random(256);

			grd.addColorStop(0, 'rgba(' + a.join(', ') + ')');
			grd.addColorStop(1, 'rgba(0, 0, 0, ' + Math.random() + ')');
		}

		return grd;
	};

	var log = function(msg) {
		//var debug = true;
		if(typeof debug != 'undefined') {
			if(typeof console != 'undefined') console.log(msg);
			else alert(msg);
		}
	};

    twinkle();
    setTimeout(function() { twinkle(); }, 1000);
    
});