
// main_init function

main_init = function(mc){
 subs_done = true;
 b      = mc.getBounds(mc);         // get boundaries
 h_inc  = (b.xMax - b.xMin) / cols; // calculate horizontal inc value
 v_inc  = (b.yMax - b.yMin) / rows; // calculate vertical inc value
 bl_w   = h_inc + .2;               // calculate block width
 bl_h   = v_inc + .2;               // calculate block height
 if (equal_wh) bl_w = bl_h = Math.max(bl_w,bl_h);
 hbw    = bl_w * .5;                // calculate half block width
 hbh    = bl_h * .5;                // calculate half block height
 if (shape < 1){
  draw_shape = function(){
   bl.moveTo (-hbw,-hbh);
   bl.lineTo (hbw,-hbh);
   bl.lineTo (hbw,hbh);
   bl.lineTo (-hbw,hbh);
  }
 } else if (shape > 2){
  if (shape == 3){ r0=.5; r1=1.2; r2=1; }else{ r0=1; r1=r2=.7; }
  draw_shape = function(){
   bl.moveTo( 0, -bl_h*r1);
   for (i=0;i<=6.28;i+=.628){              
    bl.curveTo(Math.sin(i-.314)*bl_w*r0,-Math.cos(i-.314)*bl_h*r0,Math.sin(i)*bl_w*r1,-Math.cos(i)*bl_h*r1);
    rt=r1; r1=r2; r2=rt;
   }
  }
 } else if (shape == 1){
  draw_shape = function(){
   bl.moveTo (-bl_w,0);
   bl.lineTo (0,-bl_h);
   bl.lineTo (bl_w,0);
   bl.lineTo (0,bl_h);
  }
 } else {
  br_x = hbw * 1.4; tl_x = - br_x;
  br_y = hbh * 1.4; tl_y = - br_y;
  cx = bl_w * .04;
  cy = bl_h * .04;
  draw_shape = function (){
   bl.moveTo ( 0, tl_y );
   bl.curveTo ( br_x-cx, tl_y+cy, br_x, 0 );
   bl.curveTo ( br_x-cx, br_y-cy, 0, br_y );
   bl.curveTo ( tl_x+cx, br_y-cy, tl_x, 0 );
   bl.curveTo ( tl_x+cx, tl_y+cy, 0, tl_y );
  }
 }
 s = out_effect ? 100 : 0;
 createEmptyMovieClip("msk",6);
 mc.setMask(msk);
 ba = []; bl_cnt = 0;
 for(r=0;r<rows;r++){
  for(c=0;c<cols;c++){
   msk.createEmptyMovieClip("b"+bl_cnt,bl_cnt);
   bl = ba[bl_cnt] = msk["b"+bl_cnt];
   bl.beginFill(0);
   draw_shape();
   bl.endFill();
   bl._i = bl_cnt;
   bl.__x = bl._x = b.xMin + (c+.5) * h_inc;
   bl.__y = bl._y = b.yMin + (r+.5) * v_inc;
   bl._xscale = bl._yscale = s;
   bl_cnt++;
  }
 }
}

// main_effect function

main_effect = function(mc,frame){
 if (frame > lastsubframe) {
  if (out_effect) mc._alpha = 0;
  mc.setMask(null);
  msk.removeMovieClip();
  end_effect = true;
 } else {
  perc = frame / lastsubframe;
  if (out_effect) perc = 1-perc;
  for (b=0; b<bl_cnt;b++){
   ba[b]._xscale = perc * 100;
   ba[b]._yscale = perc * 100;
   ba[b]._rotation = (perc-1) * rotate;
  }
 }
}
