/* =========================================== */
/* js for cody it */
/* last update: 2010/10/1 by yc */
/* =========================================== */

$(document).ready(function(){
	
	$('#content_container').hover(function(){
		$('#content_container').fadeTo('fast', 1.0);
	}, function(){
		$('#content_container').fadeTo('fast', 0.4);
	});
	
	var canvasWidth, canvasHeight;
	canvasWidth = $('#paper').innerWidth()-1;
	canvasHeight = $('#paper').innerHeight()-3;
	
	var paper = Raphael("paper", canvasWidth, canvasHeight);
	var circles = new Array();
	
	circles[0] = paper.circle(320, 240, 60).animate({fill: "#223fa3", stroke: "#ededed", "stroke-width": 100, "stroke-opacity": 0.5}, 3000, 'bounce');
	circles[1] = paper.circle(720, 40, 90).animate({fill: "#cc3fa3", stroke: "#0e00f0", "stroke-width": 70, "stroke-opacity": 0.6}, 2000);
	circles[2] = paper.circle(-20, 100, 110).animate({fill: "#223f00", stroke: "#575c00", "stroke-width": 90, "stroke-opacity": 0.7}, 2000);
	circles[3] = paper.circle(720, 340, 40).animate({fill: "#223fa3", stroke: "#ff0000", "stroke-width": 100, "stroke-opacity": 0.5}, 2000);
	circles[4] = paper.circle(410, 620, 140).animate({fill: "#2f3ff3", stroke: "#ff00f0", "stroke-width": 60, "stroke-opacity": 0.6}, 2000);
	circles[5] = paper.circle(920, 560, 90).animate({fill: "#cc3fa3", stroke: "#0000ff", "stroke-width": 80, "stroke-opacity": 0.7}, 2000, 'elastic');
	//circles[5] = paper.circle(920, 560, 90).animateAlong("M10,50c0,50,80-50,80,0c0,50-80-50-80,0z", 4000);
	//circles[5] = paper.ellipse(920, 560, 90, 40).animate({fill: "#cc3fa3", stroke: "#0000ff", "stroke-width": 80, "stroke-opacity": 0.7}, 2000, 'elastic');
	
	$('#paper').click(function(e) {
		
		var randomnumber = Math.floor(Math.random()*circles.length);
		var rad = Math.floor(Math.random()*150);
		var fillColor = genHex();
		var strokeColor = genHex();
		var strEasing = genEasing();
		
		for(i=0; i < circles.length; i++){
			if(i == randomnumber){
				circles[i].remove();
				circles[i] = paper.circle(e.pageX, e.pageY, rad).animate({fill: fillColor, stroke: strokeColor, "stroke-width": 80, "stroke-opacity": 0.7}, 2000, strEasing);
			}
		}
		
		paper.safari();
	});

	
});// End: (document).ready

function genHex(){
	colors = new Array(14);
	colors[0]="0";
	colors[1]="1";
	colors[2]="2";
	colors[3]="3";
	colors[4]="4";
	colors[5]="5";
	colors[5]="6";
	colors[6]="7";
	colors[7]="8";
	colors[8]="9";
	colors[9]="a";
	colors[10]="b";
	colors[11]="c";
	colors[12]="d";
	colors[13]="e";
	colors[14]="f";
	
	digit = new Array(5);
	color="#";
	
	for (i=0;i<6;i++){
		digit[i]=colors[Math.round(Math.random()*14)];
		color = color+digit[i];
	}
	return color;
}

function genEasing(){
	easing = new Array();
	easing[0] = '';
	easing[1] = 'elastic';
	easing[2] = 'bounce';
	
	var randomnumber = Math.floor(Math.random()*easing.length);
	
	return easing[randomnumber];
}

