
// main_init function

drawShape = function(mc,s){
 mc.lineStyle(s.stroke_width,s.stroke);
 if (s.fill != undefined) mc.beginFill(s.fill);
 var d = s.d.split(' ');
 for (var i=0;i<d.length;i++){
  var c = d[i].charAt(0); 
  var v = d[i].substr(1);
  v = v.split(',');
  if (c=='Q'){    
   var x = v[0];
   var y = v[1];
   i++;
   v = d[i].split(',');
   mc.curveTo(x,y,v[0],v[1]);
  } else if (c=='L'){ mc.lineTo(v[0],v[1]);
  } else if (c=='z'){ mc.lineTo(mx,my);
  } else if (c=='M'){
    var mx = v[0];
    var my = v[1];
    mc.moveTo(mx,my);
  }
 }
 if (s.fill != undefined) mc.endFill();
}

main_init = function(mc){
 if (shape_id.length > 0){
  var m = attachMovie(shape_id,'shape',4);
 } else {
  var m = createEmptyMovieClip('shape',4);
  if (shape_id == 1){
   drawShape(m,{d:"M-0.2,-5.9 Q4.5,-10.5 4.3,-3.6 Q10.6,-2.6 5.4,1.4 Q8.3,7.3 2.3,5.4 Q-0.3,11.2 -2.7,5.4 Q-9.0,6.8 -5.8,1.4 Q-11.2,-2.2 -4.7,-3.6 Q-5.6,-10.0 -0.2,-5.9 z",fill:base_color});
  }else if(shape_id==2){
   drawShape(m,{d:"M-7.3,-5.9 Q-3.2,-9.7 -0.3,-4.2 Q3.4,-9.9 7.1,-5.9 Q9.1,-1.7 5.4,2.2 L-0.3,8.5 L-6.0,2.2 Q-10.0,-2.2 -7.3,-5.9 z",fill:base_color});
  }else{
   drawShape(m,{d:"M-15.3,-0.5 L-1.4,-1.5 L-0.3,-15.5 L0.8,-1.5 L14.7,-0.5 L0.8,0.6 L-0.3,14.5 L-1.4,0.6 L-15.3,-0.5 z",fill:base_color});
   drawShape(m,{d:"M-5.0,-0.9 Q-5.0,-2.7 -3.7,-4.1 Q-2.4,-5.4 -0.6,-5.4 Q1.3,-5.4 2.6,-4.1 Q4.0,-2.7 4.0,-0.9 Q4.0,1.0 2.6,2.3 Q1.3,3.6 -0.6,3.6 Q-2.4,3.6 -3.7,2.3 Q-5.0,1.0 -5.0,-0.9 z",fill:base_color});
  }
 }
 m._visible = false;
 sc_min = shape_scale_min / 100;
 sc_max = shape_scale_max / 100;
 sc_delta = sc_max - sc_min;
 border = max_dist + Math.sqrt(m._width * m._width + m._height * m._height) * sc_max;
 border2 = border << 1; 
 max_dist2 = max_dist << 1;
 b = mc.getBounds();
 s = new flash.display.BitmapData(b.xMax-b.xMin+border2,b.yMax-b.yMin+border2,1,0);
 m = createEmptyMovieClip('shapes',6);
 m.attachBitmap(s,1);
 m._x = b.xMin - border; m._y = b.yMin - border;
 fade = new flash.filters.ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,-4<<fade_speed]);
 blur = new flash.filters.BlurFilter(shape_blur,shape_blur);
 glow = new flash.filters.GlowFilter(0,glow_alpha/100,6,6);
 if (glow_only) glow.inner = glow.knockout = true;
}

// main_effect function

main_effect = function(mc,frame){
 s.applyFilter(s,s.rectangle,{},fade) ;
 fade_cnt = subs_done ? fade_cnt + 1 : 0;
 if (fade_cnt == 256/(4<<fade_speed)) end_effect = true;
}

// sub_init function

sub_init = function(mc){
 mc.shape_cnt = 0;
 mc.tx = mc.__x -b.xMin + border - max_dist;
 mc.ty = mc.__y -b.yMin + border - max_dist;
 if (!out_effect) mc._alpha = 0;
}

// sub_effect function

sub_effect = function(mc,frame){
 perc = frame / lastsubframe;

 while (perc * shapes_per_char > mc.shape_cnt){
  glow.color = glow_colors[Math.random()*glow_colors.length<<0];
  shape.filters = [blur,glow];
  var a = vary_angle ? Math.random()*deg180 : 0;
  var sc = sc_min + Math.random() * sc_delta;
  s.draw(shape,new flash.geom.Matrix(Math.cos(a)*sc,Math.sin(a)*sc,-Math.sin(a)*sc,Math.cos(a)*sc,mc.tx+Math.random()*max_dist2,mc.ty+Math.random()*max_dist2));
  mc.shape_cnt++;
 }

 mc._alpha = out_effect ? 100 - perc * 100 : perc * 100;
 if (frame == lastsubframe) mc.done=true;
}
