
// main_init function

main_init = function(mc){
 box = function ( mc, tl_x, tl_y, br_x, br_y ){
  mc.lineStyle();
  mc.beginFill(0);
  mc.moveTo (tl_x,tl_y);
  mc.lineTo (br_x,tl_y);
  mc.lineTo (br_x,br_y);
  mc.lineTo (tl_x,br_y);
  mc.endFill();
 }
 flame = function ( mc, tl_x, tl_y, br_x, br_y ){
  var mx = ( tl_x + br_x ) / 2; // horizontal midpoint
  var my = ( tl_y + br_y ) / 2; // vertical midpoint
  var cx = (br_x - tl_x) * .022; // correction horizontal
  var cy = (br_y - tl_y) * .022; // correction vertical 
  mc.lineStyle();
  var colors = [ 0xFF9F00, 0xFFCF00, 0xFFFF9F, 0xFFCF60 ];
  var alphas = [ 100, 100, 100, 0 ];
  var ratios = [ 0, 0x20, 0x66, 0xFF ];
  var matrix = { matrixType:"box", r:0 };
  matrix.x = tl_x;
  matrix.y = tl_y;
  matrix.w = (br_x-tl_x)*.9; 
  matrix.h = (br_y-tl_y)*1.5;
  mc.beginGradientFill( "radial", colors, alphas, ratios, matrix );
  mc.moveTo ( mx, tl_y );
  mc.curveTo ( br_x-cx, tl_y+cy, br_x, my );
  mc.curveTo ( br_x-cx, br_y-cy, mx, br_y );
  mc.curveTo ( tl_x+cx, br_y-cy, tl_x, my );
  mc.curveTo ( tl_x+cx, tl_y+cy, mx, tl_y );
  mc.endFill();
 }
 createEmptyMovieClip("fire",6); 
}

// main_effect function

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

// sub_init function

sub_init = function(mc){
 w = (mc._width - $padding);
 h = (mc._height - $padding);
 b = mc.getBounds(mc);
 mc._parent.createEmptyMovieClip("m"+mc._i,mc._i*10+6);
 msk = mc._parent["m"+mc._i];
 mc.setMask(msk);
 box (msk,b.xMin,b.yMin,b.xMax,b.yMax);
 msk._x = mc._x;
 msk._y = mc._y + (out_effect ? 0 : mc._height);
 fire.createEmptyMovieClip("f"+mc._i,mc._i);
 f = fire["f"+mc._i];
 flame(f,-w,-h*(high_flames ? 4 : 2),w,0);
 f.__x = mc._x;
 f.__y = mc._y+h/2;
 f._yscale = 0;
}

// sub_effect function

sub_effect = function(mc,frame){
 perc = frame / lastsubframe;
 msk = mc._parent["m"+mc._i];
 msk._y = mc._y + mc._height * (out_effect ? perc : 1-perc);
 f = fire["f"+mc._i];
 if (!calm_fire || frame % 2){
  f._x = f.__x + Math.random() * 2;
  f._y = f.__y + Math.random() * 2;
  f._xscale = (95 + Math.random() * 10)* Math.min(1,perc * 8);
  f._yscale = 85 + Math.random() * 30;
  f._rotation = Math.random() * 5 - 2.5;
 }
 f._alpha = (80 + Math.random() * 10)* Math.min(1,(1-perc) * 8);;
 if (frame == lastsubframe){
  if (out_effect) mc._alpha = 0;
  msk.removeMovieClip();
  mc.done=true;
 }
}

