// main_init function

main_init = function(mc){
 d = deg360 / 360 * effect_angle;
 part = function ( mc, nr, r ){
  r2 = r/2;
  mc.lineStyle();
  mc.beginFill(0);
  if (nr==0){
   mc.curveTo ( -r2, -r2, 0, -r );
   mc.curveTo ( -r, -r, -r, 0 );
   mc.curveTo ( -r2, r2, 0, 0 );
  } else if (nr==1){
   mc.curveTo ( r2, -r2, r, 0 );
   mc.curveTo ( r, -r, 0, -r );
   mc.curveTo ( -r2, -r2, 0, 0 );
  } else if (nr==2){
   mc.curveTo ( r2, r2, 0, r );
   mc.curveTo ( r, r, r, 0 );
   mc.curveTo ( r2, -r2, 0, 0 );
  } else {
   mc.curveTo ( -r2, r2, -r, 0 );
   mc.curveTo ( -r, r, 0, r );
   mc.curveTo ( r2, r2, 0, 0 );
  }
  mc.endFill();
 }
}

// main_effect function

main_effect = function(mc,frame){
 if (subs_done) end_effect = true;
}

// sub_init function

sub_init = function(mc){
 b = mc.getBounds(mc);
 p = $padding/2;
 rx = Math.max(-b.xMin,b.xMax)-p;
 ry = Math.max(-b.yMin,b.yMax)-p;
 mc.r = Math.sqrt(rx*rx+ry*ry);
 m = mc._parent;
 for (i=1;i<=4;i++) {
  m.createEmptyMovieClip("m"+i+"_"+mc._i,mc._i*10+i+5);
  msk = m["m"+i+"_"+mc._i];
  part(msk,i-1,mc.r);
  if (out_effect){
   msk._x = mc.__x;
   msk._y = mc.__y;
  } else {
   msk._x = Stage.width;
   msk._y = Stage.height;
  }  
 }  
 for (i=1;i<=3;i++){
  mc.duplicateMovieClip("c"+i+"_"+mc._i,mc._i*10+i);
  m["c"+i+"_"+mc._i].setMask(m["m"+i+"_"+mc._i]);
 }
 mc.setMask(m["m4_"+mc._i]);
}

// sub_effect function

sub_effect = function(mc,frame){
 perc = frame / lastsubframe;
 if (out_effect) perc = 1 - perc; 
 m = mc._parent;
 for (i=1;i<=4;i++){
  msk = m["m"+i+"_"+mc._i];
  if (i%2 || part4){
   px = msk._x = mc.__x - Math.cos(deg90 * i - d) * mc.r * (1-perc);
   py = msk._y = mc.__y - Math.sin(deg90 * i - d) * mc.r * (1-perc);
  } else {
   msk._x = px;
   msk._y = py;
  }
  msk._rotation = perc * effect_rotation;
  if (zoom) msk._xscale = msk._yscale = perc * 100;
 }
 if (frame == lastsubframe) {
  for (i=1;i<=4;i++){
   m["c"+i+"_"+mc._i].removeMovieClip();
   m["m"+i+"_"+mc._i].removeMovieClip();
  }
  if (out_effect) mc._alpha = 0;
  mc.done = true;
 }
}

