var bgInited = false;
function init() {
	bgInited = true;
	var i, path, sym, objRad, w, h, x, y, rad, count;
	
	project.activeLayer.removeChildren();
	
	for (i=0; i<40; i++) {
		w = 10 + Math.random() * 300;
		h = w;
		path = new Path();
		count = Math.ceil(Math.random() * 7 + 2);
		path.strokeColor = mt11.hsv2rgb(Math.random(),.2,1);
		objRad = Math.random() * w/2-5 + 2;
		for(var j = 0 ; j < count;j++){
			rad = Math.random() * 10 - 5 + objRad;
			path.add(new Point(Math.cos(j/count * Math.PI*2 ) * rad + w/2,Math.sin(j/count * Math.PI*2 ) * rad + h/2));
		}
		path.closePath();
		
		sym = new Symbol(path);
		var item = sym.place(Point.random());
		var d = Math.random() * 700 + 300;
		item.data = {d: d, x: Math.random() * d + view.bounds.width*Math.random(), vx:(Math.random()-.5)*.2, vy:(Math.random()-.5), r: Math.random()-.5, y: Math.random() * 1000};
		item.position.y = item.data.y;
		item.position.x = item.data.x;
	}	
	move();
}

function move() {
	var p = Math.floor(mt11.slider.percent()*1000)/1000;
	// view.canvas.style.background = mt11.getBGColor();
	if(mt11.ua.mozilla)
		view.canvas.style.background = "-moz-linear-gradient(45deg," + mt11.getBGColor(.7) + "," + mt11.getBGColor(1) + ")";
	else
		view.canvas.style.background = "-webkit-gradient(linear, 0% 100%, 100% 0%, from(" + mt11.getBGColor(.7) + "), to(" + mt11.getBGColor(1) + ")) ";

	var layer = project.activeLayer;
	var item;
	
	
	for (var i = 0; i < layer.children.length; i++) {
		item = layer.children[i];
		item.rotate(item.data.r);
		
		item.position.x = (-1 * item.data.d * p) + item.data.x;
		item.data.x += item.data.vx;
		item.position.y += item.data.vy;
		if(item.position.y < -200) item.position.y = mt11.windowHeight+200;
		if(item.position.y > mt11.windowHeight+200) item.position.y = -200;
	}
}
function onFrame(e) {
	if(!mt11 || !mt11.initPaper) return;
	if(!bgInited) init();
    move();
}

