
// 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
 hbw    = bl_w * .5;                // calculate half block width
 bl_h   = v_inc + .2;               // calculate block height
 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 > 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 * h_inc + hbw;
   bl.__y = bl._y = b.yMin + r * v_inc + hbh;
   v = var_size ? 1+Math.random()*.5 : 1;
   bl._xscale = bl._yscale = s * v;
   bl_cnt++;
  }
 }
 bl_fr  = bl_cnt / lastsubframe; // blocks per frame
 s = 100 - s;
 // sort block array
 if (block_order ==6 || block_order==7){
  f = function(){
   b = r*cols+c;
   $ta[ block_order % 2 ? bl_cnt-1-ai : ai ] = ba[b];
   ai++;
  }
  $ta = []; ai = r = r1 = c1 = 0;
  r2 = rows; c2 = cols;
  while (ai<bl_cnt){
   for (c=c1;c<c2;c++) f(); c--; r1++;
   for (r=r1;r<r2;r++) f(); r--; c2--;
   for (c=c2-1;c>=c1;c--) f(); c++; r2--;
   for (r=r2-1;r>=r1;r--) f(); r++; c1++;
  } 
  ba = $ta;
 } else {
  $ta = $smc; $tc = $sub_cnt;
  $smc = ba; $sub_cnt = bl_cnt; $ord(block_order); ba = $smc;
  $smc = $ta; $sub_cnt = $tc;
 }
}

// 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 {
  for (b = Math.floor((frame-1) * bl_fr); b < Math.floor(frame * bl_fr); b++){
   v = var_size ? 1+Math.random()*.5 : 1;
   ba[b]._xscale = s * v;
   ba[b]._yscale = s * v;
  }
 }
}

