//**********************************************/
//
//   Copyright 2008-2010, Flea Circus Games
//
//   All rights reserved
//
//   This code may not be used, in whole or
//   in part, without permission.
//
//
//**********************************************/
var EDITOR_VERSION = "1.51";
var RELEASE_DIR = "";
var ie = (document.all) ? true : false;
var ie7 = (ie && window.XMLHttpRequest) ? true : false;
var ie6 = (ie && ! ie7) ? true : false;
var ns6 = document.getElementById && ! ie;
var webkit = navigator.userAgent.indexOf("AppleWebKit") > -1;
var isChrome = navigator.userAgent.indexOf("Chrome") > -1;
var IS_DEMO = false;
var MODE_VIEW = 0;
var MODE_EDIT = 1;
var THROTTLE_SPACE_BAR = false;
var FIELD_SIZE_X = 876;
var FIELD_SIZE_Y = 450;
var MARCHER_SIZE_X = 18;
var MARCHER_SIZE_Y = 36;
var SET_BLOCK_SIZE_X = 15;
var MAX_SETS = 31;
var MIN_SETS = 8;
var MIN_SETS_DEMO = 4;
var MAX_SETS_DEMO = 11;
var MAX_SETS_BASIC = 31;
var MAX_SETS_BASIC_LOWER = 27;
var MAX_SETS_PREMIUM = 41;
var MAX_SETS_BASIC_GUARD = MAX_SETS + 4;
var SET_BLOCK_SIZE_X_PREMIUM = 15;
var MAX_RIPPLE_STEPS = 80;
var MAX_RIPPLE_SETS = 3;
var FRAME_MILLISECS = 1000;
var FRAME_MIN_MILLISECS = 275;
var FRAME_STEP_MILLISECS = 275;
var MAX_TWEEN_GAP_MS = 100;
var MAX_ANIM_GAP_MS = 150;
var FPS_DEFAULT = 30;
var FPS_IE = 40;
var FPS_WEBKIT = 40;
var PIXELS_PER_SEC = 100;
var MIN_TOSS_MILLISECS = 2000;
var FRAMES_PER_SEC = FPS_DEFAULT;
if (ie7)    FRAMES_PER_SEC = FPS_IE;
var MAX_GUARD_PER_SHOW = 36;
var BORDER_COLOR = "#3C8C3C";
var BORDER_COLOR_DARKER = "#398939";
var HASH_NONE = 0;
var HASH_HORIZONTAL = 1;
var HASH_VERTICAL = 2;
var DEFAULT_GRID = 1;
var NUM_GRIDS = 2;
var GRID_X_NAME = [ "<span style=\"color: #543\">OFF</span>", "ON"  ];
var GRID_X = [1, 9 ];
var GRID_X_NUDGE = [0, 1];
var SAVE_HEARTBEAT_MINS = 0.5;
var SAVE_HEARTBEATS_NORMAL = 10;
var SAVE_HEARTBEATS_SLOW = 30;
var SAVE_HEARTBEATS = SAVE_HEARTBEATS_NORMAL;
var AJAX_TIMEOUT_SECS = 16;
var MOUSE_DOWN = false;
var SET_CONFIG_PAUSE = 0;
var SET_CONFIG_PACE = 1;
var NUM_STEPS_PACE = 3;
var NUM_STEPS_PAUSE = 4;
var MARCHER_X = 0;
var MARCHER_Y = 1;
var NUM_GUARD_UNIFORMS = 6;
var NUM_IMG_FRAMES_GENERAL = 8;
var NUM_HORN_TYPES = 4;
var NUM_HORN_TYPES_PREMIUM = 8;
var MARCHER_STATE_SET = 0;
var MARCHER_STATE_PLAYING = 1;
var FRAME_BRASS_SET = 0;
var FRAME_BRASS_PLAY = 1;
var FRAME_SNARE_SET = 0;
var FRAME_SNARE_PLAY1 = 1;
var FRAME_SNARE_PLAY2 = 2;
var FRAME_TENOR_SET = 3;
var FRAME_TENOR_PLAY1 = 4;
var FRAME_TENOR_PLAY2 = 5;
var FRAME_PLATES_SET = 6;
var FRAME_PLATES_PLAY1 = 6;
var FRAME_PLATES_PLAY2 = 7;
var FRAME_BASS_LEFT = 0;
var FRAME_BASS_RIGHT = 1;
var FRAME_BASS_FRONT = 2;
var FRAME_GUARD_SET = 0;
var FRAME_GUARD_WORK = 1;
var SECTION_BRASS = 0;
var SECTION_SNARE = 1;
var SECTION_TENOR = 2;
var SECTION_BASS = 3;
var SECTION_GUARD = 4;
var SECTION_PLATES = 5;
var SECTION_PROP = 6;
var SECTION_METRONOME = 7;
var ANIM_NOINST = 30;
var ANIM_KNEEL = 3;
var ANIM_SPEED_MS = [];
ANIM_SPEED_MS[SECTION_GUARD] = 50;
ANIM_SPEED_MS[SECTION_SNARE] = 150;
ANIM_SPEED_MS[SECTION_TENOR] = 300;
ANIM_SPEED_MS[SECTION_PLATES] = 250;
ANIM_SPEED_MS[SECTION_BASS] = 0;
ANIM_SPEED_MS[SECTION_BRASS] = 0;
ANIM_SPEED_MS[SECTION_PROP] = 0;
ANIM_SPEED_MS[SECTION_METRONOME] = 0;
var ANIM_SPEED_MONKEY = 200;
var MARCHER_STATE_NAME = ["ATTENTION", "PLAYING", "BACKFIELD", "ARMS DOWN", "HIGH STICKING" ];
var HORN_NAME = [ "MELLOPHONE", "SOPRANO", "CONTRABASS", "BARITONE", "TROMBONE", "SAXOPHONE", "CLARINET", "FLUTE" ];
var CAPTION_LABEL = {};
CAPTION_LABEL[SECTION_BRASS] = 'Horns';
CAPTION_LABEL[SECTION_SNARE] = 'Snares';
CAPTION_LABEL[SECTION_TENOR] = 'Tenors';
CAPTION_LABEL[SECTION_BASS] = 'Basses';
CAPTION_LABEL[SECTION_GUARD] = 'Guard';
CAPTION_LABEL[SECTION_PLATES] = 'Cymbals';
var EQUIPMENT_FLAG = 0;
var EQUIPMENT_RIFLE = 1;
var EQUIPMENT_SABRE = 2;
var FFOHUL = [];
FFOHUL[1] = {  animSpeedMS : 200, lastAnimTime : 0, currentFrame : 0, numFrames : 4 };
FFOHUL[4] = {  animSpeedMS : 180, lastAnimTime : 0, currentFrame : 0, numFrames : 6 };
var ANIM = [];
ANIM[EQUIPMENT_FLAG] =
[
{  name : 'Pose', pose : 1, frames : [ 0 ], offset : [0,-6, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 1, frames : [ 8 ], offset : [0,-6, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 0, frames : [ 6 ], offset : [-2, 2, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 0, frames : [ 14 ], offset : [ 2, 2, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 3, frames : [ 16 ], offset : [0,-6, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 0, frames : [ 17 ], offset : [0, 0, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 2, frames : [ 7 ], offset : [-4, -5, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 1, frames : [ 15 ], offset : [4, -5, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 0, frames : [ 5 ], offset : [-10, 5, 0], animSpeedMS : 50 },
{  name : 'Pose', pose : 0, frames : [ 13 ], offset : [ 10, 5, 0], animSpeedMS : 50 },
{  name : 'Spin R', pose : 1, frames : [ 7,0,1,2,3,4,5,6, 7,0,1,2,3,4,5,6 ], animSpeedMS : 80, loopSpeedMS : 0, syncOffset : +1 },
{  name : 'Spin L', pose : 1, frames : [ 15,8,9,10,11,12,13,14, 15,8,9,10,11,12,13,14 ], animSpeedMS : 80, loopSpeedMS : 0, syncOffset : -1 },
{  name : 'Sweep R', pose : 1, frames : [ 3,4,5,6, 11,12,13,14, 3,4,5,6, 7,0,1,2,3,4,5,6, 11,12,13,14, 3,4,5,6, 11,12,13,14, 15,8,9,10,11,12,13,14 ], animSpeedMS : 100, loopSpeedMS : 0, subloopFrame : 19, syncOffset : +1 },
{  name : 'Sweep L', pose : 1, frames : [ 11,12,13,14, 3,4,5,6, 11,12,13,14, 15,8,9,10,11,12,13,14, 3,4,5,6, 11,12,13,14, 3,4,5,6, 7,0,1,2,3,4,5,6  ], animSpeedMS : 100, loopSpeedMS : 0, subloopFrame : 19, syncOffset : -1 },
{  name : 'Wave R', pose : 1, frames : [ 6,7,0,1,2,15, 8,9,10, 7,0,1,2, 14,14, 15,8,9,10, 6,7,0,1,15,8,9,10, 6 ], animSpeedMS : 100, loopSpeedMS : 0, syncOffset : +1 },
{  name : 'Wave L', pose : 1, frames : [ 14,15,8,9,10, 6,7,0,1,15,8,9,10, 6,6, 7,0,1,2,15, 8,9,10, 7,0,1,2, 14 ], animSpeedMS : 100, loopSpeedMS : 0, syncOffset : -1 },
{  name : 'Wave Once R', pose : 1, frames : [ 6,7,0,1,2,3, 13  ], animSpeedMS : 80, loopSpeedMS : 0, lastAnimTime : 0, frameNum : 0, fnf : true, FFPJVV : 0, loopNum : 0, syncOffset : +1 },
{  name : 'Wave Once L', pose : 1, frames : [ 14,15,8,9,10,11,5  ], animSpeedMS : 80, loopSpeedMS : 0, lastAnimTime : 0, frameNum : 0, fnf : true, FFPJVV : 0, loopNum : 0, syncOffset : -1 },
{  name : 'Toss - Low', pose : 1, frames : [ 7,0,1,2,3,4,5,6, 7,0,1,2,3,4,5,6 ], animSpeedMS : 80, loopSpeedMS : 0, doToss : true, tossAnimNum : 1, tossDelayMS :  100, smoothToss : true, tossRight : true },
{  name : 'Toss - Med', pose : 1, frames : [ 7,0,1,2,3,4,5,6, 7,0,1,2,3,4,5,6 ], animSpeedMS : 80, loopSpeedMS : 0, doToss : true, tossAnimNum : 2, tossDelayMS :  0, smoothToss : true, tossRight : true },
{  name : 'Toss - High', pose : 1, frames : [ 7,0,1,2,3,4,5,6, 7,0,1,2,3,4,5,6 ], animSpeedMS : 80, doToss : true, tossAnimNum : 3, tossDelayMS :  -200, smoothToss : true, tossRight : true },
{  name : 'Toss - Float', pose : 1, frames : [ 7,0,1,2,3,4,5,6, 7,0,1,2,3,4,5,6 ], animSpeedMS : 80, doToss : true, tossAnimNum : 4, tossDelayMS :  -200, smoothToss : true, tossRight : true }
];
ANIM[EQUIPMENT_RIFLE] =
[
{  name : 'Pose', pose : 0, frames : [ 0 ], offset : [0,1, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 1, frames : [ 1 ], offset : [0,-2, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 2, frames : [ 9 ], offset : [0,-2, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 7, frames : [ 10 ], offset : [3, -4, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 6, frames : [ 2 ], offset : [-3, -4, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 7, frames : [ 2 ], offset : [-4, 5, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 6, frames : [ 10 ], offset : [4, 5, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 0, frames : [ 15 ], offset : [-9, 4, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Pose', pose : 0, frames : [ 7 ], offset : [9,4, 0], animSpeedMS : 0, lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 },
{  name : 'Spin R', pose : 7, frames : [ 5,6,7,0,1,2,3,4 ], offset : [4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, syncOffset : -1 },
{  name : 'Spin L', pose : 6, frames : [ 7,6,5,4,3,2,1,0 ], offset : [-4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, syncOffset : +1 },
{  name : 'Spin R - Faster', pose : 7, frames : [ 5,6,7,0,1,2,3,4 ], offset : [4, 0, 0], animSpeedMS : 50, loopSpeedMS : 0, syncOffset : -1 },
{  name : 'Spin L - Faster', pose : 6, frames : [ 7,6,5,4,3,2,1,0 ], offset : [-4, 0, 0], animSpeedMS : 50, loopSpeedMS : 0, syncOffset : +1 },
{  name : 'Work R', pose : 7, frames : [ 1,2,3,4,5,5,5, 4,3,2,1,0,7,6,5,4,3,2,1,0,7,6,5, 6,7,0   ], offset : [4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, syncOffset : -1 },
{  name : 'Work L', pose : 6, frames : [ 3,2,1,0,7,7,7, 0,1,2,3,4,5,6,7, 0,1,2,3,4,5,6,7, 6,5,4  ], offset : [-4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, syncOffset : +1 },
{  name : 'Work R - Faster', pose : 7, frames : [ 1,2,3,4,5,5,5, 4,3,2,1,0,7,6,5,4,3,2,1,0,7,6,5, 6,7,0   ], offset : [4, 0, 0], animSpeedMS : 50, loopSpeedMS : 0, syncOffset : -1 },
{  name : 'Work L - Faster', pose : 6, frames : [ 3,2,1,0,7,7,7, 0,1,2,3,4,5,6,7, 0,1,2,3,4,5,6,7, 6,5,4  ], offset : [-4, 0, 0], animSpeedMS : 50, loopSpeedMS : 0, syncOffset : +1 },
{  name : 'Toss - Double', pose : 6, frames : [ 7,6,5,4,3,2,1,0 ], offset : [-4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, doToss : true, tossAnimNum : 1, tossDelayMS : 200 },
{  name : 'Toss - Triple', pose : 6, frames : [ 7,6,5,4,3,2,1,0 ], offset : [-4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, doToss : true, tossAnimNum : 2, tossDelayMS :  0 },
{  name : 'Toss - Quad', pose : 6, frames : [ 7,6,5,4,3,2,1,0 ], offset : [-4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, doToss : true, tossAnimNum : 3, tossDelayMS : -200 },
{  name : 'Toss - Float', pose : 6, frames : [ 7,6,5,4,3,2,1,0 ], offset : [-4, 0, 0], animSpeedMS : 75, loopSpeedMS : 0, doToss : true, tossAnimNum : 4, tossDelayMS : -100 }
];
ANIM[EQUIPMENT_SABRE] = deepObjCopy( ANIM[EQUIPMENT_RIFLE] );
var TOSS_ANIM = [];
TOSS_ANIM[EQUIPMENT_RIFLE] =
[
{  name : 'Catch', pose : 6, frames : [ 0 ], offset : [0, 2, 0], animSpeedMS : 30, loopSpeedMS : 0, doToss: true },
{  name : 'Double', pose : 5, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 30, loopSpeedMS : 0, tossSpeed : 4.5, doToss: true },
{  name : 'Triple', pose : 5, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 30, loopSpeedMS : 0, tossSpeed : 5.75, doToss: true },
{  name : 'Quad', pose : 5, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 30, loopSpeedMS : 0, tossSpeed : 7.5, doToss: true },
{  name : 'Float', pose : 5, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 60, loopSpeedMS : 0, tossSpeed : 7.25, doToss: true }
];
TOSS_ANIM[EQUIPMENT_SABRE] = deepObjCopy( TOSS_ANIM[EQUIPMENT_RIFLE] );
TOSS_ANIM[EQUIPMENT_FLAG] =
[
{  name : 'Catch', pose : 3, frames : [ 4 ], offset : [0, 2, 0], animSpeedMS : 30, loopSpeedMS : 0, doToss: true },
{  name : 'Toss - Low', pose : 3, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 40, loopSpeedMS : 0, tossSpeed : 4.5, catchFrame : -1, doToss: true },
{  name : 'Toss - Med', pose : 3, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 40, loopSpeedMS : 0, tossSpeed : 5.5, catchFrame : -1, doToss: true },
{  name : 'Toss - High', pose : 3, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 40, loopSpeedMS : 0, tossSpeed : 6.5, catchFrame : 4, doToss: true },
{  name : 'Toss - Float', pose : 3, frames : [ 0,1,2,3,4,5,6,7 ], offset : [0, 0, 0], animSpeedMS : 80, loopSpeedMS : 0, tossSpeed : 7.25, catchFrame : -1, doToss: true }
];
var FFMAJI = {};
var NUM_ANIMS = [];
NUM_ANIMS[EQUIPMENT_FLAG] = ANIM[EQUIPMENT_FLAG].length;
NUM_ANIMS[EQUIPMENT_RIFLE] = ANIM[EQUIPMENT_RIFLE].length;
NUM_ANIMS[EQUIPMENT_SABRE] = NUM_ANIMS[EQUIPMENT_RIFLE];
var FFDKIM = [];
FFDKIM[EQUIPMENT_FLAG] = [3,2,1,1,3,2,3,1,3,1,3,1,3,2,3,1,3,2,3,0];
FFDKIM[EQUIPMENT_RIFLE] = [3,2,1,1,3,2,3,1,3,1,3,1,3,2,3,1,3,2,3,0];
FFDKIM[EQUIPMENT_SABRE] = FFDKIM[EQUIPMENT_RIFLE].slice();
var NUM_DEFAULT_FLAG_ANIMS = 6;
var TOSS_GRAVITY = 0.35;
var FFILEM = [];
FFILEM[EQUIPMENT_FLAG] = 3;
FFILEM[EQUIPMENT_RIFLE] = 0;
FFILEM[EQUIPMENT_SABRE] = 0;
var NUM_FLAG_POSES = 10;
var FLAG_IMG_SIZE_X = 648;
var FLAG_IMG_SIZE_Y = 216;
function reset_anims (resetAll)
{
if (resetAll)  FFMAJI = {};
return;
for (var i = 0; i < ANIM[EQUIPMENT_FLAG].length; i ++)
{
if (resetAll || ANIM[EQUIPMENT_FLAG].fnf || ANIM[EQUIPMENT_FLAG].FFPJVV < EDITOR.show.FFPJVV - 1)
{
ANIM[EQUIPMENT_FLAG][i].frameNum = 0;
ANIM[EQUIPMENT_FLAG][i].lastAnimTime = 0;
ANIM[EQUIPMENT_FLAG][i].FFPJVV = 0;
}
}
for (var i = 0; i < ANIM[EQUIPMENT_RIFLE].length; i ++)
{
if (resetAll || ANIM[EQUIPMENT_RIFLE].fnf || ANIM[EQUIPMENT_RIFLE].FFPJVV < EDITOR.show.FFPJVV - 1)
{
ANIM[EQUIPMENT_RIFLE][i].frameNum = 0;
ANIM[EQUIPMENT_RIFLE][i].lastAnimTime = 0;
ANIM[EQUIPMENT_RIFLE][i].FFPJVV = 0;
}
}
}
var NUM_UNIFORMS = 6;
var NUM_DEFAULT_FLAG_COLORS = 6;
var NUM_PREMIUM_FLAG_COLORS = 4;
var SHOW_UNIFORM = 0;
var SHOW_FLAG1 = 1;
var SHOW_GUARD_UNIFORM = 2;
var SHOW_TOOL_MENU = false;
var SHOW_TOOL_MENU2 = false;
var EDITOR;
var LOADED;
var sets = [];
var setConfig = [];
var showConfig = [];
var mouseMoveTick = 0;
var MAX_UNDO_STATES = 128;
var GROUP_TYPE_CORPS = 0;
var GROUP_TYPE_BRASS = 1;
var GROUP_TYPE_GUARD = 2;
var GROUP_TYPE_DRUMLINE = 3;
var GROUP_SIZE_DEMO = 0;
var GROUP_SIZE_FAN = 1;
var GROUP_SIZE_NORMAL = 2;
var GROUP_SIZE_PREMIUM = 3;
var LINE_DELIM = "//"
var GROUP_SHOW_DATA = [];
GROUP_SHOW_DATA[GROUP_TYPE_CORPS] = [];
GROUP_SHOW_DATA[GROUP_TYPE_BRASS] = [];
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE] = [];
GROUP_SHOW_DATA[GROUP_TYPE_GUARD] = [];
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_FAN] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_FAN] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_FAN] += "marcher=00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|10|10|10|10|10|20|20|20|30|30|30|30|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_FAN] += "set=00|xbx71|xbxA1|xby31|xbyv1|xbyY1|xbzr1|xDx71|xDxA1|xDy31|xDyv1|xDyY1|xDzr1|y6x71|y6xA1|y6y31|y6yv1|y6yY1|y6zr1|yzx71|yzxA1|yzy31|yzyv1|yzyY1|yzzr1|z2x71|z2xA1|z2y31|z2yv1|z2yY1|z2zr1|zvx71|zvxA1|zvy31|zvyv1|zvyY1|zvzr1|AFwa1|Bfwa1|BPwa1|Cpwa1|CZwa1|ylwa1|yVwa1|zvwa1|E9wa0|EJwa0|Fjwa0|FTwa0|E9zq1|EVzq1|FHzq1|Gtzq1|E9yE1|EVyE1|FHyE1|GtyE1|E9x61|FHx61|E9xS1|FHxS1|EVx61|Gtx61|EVxS1|GtxS1" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_FAN] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_NORMAL] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_NORMAL] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_NORMAL] += "marcher=02|02|00|00|00|01|01|02|02|00|00|00|01|01|02|02|00|00|00|01|01|02|00|00|00|00|01|01|02|00|00|00|00|01|01|02|00|00|00|01|01|01|02|00|00|00|01|01|01|10|10|10|10|10|10|10|20|20|20|20|30|30|30|30|30|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_NORMAL] += "set=00|xax21|xaxo1|xaxL1|xay71|xayu1|xayQ1|xazd1|xyx21|xyxo1|xyxL1|xyy71|xyyu1|xyyQ1|xyzd1|xWx21|xWxo1|xWxL1|xWy71|xWyu1|xWyQ1|xWzd1|ykx21|ykxo1|ykxL1|yky71|ykyu1|ykyQ1|ykzd1|yIx21|yIxo1|yIxL1|yIy71|yIyu1|yIyQ1|yIzd1|z6x21|z6xo1|z6xL1|z6y71|z6yu1|z6yQ1|z6zd1|zux21|zuxo1|zuxL1|zuy71|zuyu1|zuyQ1|zuzd1|AEx21|B2x21|Bqx21|BOx21|Ccx21|CAx21|CYx21|AEwj1|Bqwj1|Ccwj1|CYwj1|AEvA0|BevA0|BOvA0|CovA0|CYvA0|E8x20|EUx20|FGx20|Gsx20|E8yu0|EUyu0|FGyu0|Gsyu0|E8xL0|EUxL0|FGxL0|GsxL0|E8zd0|EUzd0|FGzd0|Gszd0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_NORMAL] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_PREMIUM] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_PREMIUM] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_PREMIUM] += "marcher=00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|10|10|10|10|10|10|10|10|10|20|20|20|20|20|30|30|30|30|30|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_PREMIUM] += "set=00|xawo1|xawJ1|xax41|xaxp1|xaxK1|xay51|xayq1|xayL1|xuwo1|xuwJ1|xux41|xuxp1|xuxK1|xuy51|xuyq1|xuyL1|xPwo1|xPwJ1|xPx41|xPxp1|xPxK1|xPy51|xPyq1|xPyL1|y9wo1|y9wJ1|y9x41|y9xp1|y9xK1|y9y51|y9yq1|y9yL1|yuwo1|yuwJ1|yux41|yuxp1|yuxK1|yuy51|yuyq1|yuyL1|yOwo1|yOwJ1|yOx41|yOxp1|yOxK1|yOy51|yOyq1|yOyL1|z9wo1|z9wJ1|z9x41|z9xp1|z9xK1|z9y51|z9yq1|z9yL1|zuwo1|zuwJ1|zux41|zuxp1|zuxK1|zuy51|zuyq1|zuyL1|AExb1|AWxb1|Bexb1|Bwxb1|BOxb1|C6xb1|Coxb1|CGxb1|CYxb1|AEws1|Bews1|BOws1|Cows1|CYws1|AEvJ0|BevJ0|BOvJ0|CovJ0|CYvJ0|E8yM1|E8ya1|EIya1|Fiya1|FSya1|Gsya1|GsyM1|E8xy1|EIxy1|Fixy1|FSxy1|Gsxy1|FSyM1|E8wW1|EIwW1|FiwW1|FSwW1|GswW1|FiyM1|E8wl1|EIwl1|Fiwl1|FSwl1|Gswl1|EIyM1" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_CORPS][GROUP_SIZE_PREMIUM] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_BRASS][GROUP_SIZE_NORMAL] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_BRASS][GROUP_SIZE_NORMAL] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_BRASS][GROUP_SIZE_NORMAL] += "marcher=03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03|03" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_BRASS][GROUP_SIZE_NORMAL] += "set=00|A5wl1|C4wQ1|C4yO1|A5zj1|A5wQ1|A5xP1|C4xk1|C4xP1|AAwl1|CywQ1|CyyO1|AAzj1|AAwQ1|AAxP1|Cyxk1|CyxP1|B5wl1|D3wQ1|D3yO1|B5zj1|B5wQ1|B5xP1|D3xk1|D3xP1|Bzwl1|DywQ1|DyyO1|Bzzj1|BzwQ1|BzxP1|Dyxk1|DyxP1|C4wl1|B5xk1|A5xk1|A5yk1|A5yO1|A5zN1|C4yk1|C4zj1|Cywl1|Bzxk1|AAxk1|AAyk1|AAyO1|AAzN1|Cyyk1|Cyzj1|D3wl1|B5yk1|C4zN1|DyzN1|B5yO1|B5zN1|D3yk1|D3zj1|Dywl1|Bzyk1|CyzN1|D3zN1|BzyO1|BzzN1|Dyyk1|Dyzj1" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_BRASS][GROUP_SIZE_NORMAL] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_NORMAL] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_NORMAL] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_NORMAL] += "marcher=40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_NORMAL] += "set=00|Cgy32|CgwB2|zuzv2|Cgzv2|CgyM2|Dcy32|DcwB2|Apzv2|Dczv2|DcyM2|E8y32|E8wB2|Blzv2|E8zv2|E8yM2|zuwB2|zuxk2|Cgxk2|zuyM2|zuy32|ApwB2|Apxk2|Dcxk2|ApyM2|Apy32|BlwB2|Blxk2|E8xk2|BlyM2|Bly32" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_NORMAL] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_PREMIUM] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_PREMIUM] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_PREMIUM] += "marcher=40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40|40" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_PREMIUM] += "set=00|Beyo2|Dywj2|yUzN2|CozN2|Coyo2|Dyyo2|EIwj2|A4zN2|DyzN2|Dyz52|EIyo2|EIx02|BezN2|EIzN2|EIz52|yUwj2|yUx02|Dyx02|yUz52|yUxH2|A4wj2|A4x02|CoxH2|A4z52|A4xH2|Bewj2|Bex02|DyxH2|Bez52|BexH2|yUyo2|Cowj2|Cox02|EIxH2|Coz52|A4yo2" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_GUARD][GROUP_SIZE_PREMIUM] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_NORMAL] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_NORMAL] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_NORMAL] += "marcher=10|10|10|10|10|10|10|10|10|20|20|20|20|20|30|30|30|30|30|50|50|50|50|50" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_NORMAL] += "set=00|AEz41|AWz41|Bez41|Bwz41|BOz41|C6z41|Coz41|CGz41|CYz41|AEyl1|Beyl1|BOyl1|Cnyl1|CXyl1|AExC0|BexC0|BOxC0|CnxC0|CXxC0|AEwT1|BewT1|BOwT1|CnwT1|CXwT1//[end]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_NORMAL] += "[end]";
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_PREMIUM] = "[begin]" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_PREMIUM] += "show=0|0|0" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_PREMIUM] += "marcher=10|10|10|10|10|10|10|10|10|10|20|20|20|20|20|30|30|30|30|30|50|50|50|50|50|50|50|50|50|50" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_PREMIUM] += "set=00|A2yV1|AyyV1|B4yV1|BAyV1|C6yV1|D8yV1|EayV1|CCyV1|DEyV1|zwyV1|A0xU1|B2xU1|ByxU1|AwxU1|zuxU1|C4xU0|CAxU0|D6xU0|DCxU0|E8xU0|zuwT1|A0wT1|B2wT1|C4wT1|AwwT1|BywT1|CAwT1|D6wT1|DCwT1|E8wT1" + LINE_DELIM;
GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][GROUP_SIZE_PREMIUM] += "[end]";
var USE_DEFAULT_SHOW_DATA = true;
function oEditor ()
{
var self = this;
this.isPlaying = false;
this.mode = MODE_VIEW;
this.authorID = 0;
this.wipID = 0;
this.is3D = false;
this.trialGroup = 0;
this.showTitle = "";
this.isPremium = false;
this.isDemo = false;
this.isGroupSnapshot = false;
this.div = $('editor');
this.dragOriginX = 0;
this.dragOriginY = 0;
this.selectBox = $('selectbox');
this.selectBoxX = 0;
this.selectBoxY = 0;
this.selectBoxActive = false;
this.FFFMJP = [];
this.FFTBGP = [];
this.marcherById = [];
this.clipboard = [];
this.FFBPXP = null;
this.cursorInEditor = false;
this.show = new oShow();
this.showID = 0;
this.snapX = DEFAULT_GRID;
this.isPostEdit = false;
this.doShowHelp = true;
this.helpLevel = 0;
this.snapLevel = 0;
this.isRestored = false;
this.isJudge = false;
this.isPreview = false;
this.didVote = false;
this.setIsChanged = false;
this.stateIsChanged = false;
this.showIsChanged = false;
this.lastActionID = "";
this.FFIRFF = "";
this.isAddingSet = false;
this.FFCIBA = null;
this.leader = null;
this.isDragging = false;
this.didDrag = false;
this.isFineSelect = false;
this.lastMouseMove = 0;
this.scaleOffsetsSet = false;
this.saveIntervalID = 0;
this.isSaving = false;
this.isPublished = false;
this.hasVoted = false;
this.showPins = true;
this.doAutoSave = true;
this.lastSaveTime = 0;
this.lockAutoSave = false;
this.postSaveAction = "";
this.statusHidden = false;
this.FFEQJR = [[]];
this.FFJBQV = [[]];
this.pauseKeyListener = false;
this.fakeCtrl = false;
this.quickSelect = false;
this.isWandSelect = false;
this.isSlowPlay = false;
this.isFastPlay = false;
this.isAnalyze = false;
this.isRecordMode = false;
this.animKeyDown = false;
this.animScrolled = false;
this.animScroll = false;
this.numSaveAttempts = 0;
this.numSaveHeartbeats = 0;
this.doPublishAfterSave = false;
this.isIndoor = false;
this.groupType = GROUP_TYPE_CORPS;
this.hashState = 0;
this.mouseX = 0;
this.mouseY = 0;
this.numSelected = 0;
this.prevSetBlock = false;
this.saveBlockedByStudio = false;
this.cheats = {};
this.hasProps = false;
this.metronome = null;
this.numFlags = NUM_DEFAULT_FLAG_COLORS;
this.flagImg = null;
this.weaponImg = null;
this.spriteURL =
{
musician    : null,
flag        : imageUrl("sprites/flag.png"),
guard       : imageUrl("sprites/guard.png"),
weapon      : imageUrl("sprites/weapon.png"),
prop        : null
};
this.spriteImg = {};
this.newSprite = function (type)
{
if (! this.spriteImg[type])
{
var s = new Image ();
s.src = this.spriteURL[type];
this.spriteImg[type] = s;
return s.cloneNode(true);
}
else
{
return this.spriteImg[type].cloneNode(true);
}
};
this.newBlip = function (elid, color)
{
var blip = document.createElement('DIV');
blip.style.height = "3px";
blip.style.width = "3px";
blip.style.zIndex = "2000";
blip.style.position = "absolute";
blip.style.backgroundColor = color;
blip.id = elid;
$('editor').appendChild(blip);
return blip;
};
this.moveBlip = function (elid, x, y)
{
$(elid).style.top = y;
$(elid).style.left = x;
$(elid).style.display = 'none';
};
this.clearBlip = function (bid)
{
$('editor').removeChild( $(bid) );
};
this.initEditMode = function (authorID)
{
this.authorID = authorID;
this.mode = MODE_EDIT;
this.initEvents();
this.redrawSetPanel();
if (! IS_DEMO && ! this.isGroupSnapshot)
this.saveIntervalID = setInterval('EDITOR.show.ajaxSave(true)', SAVE_HEARTBEAT_MINS * 60 * 1000);
addCSSRule(".marcher", "cursor:move");
addCSSRule(".equipment", "cursor:move");
if (EDITOR.groupType >= 2)
{
addCSSRule(".setpin", "background-color: #7EAA84");
}
if (this.spriteURL['flag'])
{
var flagImg = new Image();
flagImg.src = this.spriteURL['flag'];
EDITOR.numFlags = (EDITOR.isPremium) ? NUM_PREMIUM_FLAG_COLORS : NUM_DEFAULT_FLAG_COLORS;
EDITOR.spriteImg['flag'] = flagImg;
}
$('playlink').onclick = function (e)
{
var evt = e || window.event;
var target = evt.target || evt.srcElement;
if (evt.ctrlKey || EDITOR.isFakeCtrl)
{
EDITOR.isSlowPlay = true;
}
$('null').focus();
EDITOR.show.pressPlay();
return false;
};
if (EDITOR.snapLevel > 0)
{
this.snapX = 0;
}
};
this.initViewMode = function ()
{
if (! EDITOR.isGroupSnapshot)
{
listenForKeyPressView();
}
if (EDITOR.isPreview && $('bottomplaylink'))
{
$('bottomplaylink').onclick = function (e)
{
EDITOR.show.play();
return false;
};
}
};
this.load_sprites = function (fnMainStart)
{
var urls = [];
for (var spriteType in EDITOR.spriteURL)
{
if (EDITOR.spriteURL[spriteType])
{
urls.push(EDITOR.spriteURL[spriteType]);
}
}
var numImagesLoaded = 0;
for (var i=0; i < urls.length; i++)
{
var img = new Image();
img.onload = function ()
{
++ numImagesLoaded;
if (numImagesLoaded >= urls.length)
{
fnMainStart();
}
};
img.onerror = img.onload;
img.src = urls[i];
}
};
this.reload_sprite = function (spriteType, url)
{
this.spriteURL[spriteType] = url;
for (var i=0,m; m = this.show.marchers[i]; i++)
{
if (m.section == SECTION_METRONOME)
{
}
else if (m.section == SECTION_PROP)
{
if (spriteType == 'prop')
{
m.loadCustomProp(url);
}
}
else if (spriteType == 'musician' && m.section != SECTION_GUARD)
{
m.loadCustomUniform(url);
}
else if (m.section == SECTION_GUARD)
{
if (spriteType == 'guard')
{
m.loadCustomUniform(url);
}
else if (spriteType == 'flag')
{
m.loadCustomFlag(url);
}
}
}
};
this.updateSpriteSizes = function ()
{
if (! ie) { return false; }
for (var i=0, m; m = this.show.marchers[i]; i++)
{
if (m.section == SECTION_GUARD)
{
m.img.width = 144;
m.equipment.img.width = FLAG_IMG_SIZE_X;
m.equipment.img.height = FLAG_IMG_SIZE_Y;
}
}
};
this.addExtraSets = function ()
{
if (this.isPremium)
{
MAX_SETS = MAX_SETS_PREMIUM;
SET_BLOCK_SIZE_X = SET_BLOCK_SIZE_X_PREMIUM;
}
else if (this.groupType == GROUP_TYPE_GUARD)
{
MAX_SETS = MAX_SETS_BASIC_GUARD;
}
else if (EDITOR.trialGroup >= 3)
{
MAX_SETS = MAX_SETS_BASIC_LOWER;
}
else if (EDITOR.trialGroup >= 2)
{
MAX_SETS = MAX_SETS_BASIC;
}
};
this.redrawSetPanel = function ()
{
if (this.mode == MODE_EDIT)
{
$('setgraph').innerHTML = '';
for (i=0; i <= this.show.maxSet; i++)
{
this.addSetToGraph(i);
}
updateAddSetLink();
for (i=0; i <= this.show.maxSet; i++)
{
this.redrawSetBlock(i);
}
this.show.redrawSetConfig();
}
};
this.addSetToGraph = function (setNum)
{
var setWidth = SET_BLOCK_SIZE_X;
var add = '<a href="#" id="setblock'+setNum+'" class="setblock" title="Set '+ (setNum+1) +'" onClick="EDITOR.show.forceJumpToSet(' + setNum + '); return false">';
add += '<img src="' + imageUrl('show/pixel.gif') + '" style="width:'+setWidth+'px;" id="setblockimg'+setNum+'" title="Set '+setNum+'">';
add += '</a>';
$('setgraph').innerHTML += add;
this.redrawSetBlock(setNum);
};
this.toggleHashes = function (isCtrl)
{
var newHashState = 0;
if (this.hashState > 0)
{
newHashState = HASH_NONE;
}
else if (isCtrl)
{
newHashState = HASH_VERTICAL;
}
else
{
newHashState = HASH_HORIZONTAL;
}
if (newHashState == 0)
{
this.hashState = 0;
$('hashX').style.display = 'none';
$('hashY').style.display = 'none';
}
else if (newHashState == HASH_VERTICAL)
{
var doShow = false;
if (this.FFBPXP)
{
doShow = true;
var markerX = this.FFBPXP.x + ((this.FFBPXP.imgSizeX / 2) >> 0) - 1;
markerX += (this.FFBPXP.section == SECTION_BASS) ? -9 : 0;
$('hashY').style.left = markerX + 'px';
}
else if (this.cursorInEditor)
{
var editorX = (document.body.clientWidth - FIELD_SIZE_X) / 2;
var markerX = this.mouseX - editorX - 5;
$('hashY').style.left = markerX + 'px';
doShow = true;
}
if (doShow)
{
this.hashState = newHashState;
$('hashX').style.display = 'none';
$('hashY').style.display = 'block';
}
}
else if (newHashState == HASH_HORIZONTAL)
{
var doShow = false;
if (this.FFBPXP)
{
doShow = true;
var markerY = this.FFBPXP.y + this.FFBPXP.imgSizeY - 3;
$('hashX').style.top = markerY + 'px';
}
else if (this.cursorInEditor && ! isCtrl)
{
var editorY = 70;
var markerY = this.mouseY - editorY;
$('hashX').style.top = markerY + 'px';
doShow = true;
}
else if (isCtrl)
{
doShow = true;
}
if (doShow)
{
this.hashState = newHashState;
$('hashY').style.display = 'none';
$('hashX').style.display = 'block';
}
}
};
this.highlightSetBlock = function (setNum)
{
var block = $('setblock'+setNum);
if (block)
{
if (this.prevSetBlock)
{
this.prevSetBlock.style.backgroundColor = '#97D2A2';
}
block.style.backgroundColor = '#fff';
this.prevSetBlock = block;
this.setGraphNumber(setNum);
}
};
this.redrawSetBlock = function (setNum)
{
var block = $('setblock'+setNum);
if (block)
{
if (this.show.setConfig[setNum])
{
bwidth = 1 + this.show.setConfig[setNum][SET_CONFIG_PAUSE];
block.style.borderLeft = "solid " + bwidth + "px #40854F";
block.style.width = px((SET_BLOCK_SIZE_X + 1) - bwidth);
$('setblockimg'+setNum).style.width = px((SET_BLOCK_SIZE_X + 1) - bwidth);
}
else
{
block.style.width = SET_BLOCK_SIZE_X + "px";
}
this.setGraphNumber(this.show.FFPJVV);
}
};
this.updateStatus = function (msg, checkOrder)
{
var tag = checkOrder && this.show.isOrderSelected() ? ' &rArr;' : '';
$('editstatus').innerHTML = msg + tag;
$('editstatus').style.display = 'block';
};
this.hideStatus = function (msg)
{
$('editstatus').style.display = 'none';
};
this.updateSelectedStatus = function ()
{
if (this.FFFMJP.length < 2)
{
this.hideStatus();
}
else
{
if (this.numSelected != this.FFFMJP.length)
{
this.updateStatus(this.FFFMJP.length + " selected", true);
this.numSelected = this.FFFMJP.length;
}
}
};
this.setGraphNumber = function (setNum)
{
$('setsvalue').innerHTML = (this.show.FFPJVV + 1);
};
this.showOverlay = function (op)
{
if (this.mode == MODE_EDIT) {  return false; }
if (this.isRecordMode)  return false;
if (! defined(op))
{
op = 0;
$('editoroverlay').style.visibility = "visible";
setAlpha('editoroverlay', 0);
if (this.isJudge)
{
$('author').style.visibility = 'hidden';
$('authordrop').style.visibility = 'hidden';
}
}
if (op > 100) {  op = 100; }
setAlpha('editoroverlay', op);
if (op < 100)
{
setTimeout("EDITOR.showOverlay("+ (op + 20) +")", 10);
}
};
this.hideOverlay = function (op)
{
if (this.mode == MODE_EDIT) {  return false; }
if (! defined(op))
{
EDITOR.overlayFadeStart = get_now();
}
op = (100 - (get_now() - EDITOR.overlayFadeStart) / 1.5) >> 0;
setAlpha('editoroverlay', op);
if ($('showdesc'))
setAlpha('showdesc', op);
if (op > 0)
{
setTimeout("EDITOR.hideOverlay("+ op +")", 10);
}
else
{
$('editoroverlay').style.visibility = "hidden";
if ($('showdesc'))
$('showdesc').style.display = "none";
}
};
this.toggleRecordMode = function ()
{
if (this.isPlaying)  return false;
this.isRecordMode = this.isRecordMode ? false : true;
if (this.isRecordMode)
{
this.hideOverlay();
show('bottomplaylink');
}
else
{
this.showOverlay();
hide('bottomplaylink');
}
};
this.resetSelectBox = function ()
{
this.selectBoxX = 0;
this.selectBoxY = 0;
this.selectBox.style.left = "0px";
this.selectBox.style.top = "0px";
this.selectBox.style.height = "1px";
this.selectBox.style.width = "1px";
this.selectBox.style.visibility = "hidden";
this.selectBoxActive = false;
};
this.initEvents = function ()
{
document.ondblclick = doubleClick;
document.onmousedown = mouseDown;
document.onmousemove = this.mouseMove;
document.onmouseup = mouseUp;
document.onmouseover = mouseOver;
document.onmouseout = mouseOut;
this.div.onmouseover = function () {  EDITOR.cursorInEditor = true; };
this.div.onmouseout = function () {  EDITOR.cursorInEditor = false; };
if (window.addEventListener)
{
window.addEventListener('DOMMouseScroll', wheel, false);
}
window.onmousewheel = document.onmousewheel = wheel;
window.onbeforeunload = function ()
{
if (EDITOR.showIsChanged && ! IS_DEMO && ! EDITOR.isPostEdit && ! EDITOR.isGroupSnapshot)
{
return 'There are unsaved changes to your show.';
}
else
{
return;
}
};
listenForKeyPress();
};
this.pauseEvents = function ()
{
document.onmousedown = function () {  return true; };
this.pauseKeyListener = true;
};
this.FFUXRH = function (actionID, selectOnly)
{
if (actionID != 'arc')
{
EDITOR.resetArc();
}
this.stateIsChanged = true;
this.showIsChanged = true;
if (this.show.FFPJVV == this.show.maxSet)
{
this.setIsChanged = true;
updateAddSetLink();
}
if (EDITOR.show.FFPJVV == 0 || EDITOR.show.FFPJVV == 1)
{
hide('help');
hide('groupselect');
}
else if (EDITOR.isRestored && EDITOR.helpLevel < 1)
{
hide('help');
}
this.addToHistory(actionID, selectOnly);
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
};
this.FFGJOC = function (addToHistory)
{
if (addToHistory && this.FFFMJP.length > 1)
{
EDITOR.FFUXRH('clearselection', true);
}
this.FFCIBA = null;
for (i=0; i < this.FFFMJP.length; i++)
{
this.FFFMJP[i].deselect();
}
this.FFFMJP = [];
this.updateSelectedStatus();
EDITOR.scaleOffsetIsSet = false;
EDITOR.resetArc();
EDITOR.disableWandSelect();
EDITOR.prevFineSelect = false;
EDITOR.isFineSelect = false;
EDITOR.FFIRFF = "";
};
this.enableWandSelect = function ()
{
if (! this.isWandSelect)
{
this.isWandSelect = true;
var cstyle = "nw-resize";
addCSSRule(".marcher", "cursor: " + cstyle);
addCSSRule(".equipment", "cursor: " + cstyle);
document.body.style.cursor = cstyle;
EDITOR.enableWandCursor();
if (EDITOR.FFBPXP)
{
EDITOR.FFQFPT(EDITOR.FFBPXP);
}
}
};
this.enableWandCursor = function ()
{
if (this.isWandSelect)
{
var url = imageUrl('show/wand.cur');
var cstyle = "url("+url+"), nw-resize";
addCSSRule(".marcher", "cursor: " + cstyle);
addCSSRule(".equipment", "cursor: " + cstyle);
document.body.style.cursor = cstyle;
}
};
this.disableWandSelect = function ()
{
if (this.isWandSelect)
{
this.isWandSelect = false;
addCSSRule(".marcher", "cursor:move");
addCSSRule(".equipment", "cursor:move");
document.body.style.cursor = "default";
}
};
this.resetArc = function ()
{
EDITOR.show.arcFocus = [];
EDITOR.show.FFVPSA = 0;
EDITOR.show.arcFocusAngle = 0;
EDITOR.show.FFGIMI = [];
EDITOR.show.arcDirection = 0;
EDITOR.show.reverseArcKey = false;
EDITOR.show.FFJSIP = 0;
};
this.FFQFPT = function (m, isOrdered)
{
if (! m.FFBTPK)
{
isDark = false;
m.select(false, isDark);
if (m.FFBTPK)
{
this.FFFMJP.push(m);
this.updateSelectedStatus();
}
EDITOR.resetArc();
}
}
this.FFRUFU = function (m)
{
if (m.FFBTPK)
{
m.deselect();
if (! ie)
{
this.FFFMJP.splice(this.FFFMJP.indexOf(m), 1);
}
else
{
for (i=0; i < this.FFFMJP.length; i++)
{
if (this.FFFMJP[i].id == m.id)
{
this.FFFMJP.splice(i, 1);
}
}
}
this.updateSelectedStatus();
EDITOR.resetArc();
}
}
this.setDragOrigin = function (dx, dy)
{
this.dragOriginX = dx;
this.dragOriginY = dy;
for (m=0; m < this.FFFMJP.length; m++)
{
this.FFFMJP[m].setDragOrigin();
}
}
this.spawnSetPins = function ()
{
for (i=0; i < this.show.marchers.length; i++)
{
this.show.marchers[i].spawnSetPin();
}
this.updateSetPins();
}
this.toggleSetPins = function ()
{
this.showPins = 1 - this.showPins;
action_message("Set dots turned " + (this.showPins ? 'ON' : 'OFF'));
for (i=0; i < this.show.marchers.length; i++)
{
if (this.showPins)
{
this.show.marchers[i].showPin();
}
else
{
this.show.marchers[i].hidePin();
}
}
}
this.updateSetPins = function ()
{
if (EDITOR.mode != MODE_EDIT)
return false;
var pinOffX = -1  // + ((ie) ? 1 : 0)
if (EDITOR.isPlaying)
{
for (var i=0, m; m = this.show.marchers[i]; i++)
{
var offX = (m.section == SECTION_BASS) ? -8 : 0;
var pin = $(m.id + "pin");
pin.style.left = m.x + m.imgSizeX / 2 + pinOffX + offX;
pin.style.top = m.y + m.imgSizeY - 3;
}
}
else if (this.show.FFPJVV == 0)
{
for (var i=0, m; m = this.show.marchers[i]; i++)
{
if (m.section != SECTION_PROP)
{
var pin = $(m.id + "pin");
pin.style.left = px(-10);
pin.style.top = px(-10);
}
}
}
else
{
var prevSet = this.show.FFPJVV - 1;
for (var i=0, m; m = this.show.marchers[i]; i++)
{
if (m.section == SECTION_PROP) {  continue; }
var offX = (m.section == SECTION_BASS) ? -8 : 0;
var pin = $(m.id + "pin");
pin.style.left = m.sets[prevSet][0] + m.imgSizeX / 2 + pinOffX + offX;
pin.style.top = m.sets[prevSet][1] + m.imgSizeY - 3;
}
}
}
this.setLeader = function (marcher)
{
if (this.leader)
{
this.leader.isLeader = false;
}
this.leader = marcher;
marcher.isLeader = true;
marcher.setBorder("solid 1px orange");
}
this.toggleSnap = function ()
{
this.snapX = (this.snapX + 1) % NUM_GRIDS;
var onOff = GRID_X_NAME[this.snapX];
if (! SHOW_TOOL_MENU)
{
action_message("Yardline Snap is &nbsp;" + onOff);
}
}
this.addToHistory = function (actionID, selectOnly)
{
if (actionID && actionID == this.lastActionID)
{
return false;
}
this.lastActionID = actionID;
var history = this.FFEQJR[ this.show.FFPJVV ];
if (! history)
{
history = [];
this.FFEQJR[ this.show.FFPJVV ] = history;
}
if (history.length >= MAX_UNDO_STATES)
{
history.shift();
}
var state = this.getHistoryState(selectOnly);
this.FFJBQV[ this.show.FFPJVV ] = [];
history.push(state);
this.stateIsChanged = false;
}
this.getHistoryState = function (selectOnly)
{
var pos = [];
if (! selectOnly)
{
for(i=0; i < this.show.marchers.length; i++)
{
var m = this.show.marchers[i];
pos[m.id] = [ m.x, m.y ];
}
}
if (! this.show.FFWPKR[ this.show.FFPJVV ])
{
this.show.FFWPKR[ this.show.FFPJVV ] = [];
}
var group = (selectOnly) ? [] : this.show.FFWPKR[ this.show.FFPJVV ].slice();
var state =
{
'pos' : pos,
'sel' : this.FFFMJP.slice(),
'group' : group
};
return state;
};
this.undo = function ()
{
var history = this.FFEQJR[ this.show.FFPJVV ];
if (! history.length)
return false;
var currState = this.getHistoryState();
this.FFJBQV[ this.show.FFPJVV ].push(currState);
var lastState = history.pop()
if (lastState.pos.length)
{
for (i=0; i < this.show.marchers.length; i++)
{
var m = this.show.marchers[i];
m.move(lastState.pos[m.id][0], lastState.pos[m.id][1]);
}
}
this.restoreSelection(lastState.sel, lastState.group);
this.stateIsChanged = false;
this.lastActionID = "";
EDITOR.resetArc();
}
this.redo = function ()
{
var rhistory = this.FFJBQV[ this.show.FFPJVV ];
if (! rhistory.length)
return false;
var currState = this.getHistoryState();
this.FFEQJR[ this.show.FFPJVV ].push(currState);
var lastState = rhistory.pop();
if (lastState.pos.length)
{
for(i=0; i < this.show.marchers.length; i++)
{
var m = this.show.marchers[i];
m.move(lastState.pos[m.id][0], lastState.pos[m.id][1]);
}
}
this.restoreSelection(lastState.sel, lastState.group);
this.stateIsChanged = false;
EDITOR.resetArc();
}
this.restoreSelection = function (marchers, groups)
{
EDITOR.FFGJOC();
for (i=0; i < marchers.length; i++)
{
var m = marchers[i];
EDITOR.FFQFPT(m);
}
if (groups.length)
{
this.show.FFWPKR[ this.show.FFPJVV ] = groups.slice();
}
};
this.clearHistory = function ()
{
this.stateIsChanged = false;
this.FFEQJR = [[]];
this.FFJBQV = [[]];
this.undoSetNum = this.show.FFPJVV;
}
this.recoverLostMarchers = function ()
{
if (EDITOR.isPlaying)
return false;
this.FFGJOC(true);
for(i=0; i < this.show.marchers.length; i++)
{
var marcher = this.show.marchers[i];
if (marcher.x > FIELD_SIZE_X)
{
this.FFQFPT(marcher);
}
else if (marcher.x < -18)
{
this.FFQFPT(marcher);
}
else if (marcher.y > FIELD_SIZE_Y)
{
this.FFQFPT(marcher);
}
else if (marcher.y < -36)
{
this.FFQFPT(marcher);
}
}
if (EDITOR.FFFMJP.length == 0)
{
alert("No lost marchers found.");
return false;
}
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].FFQBJV([FIELD_SIZE_X / 2, FIELD_SIZE_Y / 2]);
}
EDITOR.FFFMJP.sort(function (a,b) { return a.FFPHLH - b.FFPHLH })
var offX = 0;
var offY = 0;
if (EDITOR.FFFMJP[0].x < 0)
offX = EDITOR.FFFMJP[0].x + 80 - EDITOR.FFFMJP[0].x;
if (EDITOR.FFFMJP[0].x > FIELD_SIZE_X)
offX = FIELD_SIZE_X - 80 - EDITOR.FFFMJP[0].x;
if (EDITOR.FFFMJP[0].y < 0)
offY = EDITOR.FFFMJP[0].y + 80 - EDITOR.FFFMJP[0].y;
if (EDITOR.FFFMJP[0].y > FIELD_SIZE_Y)
offY = FIELD_SIZE_Y - 80 - EDITOR.FFFMJP[0].y;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].move(EDITOR.FFFMJP[m].x + offX, EDITOR.FFFMJP[m].y + offY);
}
if (EDITOR.FFFMJP.length > 1)
{
alert("Drag the selected marcher to pull the rest onto the field.");
}
else if (EDITOR.FFFMJP.length == 0)
{
alert("There are no marchers outside the field.");
}
}
this.mouseUp = function (e)
{
if (this.isDragging && this.FFCIBA)
{
if (this.FFCIBA.isLeader)
{
this.FFCIBA.setBorder("solid 1px orange");
}
else
{
this.FFCIBA.setBorder("solid 1px " + BORDER_COLOR);
}
}
this.didDrag = false;
this.isFineSelect = false;
this.isDragging = false;
this.resetSelectBox();
}
this.mouseOut = function (e)
{
if (! this.isDragging)
{
this.unhighlightMarcher();
}
if (this.FFTBGP.length)
{
this.quickUnhighlight();
}
}
this.mouseOver = function (ev)
{
if (this.isPlaying || this.mode != MODE_EDIT)
return false;
var over = ns6 ? ev.target : ev.srcElement;
if (! this.isDragging)
{
if (over.className == "marcher" || over.className == "equipment")
{
var marcher = this.marcherById[ getnum(over.id) ];
if (this.isWandSelect || this.isFineSelect)
{
if (marcher.section == SECTION_PROP && this.show.maxSet > 0)
{
}
else
{
EDITOR.FFIRFF = "wand";
this.FFQFPT(marcher, true);
}
}
if (EDITOR.quickSelect)
{
this.quickHighlightGroup(marcher);
}
else
{
this.highlightMarcher(marcher);
}
}
}
}
this.quickUnhighlight = function ()
{
for (var i=0,m; m = EDITOR.FFTBGP[i]; i++)
{
m.quickUnhighlight();
}
EDITOR.FFTBGP = [];
};
this.quickHighlightGroup = function (marcher)
{
this.quickUnhighlight();
if (!marcher)
{
marcher = EDITOR.FFBPXP;
if (! marcher) {  return false; }
this.unhighlightMarcher(marcher);
}
var group = EDITOR.show.FFMKTM(marcher);
if (group)
{
for (var i=0,m; m = group[i]; i++)
{
m.FFHDRP();
}
this.FFTBGP = group.slice();
}
};
this.highlightMarcher = function (marcher)
{
if (this.FFBPXP)
{
this.FFBPXP.unhighlight();
}
marcher.highlight();
this.FFBPXP = marcher;
}
this.unhighlightMarcher = function ()
{
if (this.FFBPXP)
{
this.FFBPXP.unhighlight();
this.FFBPXP = null;
}
}
this.doubleClick = function (ev)
{
if (self.isPlaying || ! self.mode == MODE_EDIT)
return false;
var clickedObj = ns6 ? ev.target : ev.srcElement;
var topElement = ns6 ? "HTML" : "BODY";
while (clickedObj.tagName != topElement && clickedObj.className != "marcher" && clickedObj.className != "equipment")
{
clickedObj = ns6 ? clickedObj.parentNode : clickedObj.parentElement;
}
if (EDITOR.quickSelect)
{
return false;
}
if (clickedObj.className == "marcher" || clickedObj.className == "equipment")
{
var isCtrl = (ev.ctrlKey || EDITOR.fakeCtrl) ? true : false;
var marcher = self.marcherById[ getnum(clickedObj.id) ];
if (marcher.isGhost)
{
return false;
}
var FFBTPK = marcher.FFBTPK;
if (ie)
{
FFBTPK = ! marcher.FFBTPK;
}
if (FFBTPK && isCtrl)
{
self.show.FFTTAJ(marcher);
}
else
{
self.show.FFXLAN(marcher, isCtrl);
}
}
}
this.mouseDown = function (ev)
{
if (self.isPlaying && self.cursorInEditor)
{
self.FFGJOC();
return false;
}
if (self.isPlaying || self.mode != MODE_EDIT)
return false;
var clickedObj = ns6 ? ev.target : ev.srcElement;
var topElement = ns6 ? "HTML" : "BODY";
while (clickedObj.tagName != topElement && clickedObj.className != "marcher" && clickedObj.id != "soundprog"  && clickedObj.className != "equipment")
{
clickedObj = ns6 ? clickedObj.parentNode : clickedObj.parentElement;
}
var marcher = null;
if (clickedObj.className == "marcher" || clickedObj.className == "equipment")
{
marcher = self.marcherById[ getnum(clickedObj.id) ];
if (marcher.isGhost)
{
marcher = null;
}
}
if (marcher)
{
if (marcher.section == SECTION_PROP && EDITOR.show.propsHidden)
{
}
var isCtrl = (ev.ctrlKey || EDITOR.fakeCtrl);
if (isCtrl)
{
if (marcher.FFBTPK)
{
self.FFRUFU(marcher);
return true;
}
else
{
EDITOR.FFIRFF = "marcher";
self.FFQFPT(marcher);
self.isFineSelect = true;
}
}
else if (this.isWandSelect && marcher.FFBTPK)
{
self.FFRUFU(marcher);
}
else if (this.quickSelect)
{
self.show.FFJSGI(marcher, isCtrl);
}
else if (ev.shiftKey)
{
if (EDITOR.FFIRFF == "line" || EDITOR.FFIRFF == "marcher")
{
self.show.selectMarchersByLine(marcher);
EDITOR.FFIRFF = "line";
return false;
}
}
else
{
self.isDragging = true;
if (! marcher.FFBTPK)
{
self.FFGJOC(true);
self.FFQFPT(marcher);
EDITOR.FFIRFF = "marcher";
}
}
self.FFCIBA = marcher;
if (self.FFFMJP.length > 0)
{
for(i=0; i < self.FFFMJP.length; i++)
{
if (! self.FFFMJP[i].isLeader)
{
self.FFFMJP[i].setBorder("solid 1px " + BORDER_COLOR);
}
}
if (marcher.FFBTPK && ! throttle('quick_select'))
{
marcher.setSpecialBorder();
}
}
self.setDragOrigin(ev.clientX, ev.clientY);
return false;
}
else if (self.cursorInEditor)
{
if (ev.shiftKey)
{
}
else if (! this.isWandSelect)
{
self.setDragOrigin(ev.clientX, ev.clientY);
if (! ev.ctrlKey && ! EDITOR.fakeCtrl) {  self.FFGJOC(true) }
var editorX = (document.body.clientWidth - FIELD_SIZE_X) / 2;
var editorY = $('editor').offsetTop - document.body.scrollTop;
self.resetSelectBox();
self.selectBoxX = self.dragOriginX - editorX - 5;
self.selectBoxY = self.dragOriginY - editorY - 9;
self.selectBoxActive = true;
self.selectBox.style.visibility = "visible";
self.selectBox.style.top = px(-100);
self.selectBox.style.left = px(-100);
return false;
}
}
}
this.mouseMove = function (e)
{
if (self.isPlaying || ! self.mode == MODE_EDIT)
return false;
mouseMoveTick ++;
if (mouseMoveTick % 2 == 1)
return false;
var ev = ns6 ? e : event;
self.mouseX = ev.clientX;
self.mouseY = ev.clientY;
if (self.FFFMJP.length)
{
var editorX = (document.body.clientWidth - FIELD_SIZE_X) / 2;
var editorY = $('editor').offsetTop - document.body.scrollTop;
if (self.mouseX - editorX > FIELD_SIZE_X - 164 && self.mouseY - editorY > FIELD_SIZE_Y - 70)
{
if (! self.statusHidden)
{
self.hideStatus();
self.statusHidden = true;
}
}
else if (self.statusHidden)
{
self.updateStatus(self.FFFMJP.length + " selected", true);
self.statusHidden = false;
}
}
if (self.isDragging)
{
if (! self.didDrag)
{
self.FFUXRH();
self.didDrag = true;
}
var offX =  ev.clientX - self.dragOriginX;
var offY =  ev.clientY - self.dragOriginY;
var cOffX = self.show.FFDSXP[0] - self.FFCIBA.x;
var cOffY = self.show.FFDSXP[1] - self.FFCIBA.y;
var acOffX = self.show.FFGIMI[0] - self.FFCIBA.x;
var acOffY = self.show.FFGIMI[1] - self.FFCIBA.y;
for(i=0; i < self.FFFMJP.length; i++)
{
self.FFFMJP[i].FFLBTD(self.FFCIBA);
}
self.FFCIBA.drag(offX, offY);
self.show.FFDSXP[0] = self.FFCIBA.x + cOffX;
self.show.FFDSXP[1] = self.FFCIBA.y + cOffY;
self.show.FFGIMI[0] = self.FFCIBA.x + acOffX;
self.show.FFGIMI[1] = self.FFCIBA.y + acOffY;
if (! self.FFCIBA.isLeader)
{
for(i=0; i < self.FFFMJP.length; i++)
{
self.FFFMJP[i].moveRelativeToHandle();
}
}
return false;
}
else if (self.selectBoxActive)
{
var cx = ev.clientX;
var cy = ev.clientY;
var boxSizeX = cx - self.dragOriginX;
var boxSizeY = cy - self.dragOriginY;
var boxLeft = self.selectBoxX;
var boxTop = self.selectBoxY;
var marcherOffsetX = 0;
var marcherOffsetY = 0;
if (boxSizeX < 0)
{
boxLeft = boxLeft + boxSizeX;
boxSizeX = Math.abs(boxSizeX);
marcherOffsetX = MARCHER_SIZE_X;
}
if (boxSizeY < 0)
{
boxTop = boxTop + boxSizeY;
boxSizeY = Math.abs(boxSizeY);
marcherOffsetY = MARCHER_SIZE_Y;
}
if (boxTop + boxSizeY > FIELD_SIZE_Y - 2)
{
boxSizeY = (FIELD_SIZE_Y - 2) - boxTop;
}
self.selectBox.style.top = px(boxTop);
self.selectBox.style.left = px(boxLeft);
self.selectBox.style.width = px(boxSizeX);
self.selectBox.style.height = px(boxSizeY);
if (cx % 2 == 0 && cy % 2 == 0)
{
return;
}
for (i=0; i < self.show.marchers.length; i++)
{
var isInBox = false;
var marcher = self.show.marchers[i];
if (marcher.section == SECTION_PROP && self.show.maxSet > 0)
{
continue;
}
if (marcher.section == SECTION_METRONOME)  continue;
var mx = marcher.x + marcherOffsetX;
var my = marcher.y + marcherOffsetY;
if (mx > boxLeft && mx < boxLeft + boxSizeX && my > boxTop && my < boxTop + boxSizeY)
{
isInBox = true;
}
else if (self.selectBoxX > marcher.x && self.selectBoxX < marcher.x + marcher.imgSizeX && my > boxTop && my < boxTop + boxSizeY)
{
isInBox = true;
}
else if (self.selectBoxY > marcher.y && self.selectBoxY < marcher.y + marcher.imgSizeY && mx > boxLeft && mx < boxLeft + boxSizeX)
{
isInBox = true;
}
if (! isInBox && ! ev.ctrlKey && ! EDITOR.fakeCtrl && marcher.FFBTPK)
{
self.FFRUFU(marcher);
}
else if (! marcher.FFBTPK && isInBox)
{
EDITOR.FFIRFF = "box";
self.FFQFPT(marcher);
}
}
}
}
}
function doubleClick (e)
{
var ev = ns6 ? e : event;
return EDITOR.doubleClick(ev);
}
function mouseDown (e)
{
MOUSE_DOWN = true;
var ev = ns6 ? e : event;
return EDITOR.mouseDown(ev);
}
function mouseUp (e)
{
MOUSE_DOWN = false;
var ev = ns6 ? e : event;
EDITOR.mouseUp(ev);
}
function mouseOver (e)
{
var ev = ns6 ? e : event;
EDITOR.mouseOver(ev);
}
function mouseOut (e)
{
var ev = ns6 ? e : event;
EDITOR.mouseOut(ev);
}
function oShow ()
{
this.title = "Untitled";
this.authorName = "Anon";
this.authorID = 0;
this.hasDescription = false;
this.editorVersion = EDITOR_VERSION;
this.marchers = [];
this.FFPJVV = 0;
this.maxSet = 0;
this.startTime = 0;
this.lastTweenTime = 0;
this.lastAnimTime = [];
this.longestPath = 0;
this.timeInterval = 0;
this.intervalID = 0;
this.FFDSXP = [0,0];
this.arcFocus = [0,0];
this.FFVPSA = 0;
this.arcDirection = 0;
this.FFGIMI = [0,0];
this.numBasses = 0;
this.showConfig = [];
this.marcherConfig = [];
this.setConfig = [];
this.ripples = [];
this.ftlTrains = [];
this.pivots = [];
this.marcherIsDeleted = [];
this.setTime = [];
this.isSetup = false;
this.propsHidden = false;
this.frameCount = 0;
this.showStartTime = 0;
this.FFWPKR = [];
this.FFOWUW = 300;
this.addSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (EDITOR.isAddingSet)
return false;
EDITOR.isAddingSet = true;
if (! EDITOR.setIsChanged)
{
}
if (this.maxSet == MAX_SETS)
{
if (IS_DEMO)
{
alert("You have the max number of sets for the demo.\n\nTo create a complete show, sign up now -- it's free!");
}
else
{
var msg = "You have reached the max number of sets.";
if (! EDITOR.isPremium) {  msg += "\n\nYou can add more by upgrading your membership!"; }
alert(msg);
}
setTimeout("EDITOR.isAddingSet = false;", 200);
return false;
}
if (this.FFPJVV != this.maxSet)
{
this.insertSet();
setTimeout("EDITOR.isAddingSet = false;", 200);
return false;
}
if (! this.FFWPKR[ this.FFPJVV ])
{
this.FFWPKR[ this.FFPJVV ] = [];
}
this.FFWPKR[ this.FFPJVV + 1 ] = this.FFWPKR[ this.FFPJVV ].slice();
newSetNumber(this.FFPJVV + 1);
this.saveSet();
this.maxSet += 1;
this.FFPJVV = this.maxSet;
EDITOR.FFEQJR[ this.FFPJVV  ] = [];
this.setConfig[this.FFPJVV] = [];
this.resetPace();
for (i=0; i < this.marchers.length; i++)
{
this.marchers[i].addSet(this.FFPJVV);
}
this.saveSet();
EDITOR.setIsChanged = false;
EDITOR.addSetToGraph(this.FFPJVV);
EDITOR.highlightSetBlock(this.FFPJVV);
$('setblock'+(this.FFPJVV-1)).style.backgroundColor = '#97D2A2';
if (EDITOR.show.FFPJVV == 1 && EDITOR.helpLevel < 1)
{
EDITOR.helpLevel = 1;
newHelp("Move them to a new spot, then click \"Play\"");
}
if (EDITOR.show.FFPJVV == 2)
{
hide('help');
}
if ($('studiosublinks'))
{
}
setTimeout("EDITOR.isAddingSet = false;", 200);
EDITOR.updateSetPins();
};
this.jumpToNextSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.FFPJVV + 1 <= this.maxSet)
{
this.forceJumpToSet(this.FFPJVV + 1);
}
};
this.jumpToPrevSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.FFPJVV > 0)
{
this.forceJumpToSet(this.FFPJVV - 1);
}
};
this.jumpToFirstSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.FFPJVV > 0)
{
this.forceJumpToSet(0);
}
};
this.jumpToLastSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.maxSet > 0)
{
this.forceJumpToSet(this.maxSet);
}
};
this.saveSet = function ()
{
if (! EDITOR.isPlaying)
{
for (i=0; i < this.marchers.length; i++)
{
this.marchers[i].saveSet(this.FFPJVV);
}
}
};
this.deleteSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.FFPJVV == 0 && this.maxSet == 0)
{
alert("Sorry, you can't delete the first set.\n\nClick 'Start New Show' if you want to start over.");
return false;
}
if (confirm("Are you sure you want to delete Set " + (this.FFPJVV+1) + "?"))
{
this.maxSet --;
for (i=0; i < this.marchers.length; i++)
{
this.marchers[i].deleteSet(this.FFPJVV);
}
this.setConfig.splice(this.FFPJVV, 1);
this.ripples.splice(this.FFPJVV, 1);
EDITOR.FFEQJR.splice(this.FFPJVV, 1);
EDITOR.FFJBQV.splice(this.FFPJVV, 1);
this.FFWPKR.splice(this.FFPJVV, 1);
var newSet = this.FFPJVV - 1;
if (this.FFPJVV == 0)
newSet = 0;
this.jumpToSet(newSet);
EDITOR.redrawSetPanel();
EDITOR.redrawSetBlock(this.FFPJVV);
EDITOR.highlightSetBlock(this.FFPJVV);
action_message("Set Deleted");
}
};
this.insertSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.maxSet >= MAX_SETS)
{
var msg = "You have reached the max number of sets.";
if (! EDITOR.isPremium) {  msg += "\n\nYou can add more by upgrading your membership!"; }
alert(msg);
return false;
}
if (confirm("Insert a new copy of the current set?"))
{
this.saveSet();
for (i=0; i < this.marchers.length; i++)
{
this.marchers[i].insertSet(this.FFPJVV);
}
this.maxSet += 1;
this.setConfig.splice(this.FFPJVV+1, 0, [ this.setConfig[this.FFPJVV][0], this.setConfig[this.FFPJVV][1] ] );
this.ripples.splice(this.FFPJVV+1, 0, []);
EDITOR.FFEQJR.splice(this.FFPJVV + 1, 0, []);
EDITOR.FFJBQV.splice(this.FFPJVV + 1, 0, []);
if (! this.FFWPKR[ this.FFPJVV ])  this.FFWPKR[ this.FFPJVV ] = [];
this.FFWPKR[ this.FFPJVV + 1 ] = this.FFWPKR[ this.FFPJVV ].slice();
EDITOR.redrawSetPanel();
this.jumpToSet(this.FFPJVV + 1);
action_message("New Set Inserted");
EDITOR.setIsChanged = false;
EDITOR.updateSetPins();
this.saveSet();
}
};
this.resetSet = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.FFPJVV == 0)
{
alert("Sorry, you can't reset the first set.\n\nClick 'Start New Show' if you want to start over.");
return false;
}
if (confirm("Discard all changes and copy the preceding set?"))
{
EDITOR.FFUXRH();
for (i=0; i < this.marchers.length; i++)
{
this.marchers[i].resetSet(this.FFPJVV, this.FFPJVV - 1);
}
this.setConfig[this.FFPJVV][SET_CONFIG_PACE] = this.setConfig[this.FFPJVV - 1][SET_CONFIG_PACE];
this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] = this.setConfig[this.FFPJVV - 1][SET_CONFIG_PAUSE];
this.ripples[ this.FFPJVV ] = [];
this.FFWPKR[ this.FFPJVV ] = [];
this.redrawSetConfig();
if (this.FFPJVV == this.maxSet)
EDITOR.setIsChanged = false;
this.saveSet();
}
};
this.FFNAOT = function (marchers)
{
if (marchers.length < 3 || EDITOR.FFIRFF == "supergroup" || EDITOR.FFIRFF == "section" || EDITOR.FFIRFF == "all")
{
return false;
}
var deletedMarchers = this.getDeletedMarchers();
var numActiveMarchers = this.marchers.length - deletedMarchers.length;
if (marchers.length == numActiveMarchers)  return false;
if (! this.FFWPKR[ this.FFPJVV ])
{
this.FFWPKR[ this.FFPJVV ] = [];
}
var gid = this.FFPFIF();
for (var i=0,m; m = marchers[i]; i++)
{
this.FFWPKR[ this.FFPJVV ][ m.id ] = gid;
}
this.FFWPKR[ this.FFPJVV ][ gid ] = marchers.slice();
};
this.FFPFIF = function ()
{
++ this.FFOWUW;
return this.FFOWUW;
};
this.FFCFQT = function (marchers)
{
if (! this.FFWPKR[ this.FFPJVV ])
{
this.FFWPKR[ this.FFPJVV ] = [];
}
for (var i=0,m; m = marchers[i]; i++)
{
this.FFPUGQ(m);
}
};
this.FFPUGQ = function (marcher)
{
if (! this.FFWPKR[ this.FFPJVV ])
{
return false;
}
var gid = this.FFWPKR[ this.FFPJVV ][ marcher.id ];
if (gid)
{
var group = this.FFWPKR[ this.FFPJVV ][ gid ];
for (var i=0,m; m = group[i]; i++)
{
this.FFWPKR[ this.FFPJVV ][ m.id ] = null;
}
this.FFWPKR[ this.FFPJVV ][ gid ] = null;
}
};
this.FFMKTM = function (marcher)
{
var thisSet = this.FFWPKR[ this.FFPJVV ] || [  ];
var groupID = thisSet[ marcher.id ];
var group = [];
if (! groupID)
{
var group1 = this.FFROPQ(marcher);
for (var i=0,m; m = group1[i]; i++)
{
if (thisSet && thisSet[ m.id ])
{
continue;
}
else
{
group.push(m);
}
}
}
else
{
var group1 = thisSet[ groupID ];
for (var i=0,m; m = group1[i]; i++)
{
if (thisSet[ m.id ] && thisSet[ m.id ] != groupID)
{
continue;
}
else
{
group.push(m);
}
}
}
return group;
};
this.FFJSGI = function (marcher, isCtrl)
{
throttle('quick_select', 50);
EDITOR.FFIRFF = "group";
var group = this.FFMKTM(marcher);
var allSelected = true;
for (var i=0,m; m = group[i]; i++)
{
if (! m.FFBTPK) { allSelected = false; break; }
}
if (allSelected)
{
EDITOR.FFIRFF = "supergroup";
for (var i=0,m; m = group[i]; i++)
{
EDITOR.FFRUFU(m);
}
EDITOR.quickHighlightGroup(marcher);
return true;
}
else
{
EDITOR.FFIRFF = "supergroup";
EDITOR.quickUnhighlight();
for (var i=0,m; m = group[i]; i++)
{
EDITOR.FFQFPT(m);
}
return true;
}
};
this.resetMarchers = function (isCtrl)
{
if (EDITOR.isPlaying)  return false;
if (this.FFPJVV == 0 && ! isCtrl)
{
alert("You can't Reset the first set.");
return false;
}
else if (this.FFPJVV == this.maxSet && isCtrl)
{
alert("You can't Reverse Reset the last set.");
return false;
}
var action = "Reset";
var fromSet = this.FFPJVV - 1;
if (isCtrl)
{
action = "Reverse Reset";
fromSet = this.FFPJVV + 1;
}
if (confirm(action + " the selected marchers?"))
{
EDITOR.FFUXRH();
for (i=0; i < EDITOR.FFFMJP.length; i++)
{
EDITOR.FFFMJP[i].resetSet(this.FFPJVV, fromSet);
}
}
};
this.copyDots = function ()
{
if (EDITOR.isPlaying)  return false;
if (! EDITOR.FFFMJP.length) return false;
if (! this.requireOrderSelect())  {  return false; }
EDITOR.clipboard = [];
for (i=0; i < EDITOR.FFFMJP.length; i++)
{
var m = EDITOR.FFFMJP[i];
var dot = [ m.id, m.x>>0, m.y>>0, m.section, m.state ];
if (m.section == SECTION_GUARD)
{
dot.push(m.flagNum);
}
EDITOR.clipboard.push(dot);
}
action_message("Dots Copied");
};
this.pasteDots = function ()
{
if (EDITOR.isPlaying)  return false;
if (! EDITOR.clipboard.length) return false;
if (! EDITOR.FFFMJP.length) return false;
if (EDITOR.clipboard.length != EDITOR.FFFMJP.length)
{
alert("Please select " + EDITOR.clipboard.length + " marchers, to match the number of dots on your clipboard.");
return false;
}
if (! this.requireOrderSelect())  {  return false; }
EDITOR.FFUXRH();
var sameMarchers = true;
var dotsByID = {};
for (var d,i=0; d=EDITOR.clipboard[i]; i++)
{
dotsByID[ d[0] ] = d;
}
for (var m,i=0; m=EDITOR.FFFMJP[i]; i++)
{
if (! dotsByID[ m.id ]) sameMarchers = false;
}
var centerOffset = [0,0];
if (! sameMarchers)
{
var dotCenter = this.getCenterDot(EDITOR.clipboard);
var selCenter = this.FFOFOJ(false);
centerOffset = [ selCenter[0]-dotCenter[0], selCenter[1]-dotCenter[1] ];
}
for (var m,i=0; m=EDITOR.FFFMJP[i]; i++)
{
var dot = EDITOR.clipboard[i];
if (sameMarchers) dot = dotsByID[m.id];
m.move(dot[1] + centerOffset[0], dot[2] + centerOffset[1]);
if (m.section == dot[3])
{
if (m.section == SECTION_GUARD && sameMarchers)
{
m.setFlag(dot[5], true);
m.setState(dot[4]);
}
else if (m.section == SECTION_GUARD && m.equipment.flagNum != dot[5])
{
}
else
{
m.setState(dot[4]);
}
}
}
action_message("Dots Pasted");
};
this.getDeletedMarchers = function ()
{
var deletedMarchers = [];
for (i=0; i < this.marchers.length; i++)
{
if (this.marchers[i].isDeleted)
{
deletedMarchers.push(this.marchers[i]);
}
}
return deletedMarchers;
};
this.deleteMarchers = function (isCtrl)
{
if (EDITOR.isPlaying)
return false;
if (isCtrl)
{
if (confirm("Un-Delete all deleted marchers?"))
{
EDITOR.FFGJOC();
var numRestored = 0;
for (i=0; i < this.marchers.length; i++)
{
if (this.marchers[i].isDeleted)
{
this.marchers[i].undelete();
++ numRestored;
EDITOR.FFQFPT(this.marchers[i]);
EDITOR.FFIRFF = "restore";
}
}
action_message(numRestored + " marchers un-deleted");
}
}
else
{
if (EDITOR.FFFMJP.length == 0)
{
return false;
}
if (confirm("Delete the selected marchers?\n\n(You can press Ctrl-Delete to bring them back.)"))
{
var numDeleted = 0;
for (i=0; i < EDITOR.FFFMJP.length; i++)
{
EDITOR.FFFMJP[i].dodelete();
++ numDeleted;
}
var baseMarcher = EDITOR.FFFMJP[0];
var isOk = false;
for (i=0; i < this.marchers.length; i++)
{
if (! this.marchers[i].isDeleted)
{
isOk = true;
break;
}
}
if (! isOk)
{
for (i=0; i < EDITOR.FFFMJP.length; i++)
{
EDITOR.FFFMJP[i].undelete();
}
alert('You must have at least one marcher on the field.');
return false;
}
else
{
EDITOR.FFGJOC();
}
var isBB = false;
if (numDeleted == 1 && this.maxSet == 0 && baseMarcher.section == SECTION_SNARE && ! ___BB)
{
var snares = this.FFROPQ(baseMarcher);
if (snares.length >= 5)
{
var left = 999;
for (var i = 0; i < snares.length; i ++)
{
if (snares[i].id < left) {  left = snares[i].id; }
}
if (left == baseMarcher.id)
{
___BB = 1;
action_message("[ CUT ]", 0, 1200);
isBB = true;
}
}
}
if (! isBB)
{
action_message(numDeleted + " marchers deleted", numDeleted * 2);
}
}
}
};
this.tradeSets = function ()
{
if (EDITOR.isPlaying)
return false
if (EDITOR.FFFMJP.length != 2)
{
alert("Select the two marchers that will trade spots with each other.");
return false;
}
var m0 = EDITOR.FFFMJP[0];
var m1 = EDITOR.FFFMJP[1];
if (m0.section != m1.section)
{
}
if (confirm("Have the selected marchers trade spots?\n\nThis will affect all of their future sets."))
{
action_message("Sets Traded")
this.saveSet();
EDITOR.FFUXRH();
for (var s = this.FFPJVV; s <= this.maxSet; s++)
{
var tmp = [ m0.sets[s][0], m0.sets[s][1] ];
m0.sets[s][0] = m1.sets[s][0];   m0.sets[s][1] = m1.sets[s][1];
m1.sets[s][0] = tmp[0];          m1.sets[s][1] = tmp[1];
}
m0.jumpToSet(this.FFPJVV);
m1.jumpToSet(this.FFPJVV);
}
};
this.selectAllMarchers = function ()
{
EDITOR.FFGJOC(true);
for (var m,i=0; m = EDITOR.show.marchers[i]; i++)
{
if (m.section == SECTION_PROP || m.isGhost || m.isDeleted || m.section == SECTION_METRONOME)  continue;
EDITOR.FFQFPT(m);
EDITOR.FFIRFF = "all";
}
};
this.selectMarchersByLine = function (endMarcher)
{
var first = EDITOR.FFFMJP[ EDITOR.FFFMJP.length - 1 ];
var angle = endMarcher.angleToMarcher(first);
if (first.id == endMarcher.id)
{
return false;
}
EDITOR.FFUXRH('selectline', true);
var checkX = first.x;
var checkY = first.y;
var checkInterval = 8;
var boxSizeX = 18;
var boxSizeY = 18;
var selectableMarchers = [];
for (var m,i=0; m = EDITOR.show.marchers[i]; i++)
{
if (m.section == SECTION_PROP || m.isGhost || m.isDeleted || m.section == SECTION_METRONOME)
{
continue;
}
selectableMarchers.push(m);
}
var numMisses = 0;
var isDone = false;
while ((! isDone) && checkX > 0 && checkX < FIELD_SIZE_X && checkY > 0 && checkY < FIELD_SIZE_Y)
{
var checkX = checkX + Math.sin(angle * Math.PI / 180) * checkInterval;
var checkY = checkY + Math.cos(angle * Math.PI / 180) * checkInterval * -1.0;
var boxLeft = checkX - (boxSizeX / 2);
var boxTop = checkY - (boxSizeY / 2);
var numMatches = 0;
for (var m,i=0; m = selectableMarchers[i]; i++)
{
var mx = m.x;
var my = m.y;
if (mx > boxLeft && mx < boxLeft + boxSizeX && my > boxTop && my < boxTop + boxSizeY)
{
if (m.FFBTPK)
{
EDITOR.FFRUFU(m);
}
EDITOR.FFQFPT(m);
numMatches += 1;
if (m.id == endMarcher.id)
{
isDone = true;
}
}
}
if (! numMatches)
{
++ numMisses;
}
}
};
this.FFXLAN = function (mainMarcher, isCtrl)
{
if (! isCtrl)
{
EDITOR.FFGJOC(true);
}
EDITOR.FFIRFF = "section";
var selMarchers = this.FFROPQ(mainMarcher);
var selByFlagColor = (mainMarcher.section == SECTION_GUARD && EDITOR.isPremium) ? true : false;
for (m=0; m < selMarchers.length; m++)
{
EDITOR.FFQFPT( selMarchers[m] );
}
};
this.FFROPQ = function (mainMarcher)
{
var smarchers = [];
var selByFlagColor = (mainMarcher.section == SECTION_GUARD && EDITOR.isPremium) ? true : false;
for (m=0; m < this.marchers.length; m++)
{
var marcher = this.marchers[m];
if (selByFlagColor)
{
if (marcher.section == mainMarcher.section && marcher.flagNum == mainMarcher.flagNum)
{
smarchers.push(marcher);
}
}
else
{
if (marcher.section == mainMarcher.section && marcher.hornType == mainMarcher.hornType && marcher.state == mainMarcher.state)
{
smarchers.push(marcher);
}
}
}
return smarchers;
};
this.FFTTAJ = function (baseMarcher)
{
var selMarchers = this.FFROPQ(baseMarcher);
for (m=0; m < selMarchers.length; m++)
{
var marcher = selMarchers[m];
if (marcher.FFBTPK)
{
EDITOR.FFRUFU(marcher);
}
}
};
this.selectEveryOtherMarcher = function (isCtrl)
{
if (! this.requireOrderSelect())  {  return false; }
var start = (isCtrl) ? 0 : 1;
EDITOR.FFUXRH('splitselect', true);
var deselect = [];
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
if (m % 2 == start)
{
deselect.push(EDITOR.FFFMJP[m]);
}
}
for (m=0; m < deselect.length; m++)
{
EDITOR.FFRUFU(deselect[m]);
}
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
};
this.selectLongestMarcher = function ()
{
if (this.FFPJVV == 0)
{
alert("This only works after the first set.");
return false;
}
this.saveSet();
var longest = this.getLongestPath(this.FFPJVV - 1, true);
if (longest['marchers'].length)
{
EDITOR.FFGJOC(true);
for (m=0; m < longest['marchers'].length; m++)
{
EDITOR.FFQFPT(longest['marchers'][m]);
}
var numSteps = Math.ceil(longest['dist'] / 9.0);
var avg = Math.ceil(longest['avg'] / 9.0);
action_message("Longest path to this set: &nbsp; <span style=\"font-size: 120%; color: #F0D417\">" + numSteps + "</span>&nbsp; steps", 0,1200);
}
};
this.FFKUGO = function (useHighlighted)
{
this.FFDSXP = this.FFOFOJ(useHighlighted);
};
this.FFOFOJ = function (useHighlighted)
{
if (useHighlighted && EDITOR.FFBPXP && MOUSE_DOWN)
{
return [EDITOR.FFBPXP.x, EDITOR.FFBPXP.y];
}
return this.getCenterPoint(EDITOR.FFFMJP);
};
this.getCenterPoint = function (marchers, setNum)
{
var stop =  9999;
var sleft =  9999;
var sright = -9999;
var sbot = -9999;
for (var m=0; m < marchers.length; m++)
{
var marcher = marchers[m];
var mx = marcher.x;
var my = marcher.y;
if (setNum !== undefined)
{
mx = marcher.sets[setNum][0];
my = marcher.sets[setNum][1];
}
if (mx < sleft)  sleft = mx;
if (mx > sright) sright = mx;
if (my < stop)   stop = my;
if (my > sbot)   sbot = my;
}
return [sleft + ((sright - sleft) / 2), stop + ((sbot - stop) / 2)];
};
this.getCenterDot = function (dots)
{
var stop =  9999;
var sleft =  9999;
var sright = -9999;
var sbot = -9999;
for (var d,i=0; d = dots[i]; i++)
{
if (d[1] < sleft)  sleft = d[1];
if (d[1] > sright) sright = d[1];
if (d[2] < stop)   stop = d[2];
if (d[2] > sbot)   sbot = d[2];
}
return [sleft + ((sright - sleft) / 2), stop + ((sbot - stop) / 2)];
};
this.rotateMarchers = function (direction, isFine)
{
if (EDITOR.FFBPXP && MOUSE_DOWN)
{
isFine = true;
}
if (EDITOR.FFFMJP.length > 1)
{
EDITOR.FFUXRH('rotate');
this.FFKUGO(true);
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].rotate(this.FFDSXP, direction, isFine);
}
}
};
this.scaleMarchers = function (directionX, directionY, isFine, skipChange)
{
if (EDITOR.FFBPXP && MOUSE_DOWN)
{
isFine = true;
}
if (EDITOR.FFFMJP.length > 1)
{
if (! skipChange) {  EDITOR.FFUXRH('scale'); }
this.FFKUGO(true);
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].scale(this.FFDSXP, directionX, directionY, isFine);
}
}
};
this.toggleMarcherState = function (isReverse)
{
if (EDITOR.FFFMJP.length > 0)
{
var baseState = EDITOR.FFFMJP[0].state >> 0;
var baseSection = EDITOR.FFFMJP[0].section >> 0;
var baseEquipment = 0;
if (baseSection == SECTION_GUARD)
{
baseEquipment = EDITOR.FFFMJP[0].equipment.equipmentType;
}
var skipUpdate = false;
if (baseSection == SECTION_GUARD)
{
if (EDITOR.isPremium)
{
var diff = (isReverse) ? -1 : 1;
if (! EDITOR.animScroll)
{
diff = 0;
skipUpdate = true;
}
var nextState = baseState + diff;
if (nextState > NUM_ANIMS[baseEquipment] - 1)
{
nextState = 0;
}
else if (nextState < 0)
{
nextState = NUM_ANIMS[baseEquipment] - 1;
}
var animName = ANIM[baseEquipment][nextState].name;
if (animName)
{
var nextLabel = nextState + 1;
var anum = "<span style=\"font-size: 125%; position: relative; top: 3px; color: #FFBB4A; margin-right: 16px\">" + nextLabel + "</span>";
action_message(anum + animName, 0, 1500);
}
else
{
clear_action_message();
}
if (EDITOR.isPremium)
{
EDITOR.animScroll = true;
if (EDITOR.scrollID)
{
clearTimeout(EDITOR.scrollID);
EDITOR.scrollID = 0;
}
EDITOR.scrollID = setTimeout("EDITOR.animScroll = false;", 1500);
}
}
}
if (skipUpdate)
{
return false;
}
var newState = -1;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var marcher = EDITOR.FFFMJP[m];
var sectionMatch = baseSection;
if (sectionMatch == SECTION_SNARE || sectionMatch == SECTION_TENOR)
{
if (marcher.section == SECTION_SNARE || marcher.section == SECTION_TENOR)
{
sectionMatch = marcher.section;
}
}
if (marcher.section == sectionMatch)
{
if (sectionMatch == SECTION_GUARD && marcher.equipment.equipmentType != baseEquipment)
{
}
else
{
newState = marcher.togglePlayState(baseState, isReverse);
}
}
}
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
}
if (newState >= 0)
{
if (baseSection == SECTION_SNARE || baseSection == SECTION_TENOR || baseSection == SECTION_PLATES)
{
action_message(MARCHER_STATE_NAME[ newState ]);
}
}
};
this.toggleMarcherStateNew = function (isReverse)
{
if (EDITOR.FFFMJP.length > 0)
{
var baseState = EDITOR.FFFMJP[0].state >> 0;
var baseSection = EDITOR.FFFMJP[0].section >> 0;
var baseEquipment = 0;
if (baseSection == SECTION_GUARD)
{
baseEquipment = EDITOR.FFFMJP[0].equipment.equipmentType;
}
var skipUpdate = false;
if (baseSection == SECTION_GUARD)
{
if (EDITOR.isPremium)
{
var diff = (isReverse) ? -1 : 1;
if (! EDITOR.animScroll)
{
diff = 0;
skipUpdate = true;
}
var nextState = baseState + diff;
if (nextState > NUM_ANIMS[baseEquipment] - 1)
{
nextState = 0;
}
else if (nextState < 0)
{
nextState = NUM_ANIMS[baseEquipment] - 1;
}
var animName = ANIM[baseEquipment][nextState].name;
if (animName)
{
var nextLabel = nextState + 1;
var anum = "<span style=\"font-size: 125%; position: relative; top: 3px; color: #FFBB4A; margin-right: 16px\">" + nextLabel + "</span>";
show_action_message(anum + animName);
}
else
{
clear_action_message();
}
if (EDITOR.isPremium)
{
EDITOR.animScroll = true;
}
}
}
if (skipUpdate)
{
return false;
}
var newState = -1;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var marcher = EDITOR.FFFMJP[m];
var sectionMatch = baseSection;
if (sectionMatch == SECTION_SNARE || sectionMatch == SECTION_TENOR)
{
if (marcher.section == SECTION_SNARE || marcher.section == SECTION_TENOR)
{
sectionMatch = marcher.section;
}
}
if (marcher.section == sectionMatch)
{
if (sectionMatch == SECTION_GUARD && marcher.equipment.equipmentType != baseEquipment)
{
}
else
{
newState = marcher.togglePlayState(baseState, isReverse);
}
}
}
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
}
if (newState >= 0)
{
if (baseSection == SECTION_SNARE || baseSection == SECTION_TENOR || baseSection == SECTION_PLATES)
{
action_message(MARCHER_STATE_NAME[ newState ]);
}
}
};
this.ghostMarchers = function (isCtrl)
{
if (EDITOR.FFFMJP.length)
{
if (isCtrl)
{
for (m=0; m < EDITOR.show.marchers.length; m++)
{
if (! EDITOR.show.marchers[m].FFBTPK)
{
EDITOR.show.marchers[m].setGhost(true);
}
}
}
else
{
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].setGhost(true);
}
EDITOR.FFGJOC();
}
action_message("Ghost is ON");
}
else
{
var gmarchers = [];
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].isGhost)
{
this.marchers[m].setGhost(false);
gmarchers.push(this.marchers[m]);
}
}
EDITOR.show.FFNAOT(gmarchers);
}
};
this.hideProps = function ()
{
if (! EDITOR.isPremium) { return false; }
EDITOR.show.propsHidden = (EDITOR.show.propsHidden + 1) % 2;
var numProps = 0;
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_PROP)
{
this.marchers[m].deselect();
++ numProps;
}
}
if (! numProps)
{
alert('Sorry, no props found.\n\nUse the Studio below to add some to the show.');
return false;
}
if (EDITOR.show.propsHidden)
{
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_PROP && ! this.marchers[m].isDeleted)
{
this.marchers[m].setGhost(true);
}
}
}
else
{
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_PROP && ! this.marchers[m].isDeleted)
{
this.marchers[m].setGhost(false);
}
}
}
};
this.toggleMarcherEquipment = function ()
{
if (EDITOR.FFFMJP.length > 0)
{
var mainMarcher = EDITOR.FFFMJP[0];
if (mainMarcher.section == SECTION_GUARD)
{
EDITOR.show.changeFlags();
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
}
else if (mainMarcher.section == SECTION_BRASS)
{
this.toggleHornType();
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
}
else
{
alert("You can only change equipment for brass or guard members.");
return 0;
}
}
};
this.toggleMarcherUniformNum = function ()
{
if (EDITOR.FFFMJP.length > 0)
{
var mainMarcher = EDITOR.FFFMJP[0];
if (mainMarcher.section == SECTION_GUARD)
{
EDITOR.show.changeUniforms();
EDITOR.show.FFNAOT(EDITOR.FFFMJP);
}
}
};
this.toggleMarcherNoinst = function ()
{
if (! EDITOR.FFFMJP.length) { return false; }
var baseSection = EDITOR.FFFMJP[0].section >> 0;
var baseState = EDITOR.FFFMJP[0].state >> 0;
if (baseSection != SECTION_GUARD && baseSection != SECTION_BASS)
{
var newState = (baseState != ANIM_NOINST) ? ANIM_NOINST : 0;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
if (EDITOR.FFFMJP[m].section != SECTION_GUARD)
{
EDITOR.FFFMJP[m].setState(newState);
}
}
}
};
this.toggleHornType = function ()
{
if (this.maxSet != 0)
{
if (! throttle("equipment", 20 * 1000) )
{
if (! confirm("Change equipment for these marchers?"))
{
return 0;
}
}
}
var baseState = EDITOR.FFFMJP[0].hornType;
var newHorn = (baseState + 1) % NUM_HORN_TYPES;
action_message(HORN_NAME[newHorn]);
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
if (EDITOR.FFFMJP[m].section == SECTION_BRASS)
{
EDITOR.FFFMJP[m].toggleEquipment(newHorn);
}
}
};
this.addMetronome = function ()
{
if (EDITOR.metronome)
{
if (EDITOR.metronome.isDeleted)
{
EDITOR.metronome.undelete();
action_message("Mr. Metronome On");
}
else
{
EDITOR.metronome.dodelete();
action_message("Mr. Metronome Off");
}
return false;
}
else
{
if (! confirm("Add Mr. Metronome to this show?\n\nThis is for synced shows ONLY.\n\nHe will NOT appear in the show, and will only affect the tempo in Preview mode."))  return false;
var mrMet = this.addMarcher(EDITOR.show.marchers.length, [SECTION_METRONOME, 0], [snapX((6 * 72)) - 19, snapY(350), 0]);
mrMet.spawnSetPin();
EDITOR.FFGJOC();
EDITOR.FFQFPT(mrMet);
action_message("Added Mr. Metronome");
mrMet.propagateSets();
this.saveSet();
return true;
}
};
this.addSixthBass = function ()
{
if (! EDITOR.isPremium)
{
return false;
}
if (this.maxSet != 0)
{
}
if (EDITOR.show.numBasses >= 6)
{
alert("Sorry, you already have a sixth bass.");
return 0;
}
if (! confirm("Add Bass #6 to this show?"))
{
return false;
}
var bass6 = this.addMarcher(EDITOR.show.marchers.length, [SECTION_BASS, 0], [snapX((6 * 72)) - 19, snapY(350), 0]);
bass6.spawnSetPin();
EDITOR.FFGJOC();
EDITOR.FFQFPT(bass6);
action_message("Added Sixth Bass");
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_BASS)
{
bass6.setState( this.marchers[m].state );
break;
}
}
bass6.propagateSets();
this.saveSet();
return true;
};
this.toggleMarcherCaption = function ()
{
if (! EDITOR.isPremium)
{
return false;
}
if (! EDITOR.FFFMJP.length)
{
return 0;
}
if (this.maxSet != 0)
{
if (! throttle("caption", 20 * 1000) )
{
if (! confirm("Change caption for these marchers?"))
{
return 0;
}
}
}
if (EDITOR.FFFMJP.length > 0)
{
var baseSection = EDITOR.FFFMJP[0].section >> 0;
if (baseSection == SECTION_BASS)
{
alert("Sorry, you can't change the basses.");
return 0;
}
if (baseSection == SECTION_PROP || baseSection == SECTION_METRONOME)
{
return 0;
}
var newSection = (baseSection + 1) % 6;
if (newSection == SECTION_BASS) { newSection ++; }
if (newSection == SECTION_GUARD)
{
var selMarchers = this.getMarchersInSection(newSection);
if (selMarchers.length + EDITOR.FFFMJP.length > MAX_GUARD_PER_SHOW)
{
newSection ++;
}
}
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var thisSection = EDITOR.FFFMJP[m].section;
if (thisSection == SECTION_BASS || thisSection == SECTION_PROP || thisSection == SECTION_METRONOME)
{
}
else
{
EDITOR.FFFMJP[m].toggleSection(newSection);
}
}
this.saveSet();
}
};
this.getMarchersInSection = function (section)
{
var sectionMarchers = []
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
if (marcher.section == section)
{
sectionMarchers.push(marcher);
}
}
return sectionMarchers;
};
this.addPivotPoint = function ()
{
for (var m=0; m < EDITOR.FFFMJP.length; m++)
{
if (EDITOR.FFFMJP[m].pivotKey)
{
this.clearPivot(EDITOR.FFFMJP[m].pivotKey);
return;
}
}
var pivotPos = [];
var pivotOn = "";
var pivotDetail = [];
var pivotMarchers = EDITOR.FFFMJP.slice();
if (EDITOR.FFBPXP)
{
pivotOn = "marcher";
pivotTarget = EDITOR.FFBPXP;
pivotPos = [ EDITOR.FFBPXP.x, EDITOR.FFBPXP.y ];
}
else
{
pivotOn = "center";
pivotTarget = {};
pivotPos = this.FFOFOJ();
}
if (! this.pivots[this.FFPJVV])  this.pivots[this.FFPJVV] = {};
var pivotKey = "p" + EDITOR.FFFMJP[0].id;
this.pivots[this.FFPJVV][pivotKey] = [ pivotPos, pivotOn, pivotTarget, pivotMarchers, { direction : 1, prevPoint : pivotPos, tweenPoint : pivotPos } ];
for (var m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].addPivot(pivotKey);
}
var pivotBlipID = 'pivot' + pivotKey;
var centerBlip = EDITOR.newBlip(pivotBlipID, 'red');
EDITOR.moveBlip(pivotBlipID , pivotPos[0] + 8, pivotPos[1] + 32);
action_message("Pivot Added");
};
this.clearPivot = function (pivotKey)
{
var pivot = this.pivots[this.FFPJVV][pivotKey];
for (var m=0; m < pivot[3].length; m++)
{
pivot[3][m].clearPivot();
}
delete this.pivots[this.FFPJVV][pivotKey];
EDITOR.clearBlip('pivot' + pivotKey);
action_message("Pivot Cleared");
};
this.initTweenPivots = function ()
{
for (var p in this.pivots[this.FFPJVV + 1])
{
var pivot = this.pivots[this.FFPJVV + 1][p];
if (! pivot.length) continue;
if (pivot[1] == "center")
{
pivot[4]['prevPoint'] = this.getCenterPoint(pivot[3], this.FFPJVV);
pivot[0] = this.getCenterPoint(pivot[3], this.FFPJVV+1);
}
else if (pivot[1] == "marcher")
{
var target = pivot[2];
var prevSet = target.sets[this.FFPJVV];
var nextSet = target.sets[this.FFPJVV+1];
pivot[4]['prevPoint'] = [ prevSet[0], prevSet[1] ];
pivot[0] = [ nextSet[0], nextSet[1] ];
}
EDITOR.moveBlip("pivot"+p, pivot[4]['prevPoint'][0]+ 8, pivot[4]['prevPoint'][1]+32);
pivot[4]['direction'] = 1;
var pivotStartPos = pivot[4]['prevPoint'];
var pivotEndPos = pivot[0];
var marchers = pivot[3];
for (var m=0; m < marchers.length; m++)
{
var marcher = marchers[m];
var from = marcher.sets[this.FFPJVV];
var to = marcher.sets[this.FFPJVV+1];
marcher.pivotStartRadius = get_distance(from, pivotStartPos);
marcher.pivotEndRadius = get_distance(to, pivotEndPos);
marcher.pivotStartAngle = FFMBEJ(from, pivotStartPos);
marcher.pivotEndAngle = FFMBEJ(to, pivotEndPos);
if (pivot[4]['direction'] > 0 && marcher.pivotEndAngle  < marcher.pivotStartAngle) { marcher.pivotEndAngle += 360; }
}
}
};
this.tweenPivots = function (progress)
{
for (var p in this.pivots[this.FFPJVV + 1])
{
var pivot = this.pivots[this.FFPJVV + 1][p];
var from = pivot[4]['prevPoint'];
var to = pivot[0];
var tweenX = from[0] + (to[0] - from[0]) * progress;
var tweenY = from[1] + (to[1] - from[1]) * progress;
pivot[4]['tweenPoint'] = [ tweenX, tweenY ];
EDITOR.moveBlip("pivot"+p, tweenX+8, tweenY+32);
}
};
this.followTheLeaderNew = function (isCtrl)
{
if (EDITOR.FFFMJP.length < 3)  return false;
if (! this.requireOrderSelect()) return false;
if (! this.ftlTrains[this.FFPJVV])  this.ftlTrains[this.FFPJVV] = {};
var trainMarchers = EDITOR.FFFMJP.slice();
if (isCtrl)  trainMarchers.reverse();
var leader = trainMarchers[0];
if (! this.ftlTrains[this.FFPJVV][leader.id])
{
this.ftlTrains[this.FFPJVV][leader.id] = {};
train[m].setTrainLeader(this.FFPJVV);
for (var m=1; m < trainMarchers.length; m++)
{
trainMarchers[m].setTrainFollower(this.FFPJVV);
}
}
};
this.followTheLeader = function (isCtrl)
{
if (EDITOR.FFFMJP.length > 2)
{
if (! this.requireOrderSelect())  {  return false; }
EDITOR.FFUXRH();
var train = EDITOR.FFFMJP.slice();
if (isCtrl)
{
train.reverse();
}
var prevSpot = [];
var numMarchers = train.length;
var leader = train[0];
EDITOR.setLeader(leader);
for (m=0; m < numMarchers; m++)
{
prevSpot[m] = [train[m].x, train[m].y];
}
var offX = train[0].x - train[1].x;
var offY = train[0].y - train[1].y;
leader.move(train[0].x + offX, leader.y + offY);
for (m=1; m < train.length; m++)
{
train[m].move(prevSpot[m-1][0], prevSpot[m-1][1]);
}
}
};
this.clearRipples = function ()
{
if (! this.ripples[this.FFPJVV] || ! this.ripples[this.FFPJVV].length)
{
alert("There are no ripples in this set.");
return false;
}
action_message("Ripples Cleared");
this.ripples[this.FFPJVV] = [];
};
this.getRippleStats = function ()
{
var numSteps = 0;
var numRipples = 0;
for (var i=0; i < this.ripples.length; i++)
{
var rs = this.ripples[i];
if (rs)
{
numRipples += rs.length;
numSteps += this.countRippleStepsForSet(rs);
}
}
return {  numSteps: numSteps, numRipples: numRipples };
};
this.getRippleSets = function ()
{
var rippleSetNums = [];
for (var i=0; i < this.ripples.length; i++)
{
var rs = this.ripples[i];
if (rs)
{
if (rs.length) rippleSetNums.push(i+1);
}
}
return rippleSetNums;
};
this.showRippleStatusOLD = function ()
{
var currentRipples = this.ripples[this.FFPJVV] || [];
var numSteps = this.countRippleStepsForSet(currentRipples);
var ripStat = this.getRippleStats();
alert("Ripples in this set: " + currentRipples.length + ", with " + numSteps + " steps.\n\nRipples in the show: " + ripStat.numRipples + ", with " + ripStat.numSteps + " steps (max: "+ MAX_RIPPLE_STEPS +")");
};
this.showRippleStatus = function ()
{
var ripSets = this.getRippleSets();
var ripNums = ripSets.join(', ');
alert("You can only have ripples in " + MAX_RIPPLE_SETS + " sets.\n\nThese are the set numbers you have ripples in: " + ripNums + "\n\nTip: You can go to a set and press Ctrl-@ to clear all ripples in that set.");
};
this.countRippleStepsForSet = function (ripples)
{
var numSteps = 0;
var seen = [];
for (var ripple,j=0; ripple=ripples[j]; j++)
{
for (var i=0; i < ripple.length; i++)
{
var marcherID = ripple[i];
if (! seen[marcherID]) {  numSteps += 1; seen[marcherID] = 1; }
}
}
return numSteps;
};
this.isValidRipple = function (ripple)
{
var numMarchers = ripple.length;
for (var m=0; m < numMarchers; m++)
{
var marcher = EDITOR.marcherById[ripple[m]];
var thisSet = marcher.sets[this.FFPJVV];
var nextSet = marcher.sets[this.FFPJVV + 1];
if (marcher.section == SECTION_GUARD)
{
if (marcher.flagNum != nextSet[3])
{
alert("Sorry, you can't ripple into an equipment change.");
return false;
}
if (nextSet[2] > NUM_FLAG_POSES - 1)
{
alert("The next set for a ripple must be a pose (not an animation).");
return false;
}
}
else
{
if (nextSet[2] == 3 && marcher.x != nextSet[0] && marcher.y != nextSet[1])
{
alert("You can't ripple into a kneel position if the marcher is moving.");
return false;
}
}
if (nextSet[2] == thisSet[2])
{
alert("You need to change the marcher's animation in the next set for a ripple to work.");
return false;
}
}
return true;
};
this.addRipple = function (isCtrl)
{
if (! EDITOR.isPremium) {  alert('Ripples can only be added by upgrading to Premium membership.'); return false; }
if (this.maxSet == 0) {  alert('You need more than one set to add a ripple.'); return false; }
if (this.FFPJVV + 1 > this.maxSet)  {  alert("Try adding the ripple to the preceding set.");  return false; }
if (EDITOR.FFFMJP.length < 2) {  alert("You need to select at least 2 marchers to form a ripple.");  return false; }
if (! this.requireOrderSelect())  {  return false; }
var group = EDITOR.FFFMJP.map( function (m) { return m.id; } );
if (! this.isValidRipple(group))  return false;
if (! this.ripples[this.FFPJVV]) this.ripples[this.FFPJVV] = [];
var ripSets = this.getRippleSets();
if (ripSets.length >= MAX_RIPPLE_SETS && ! this.ripples[this.FFPJVV].length)
{
var ripNums = ripSets.join(', ');
alert("You can only have ripples in " + MAX_RIPPLE_SETS + " sets.\n\nThese are the set numbers you have ripples in: " + ripNums + "\n\nTip: You can go to a set and press Ctrl-@ to clear all ripples in that set.");
return false;
}
var thisSetRipples = this.ripples[this.FFPJVV];
var flatRipple = group.join(',');
for (var i=0,r; r=thisSetRipples[i]; i++)
{
var flat = r.join(',');
if (flat == flatRipple)  {  alert('This ripple is already added.');  return false; }
}
thisSetRipples.push(group);
action_message("Ripple Added");
};
this.requireOrderSelect = function ()
{
if (! this.isOrderSelected())
{
alert("To use this shortcut, the marchers need to be selected in order.\n\nTip:  Use Ctrl-Click to select them one at a time.\n\nOr hold down the ! key and use the wand to select each marcher.\n\nWhen they are selected in order, you will see an arrow (=>) next to the # Selected in the lower right.");
EDITOR.FFGJOC(true);
return false;
}
return true;
};
this.isOrderSelected = function ()
{
return ! (EDITOR.FFIRFF == "box" || EDITOR.FFIRFF == "all" || EDITOR.FFIRFF == "section");
};
this.cleanBlock = function (FFTOAK)
{
if (EDITOR.FFFMJP.length < 4)
{
alert("You need at least 4 marchers to form a block.");
return false;
}
var FFNAHE = [999,-999,-999,999];
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var marcher = EDITOR.FFFMJP[m];
if (marcher.y < FFNAHE[0])
FFNAHE[0] = marcher.y;
if (marcher.x > FFNAHE[1])
FFNAHE[1] = marcher.x;
if (marcher.y > FFNAHE[2])
FFNAHE[2] = marcher.y;
if (marcher.x < FFNAHE[3])
FFNAHE[3] = marcher.x;
}
if (FFNAHE[1] == FFNAHE[3] || FFNAHE[0] == FFNAHE[2])
{
this.cleanLine();
return true;
}
if (FFTOAK)
{
var FFWMHV = FFNAHE[1] - FFNAHE[3];
var FFUFDE = FFNAHE[2] - FFNAHE[0];
if (FFWMHV > FFUFDE)
{
FFNAHE[0] -= (FFWMHV - FFUFDE) / 2;
FFNAHE[2] += (FFWMHV - FFUFDE) / 2;
}
else
{
FFNAHE[1] += (FFUFDE - FFWMHV) / 2;
FFNAHE[3] -= (FFUFDE - FFWMHV) / 2;
}
}
var FFXMJC = [];
if (! FFTOAK)
{
var FFIUTN = 0;
var FFGBAA = false;
var FFGTOE = false;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var marcher = EDITOR.FFFMJP[m];
if (Math.abs(marcher.x - FFNAHE[3]) < 12 )
{
++ FFIUTN;
if (Math.abs(marcher.y - FFNAHE[0]) < 12)
{
FFGBAA = true;
}
if (Math.abs(marcher.y - FFNAHE[2]) < 12)
{
FFGTOE = true;
}
}
}
if (FFIUTN > 1 && FFGBAA && FFGTOE)
{
if (EDITOR.FFFMJP.length % FFIUTN == 0)
{
var FFWOUP = EDITOR.FFFMJP.length / FFIUTN;
FFXMJC = [FFWOUP, FFIUTN];
}
}
}
if (! FFXMJC[0])
{
var FFDKIL = 99;
for (x=2; x <= EDITOR.FFFMJP.length / 2; x++)
{
if (EDITOR.FFFMJP.length % x == 0)
{
var y = EDITOR.FFFMJP.length / x;
if (x + y < FFDKIL)
{
FFDKIL = x + y;
FFXMJC = [x,y];
}
}
}
}
if (! FFXMJC[0])
{
alert("Sorry, you can't make an even block with " + EDITOR.FFFMJP.length + " marchers.");
return false;
}
EDITOR.FFUXRH();
var FFWMHV = FFNAHE[1] - FFNAHE[3];
var FFUFDE = FFNAHE[2] - FFNAHE[0];
if (FFWMHV > FFUFDE && FFXMJC[0] < FFXMJC[1])
{
tmp = FFXMJC[0];
FFXMJC[0] = FFXMJC[1];
FFXMJC[1] = tmp;
}
var blockIntX = FFWMHV / (FFXMJC[0] - 1);
var blockIntY = FFUFDE / (FFXMJC[1] - 1);
var FFJTRB = [];
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
FFJTRB.push(EDITOR.FFFMJP[m]);
}
FFJTRB.sort(function (a,b) { return a.y - b.y });
for (y=0; y <= FFXMJC[1] - 1; y++)
{
row = [];
for (x=0; x <= FFXMJC[0] - 1; x++)
{
row.push(FFJTRB.shift());
}
row.sort(function (a,b) { return a.x - b.x })
for (x=0; x <= FFXMJC[0] - 1; x++)
{
var pegX = FFNAHE[3] + x * blockIntX;
var pegY = FFNAHE[0] + y * blockIntY;
var marcher = row[x];
marcher.move(pegX, pegY);
}
}
};
this.cleanCurve = function (isCtrl)
{
if (EDITOR.FFFMJP.length < 3)
{
return false;
}
if (! this.requireOrderSelect())  {  return false; }
EDITOR.FFUXRH('curve');
for (var j = 0; j < 3; j ++)
{
var totalDist = 0;
var intervals = [];
for (var i=1,m; m = EDITOR.FFFMJP[i]; i++)
{
var prev = EDITOR.FFFMJP[i - 1];
var dist = m.FFDCCO([ prev.x, prev.y ]);
intervals[ m.id ] = dist;
totalDist += dist;
}
var avgInterval = totalDist / (EDITOR.FFFMJP.length - 1);
var prevAngle = 0;
for (var i=1,m; i < EDITOR.FFFMJP.length - 1; i++)
{
var m = EDITOR.FFFMJP[i];
var prev = EDITOR.FFFMJP[i - 1];
var newAngle = m.angleToMarcher(prev);
var currInterval = m.FFDCCO([ prev.x, prev.y ]);
var moveDist = avgInterval - currInterval;
var newX = m.x + Math.sin(newAngle * Math.PI / 180) * moveDist;
var newY = m.y + Math.cos(newAngle * Math.PI / 180) * moveDist * -1.0;
m.move(newX, newY);
}
}
};
this.cleanLine = function (isCtrl, skipHistory)
{
if (EDITOR.FFFMJP.length < 3)
{
return false;
}
if (! skipHistory)
{
EDITOR.FFUXRH();
}
this.FFKUGO();
EDITOR.FFFMJP.sort(function (a,b) { return a.id - b.id })
var marcher1 = null;
var FFEUUS = 0;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var dist = EDITOR.FFFMJP[m].FFDCCO(this.FFDSXP);
if (dist > FFEUUS)
{
marcher1 = EDITOR.FFFMJP[m];
FFEUUS = dist;
}
}
var marcher2 = null;
FFEUUS = 0;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].FFQBJV([marcher1.x, marcher1.y]);
var dist = EDITOR.FFFMJP[m].FFPHLH;
if (dist > FFEUUS)
{
marcher2 = EDITOR.FFFMJP[m];
FFEUUS = dist;
}
}
EDITOR.FFFMJP.sort(function (a,b) { return a.FFPHLH - b.FFPHLH })
var hastop = false;
var hasbot = false;
if (marcher1.x != marcher2.x && marcher1.y != marcher2.y && ! isCtrl)
{
for (m=1; m < EDITOR.FFFMJP.length-1; m++)
{
var marcher = EDITOR.FFFMJP[m];
if (marcher.x != marcher1.x && marcher.y == marcher1.y)
{
hastop = true;
}
else if (marcher.x != marcher2.x && marcher.y == marcher2.y)
{
hasbot = true;
}
}
}
if (hastop && hasbot)
{
if (Math.abs(marcher1.x - marcher2.x) > Math.abs(marcher1.y - marcher2.y))
{
var newY = marcher1.y - ((marcher1.y - marcher2.y) / 2);
marcher1.move(marcher1.x, newY);
marcher2.move(marcher2.x, newY);
}
else
{
var newX = marcher1.x - ((marcher1.x - marcher2.x) / 2);
marcher1.move(newX, marcher1.y);
marcher2.move(newX, marcher2.y);
}
}
if (! isCtrl)
{
if (Math.abs(marcher1.x - marcher2.x) < 16)
{
marcher2.move(marcher1.x, marcher2.y);
}
if (Math.abs(marcher1.y - marcher2.y) < 16)
{
marcher2.move(marcher2.x, marcher1.y);
}
}
var intX = (marcher2.x - marcher1.x) / (EDITOR.FFFMJP.length - 1);
var intY = (marcher2.y - marcher1.y) / (EDITOR.FFFMJP.length - 1);
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var newX = marcher1.x + intX * m;
var newY = marcher1.y + intY * m;
EDITOR.FFFMJP[m].move(newX, newY);
}
if (! skipHistory)
{
}
};
this.FFEKAT = function ()
{
this.arcFocusAngle = (360 + this.FFJSIP - (90 * this.arcDirection)) % 360;
};
this.arcMarchers = function (direction, isFine)
{
if (EDITOR.FFFMJP.length < 3)
{
return false;
}
isFine = (isFine) ? true : false;
if (this.reverseArcKey)
{
}
var isInit = false;
if (! this.FFVPSA)
{
EDITOR.FFUXRH('arc');
this.FFVPSA = 100;
this.arcDirection = direction;
var prevAngles = [];
var center = this.FFOFOJ();
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var marcher = EDITOR.FFFMJP[m];
prevAngles.push( FFMBEJ([marcher.x, marcher.y], center ) );
}
this.cleanLine(true, true);
this.FFGIMI = this.FFOFOJ();
this.FFJSIP = EDITOR.FFFMJP[0].angleToMarcher(EDITOR.FFFMJP[EDITOR.FFFMJP.length-1]);
if (this.FFJSIP > 180) { this.FFJSIP -= 180; }
var totalOffset = 0;
for (var i = 0; i < prevAngles.length; i++)
{
totalOffset += angle_difference(360 + prevAngles[i], 360 + this.FFJSIP);
}
this.arcDirection = (totalOffset < 0) ? -1 : 1;
this.FFEKAT();
isInit = true;
}
else
{
var dist = this.FFVPSA * 0.2 * (direction * this.arcDirection);
if (isFine) {  dist *= 0.25; }
this.FFVPSA -= dist;
if (this.FFVPSA < 20)
{
this.FFVPSA = 20;
}
else if (this.FFVPSA > 350)
{
this.FFVPSA = 300;
this.arcDirection = (this.arcDirection > 0) ? -1 : 1;
this.reverseArcKey = (this.reverseArcKey) ? false : true;
this.FFEKAT();
}
}
this.moveArcFocus();
this.moveMarchersToArc();
};
this.moveArcFocus = function ()
{
this.arcFocus[0] = this.FFGIMI[0] + Math.sin(this.arcFocusAngle * Math.PI / 180) * this.FFVPSA;
this.arcFocus[1] = this.FFGIMI[1] + Math.cos(this.arcFocusAngle * Math.PI / 180) * this.FFVPSA * -1.0;
};
this.moveMarchersToArc = function ()
{
this.cleanLine(true, true);
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].FFDQOR(this.arcFocus, this.arcFocusAngle);
}
EDITOR.FFFMJP.sort(function (a,b) { return a.FFIFIX - b.FFIFIX });
if (this.arcDirection < 0)
{
}
var axisLen = EDITOR.FFFMJP[0].FFDCCO(this.FFGIMI);
var totalAngle = Math.atan2(axisLen * Math.PI / 180.0, this.FFVPSA * Math.PI / 180.0) * 180.0 / Math.PI;
totalAngle *= 2.0;
var startAngle = FFMBEJ([EDITOR.FFFMJP[0].x, EDITOR.FFFMJP[0].y], this.arcFocus);
var angleInterval = totalAngle / (EDITOR.FFFMJP.length-1);
var rad = EDITOR.FFFMJP[0].FFDCCO(this.arcFocus);
for (m=1; m < EDITOR.FFFMJP.length-1; m++)
{
var newAngle = startAngle + angleInterval * m;
var newX = this.arcFocus[0] + Math.sin(newAngle * Math.PI / 180) * rad;
var newY = this.arcFocus[1] + Math.cos(newAngle * Math.PI / 180) * rad * -1.0;
EDITOR.FFFMJP[m].move(newX, newY);
}
};
this.circleMarchers = function (doAlign, isOval)
{
if (EDITOR.FFFMJP.length < 3)
{
return false;
}
EDITOR.FFUXRH();
this.FFKUGO();
var FFWMHV = 0;
var FFUFDE = 0;
if (isOval)
{
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var marcher = EDITOR.FFFMJP[m];
var distX = Math.abs(this.FFDSXP[0] - marcher.x);
var distY = Math.abs(this.FFDSXP[1] - marcher.y);
if (distX > FFWMHV) {  FFWMHV = distX; }
if (distY > FFUFDE) {  FFUFDE = distY; }
}
}
else
{
var longestRadius = 0;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var radius = EDITOR.FFFMJP[m].FFDCCO(this.FFDSXP);
longestRadius += radius;
EDITOR.FFFMJP[m].FFDQOR(this.FFDSXP);
}
longestRadius = longestRadius / EDITOR.FFFMJP.length;
FFWMHV = longestRadius;
FFUFDE = longestRadius;
}
EDITOR.FFFMJP.sort(function (a,b) { return a.FFIFIX - b.FFIFIX })
var startAngle = EDITOR.FFFMJP[0].FFIFIX;
if (doAlign) {  startAngle = 0; }
var angleInterval = 360 / EDITOR.FFFMJP.length;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var newAngle = startAngle + (angleInterval * m);
var newX = this.FFDSXP[0] + Math.sin(newAngle * Math.PI / 180) * FFWMHV;
var newY = this.FFDSXP[1] + Math.cos(newAngle * Math.PI / 180) * FFUFDE * -1.0;
EDITOR.FFFMJP[m].move(newX, newY);
}
};
this.scatterMarchers = function (isCtrl)
{
if (! isCtrl) {  this.scaleMarchers(1,1,true, true); }
EDITOR.FFUXRH('scatter');
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
var offX = 0;
var offY = 0;
if (isCtrl)
{
if (rand(0,1) == 1)
{
offX = rand(-4, 4);
}
}
else
{
var step = 4;
var angle = rand(0,90) * 4;
var offX = Math.sin(angle * Math.PI / 180) * step;
var offY = Math.cos(angle * Math.PI / 180) * step * -1.0;
}
EDITOR.FFFMJP[m].nudge(offX, offY);
}
};
this.nudgeMarchers = function (offX, offY)
{
if (! EDITOR.FFFMJP.length)
{
return false;
}
EDITOR.FFUXRH('nudge');
this.FFDSXP[0] += offX;
this.FFDSXP[1] += offY;
for (m=0; m < EDITOR.FFFMJP.length; m++)
{
EDITOR.FFFMJP[m].nudge(offX, offY);
}
};
this.addMarcher = function (aid, marcherConfig, startSet)
{
if (! marcherConfig)
{
marcherConfig = [0,0];
}
var section = marcherConfig[0];
var hornType = marcherConfig[1];
var uniformNum = marcherConfig[2];
if (! section)
{
section = SECTION_BRASS;
}
var bassNum;
if (section == SECTION_BASS)
{
this.numBasses ++;
bassNum = this.numBasses;
}
var m = new oMarcher(aid, [section, hornType, uniformNum], bassNum);
m.setSprite();
m.init(startSet);
this.marchers.push(m);
EDITOR.marcherById[aid] = m;
return m;
};
this.addProps = function ()
{
if (EDITOR.hasProps)
{
alert("Sorry, you already have props in this show.");
return false;
}
if (EDITOR.show.maxSet > 0)
{
}
if (! confirm("Add props to this show?"))
{
return false;
}
if (EDITOR.cheats['chairs'])
{
var slotX = 0;
var FFOGQE = 80;
var aid = this.marchers.length;
for (var i = 0; i < 64; i ++)
{
var m = this.addMarcher(aid, [SECTION_PROP, 0], [snapX((4 * 72)) + (slotX * 31), FFOGQE, 0]);
++ aid;
++ slotX;
if (slotX % 8 == 0)
{
slotX = 0;
FFOGQE += 31;
}
m.propagateSets();
}
}
else
{
var aid = this.marchers.length;
for (var i = 0; i < 10; i ++)
{
var m = this.addMarcher(aid, [SECTION_PROP, 0], [snapX((1 * 72) + i * 72 - 12 + 36), 48, 0]);
++ aid;
m.propagateSets();
}
}
this.saveSet();
action_message("Props Added");
};
this.setLongestPath = function ()
{
var hasToss = false;
this.longestPath = 0;
for (var i = 0, m; m = this.marchers[i]; i++)
{
if (m.isDeleted) continue;
var dist = m.comparitiveDistToNextSet(this.FFPJVV);
if (dist > this.longestPath)
{
this.longestPath = dist;
}
if (m.section == SECTION_GUARD)
{
if (m.equipment.currentAnim.doToss)
{
hasToss = true;
}
}
}
this.longestPath = Math.sqrt(this.longestPath);
var longest = this.getLongestPath(this.FFPJVV);
if (EDITOR.isSlowPlay)
{
longest['dist'] *= 3;
}
else if (EDITOR.isFastPlay)
{
longest['dist'] *= 0.4;
}
this.longestPath = longest['dist'];
this.timeInterval = (this.longestPath / PIXELS_PER_SEC) * FRAME_MILLISECS;
this.timeInterval = Math.ceil((this.timeInterval) / FRAME_STEP_MILLISECS) * FRAME_STEP_MILLISECS;
if (this.setConfig[this.FFPJVV] && ! EDITOR.isFastPlay)
{
this.timeInterval += this.setConfig[this.FFPJVV][SET_CONFIG_PACE] * FRAME_STEP_MILLISECS;
}
if (this.timeInterval < FRAME_MIN_MILLISECS)
this.timeInterval = FRAME_MIN_MILLISECS;
if (hasToss && this.timeInterval < MIN_TOSS_MILLISECS)
{
this.timeInterval = MIN_TOSS_MILLISECS;
}
};
this.getLongestPath = function (fromSet)
{
var FFEUUS = 0;
var longestMarcher = 0;
var longestMarchers = [];
for (var i = 0, m; m = this.marchers[i]; i++)
{
if (m.isDeleted) continue;
if (m.isGhost) continue;
var dist = m.comparitiveDistToNextSet(fromSet);
if (dist > FFEUUS)
{
longestMarchers = [];
FFEUUS = dist;
longestMarcher = m;
}
if (dist == FFEUUS)
{
longestMarchers.push(m);
}
}
FFEUUS = Math.sqrt(FFEUUS);
return {  dist: FFEUUS, marcher: longestMarcher, marchers: longestMarchers };
};
this.setShowLength = function ()
{
var total = 0;
for (s=0; s < this.maxSet; s++)
{
total += this.setTime[s];
}
this.totalTime = total;
};
this.deleteTimekeeper = function ()
{
var timeKeepers = [];
for (var i = 0, m; m = this.marchers[i]; i++)
{
if (m.isDeleted) continue;
if (m.section == SECTION_PROP) continue;
var prevX = 0;
var prevY = 0;
var setsMoved = 0;
var margin = 80;
var outofplay = true;
for (var s = 0; s < m.sets.length; s++)
{
var set = m.sets[s];
if (prevX != set[0] || prevY != set[1])
{
++ setsMoved;
}
prevX = set[0];
prevY = set[1];
if (set[0] < FIELD_SIZE_X - margin && set[0] > margin)
{
if (set[1] < FIELD_SIZE_Y - margin && set[1] > margin)
{
outofplay = false;
break;
}
}
}
if (outofplay && setsMoved > 3)
{
timeKeepers.push(m);
}
}
if (timeKeepers.length == 1)
{
timeKeepers[0].dodelete();
}
};
this.processShowData = function (data)
{
if (data.substr(0,7) != "[begin]")
{
eval(data);
this.showConfig = showConfig;
this.loadedSets = sets;
this.setConfig = setConfig;
if (! defined(this.showConfig[SHOW_UNIFORM]))
{
this.showConfig[SHOW_UNIFORM] = 0;
this.showConfig[SHOW_FLAG1] = 0;
}
else
{
-- this.showConfig[SHOW_UNIFORM];
-- this.showConfig[SHOW_FLAG1];
}
this.showConfig[SHOW_GUARD_UNIFORM] = this.showConfig[SHOW_UNIFORM];
}
else
{
this.showConfig = [];
this.loadedSets = [];
this.setConfig = [];
var setNum = 0;
var lines = data.split(LINE_DELIM);
for (var l=0, line; line = lines[l]; l++)
{
if (lines[l].substr(0,1) == "[")  {  continue; }
var parts = lines[l].split("=");
if (parts[0] == "show")
{
var els = parts[1].split("|");
for (var e=0, el; el=els[e]; e++)
{
this.showConfig.push(el >> 0);
}
if (this.showConfig.length <= 2)
{
-- this.showConfig[SHOW_FLAG1];
-- this.showConfig[SHOW_UNIFORM];
this.showConfig[SHOW_GUARD_UNIFORM] = this.showConfig[SHOW_UNIFORM];
}
}
else if (parts[0] == "marcher")
{
var els = parts[1].split("|");
for (var e=0, el; el=els[e]; e++)
{
var section = el.charAt(0);
var hornType = el.charAt(1);
if (! hornType) {  hornType = 0; }
var uniformNum = el.charAt(2);
if (! uniformNum) {  uniformNum = this.showConfig[SHOW_GUARD_UNIFORM]; }
this.marcherConfig.push([section, hornType, uniformNum]);
}
}
else if (parts[0] == "deleted")
{
var els = parts[1].split("|");
for (var e=0, el; el=els[e]; e++)
{
var marcherID = el;
this.marcherIsDeleted[marcherID] = true;
}
}
else if (parts[0] == "set")
{
var meta = parts[1].split("!!");
var els = meta[0].split("|");
var setConf = "" + els.shift();
this.setConfig.push([toInt(setConf.charAt(0)), toInt(setConf.charAt(1))]);
var set = [];
for (var e=0, el; el=els[e]; e++)
{
var spot1 = el.substr(0,2);
var spot2 = el.substr(2,2);
var state = el.substr(4,1);
var flagNum = el.substr(5,1);
if (! defined(flagNum)) {  flagNum = this.showConfig[SHOW_FLAG1]; }
set.push([ base62_to_dec(spot1), base62_to_dec(spot2), char_base62_to_dec(state), flagNum ]);
}
this.loadedSets.push(set);
if (meta[1])
{
var metaEl = meta[1].split("|");
for (var m,i=0; m = metaEl[i]; i++)
{
var els = m.split(',');
var extType = els.shift();
var flag = els.shift();
if (extType == 'r')
{
this.ripples[setNum] = this.ripples[setNum] || [];
this.ripples[setNum].push(els);
}
}
}
++ setNum;
}
}
}
};
this.loadSaved = function (showData)
{
if (EDITOR.mode == MODE_VIEW)
{
this.editorVersion = LOADED.editorVersion;
if (! this.editorVersion)
{
this.editorVersion = EDITOR_VERSION;
}
if (this.editorVersion <= 1.01)
{
FRAME_MIN_MILLISECS = 750;
}
}
else if (EDITOR.mode == MODE_EDIT && LOADED)
{
this.editorVersion = LOADED.editorVersion;
}
if (! showData)
{
showData = LOADED.showData;
}
this.processShowData( showData );
this.isSetup = true;
if (this.showConfig.length < 1)
{
this.showConfig[SHOW_UNIFORM] = 0;
this.showConfig[SHOW_FLAG1] = 0;
}
if (! defined(this.showConfig[SHOW_GUARD_UNIFORM]))
{
this.showConfig[SHOW_GUARD_UNIFORM] = this.showConfig[SHOW_UNIFORM];
}
if (EDITOR.isPremium)
{
this.showConfig[SHOW_GUARD_UNIFORM] = 0;
}
if (EDITOR.isPremium)
{
this.showConfig[SHOW_FLAG1] = 0;
}
this.maxSet = this.loadedSets.length - 1;
this.spawnMarchers();
for (s=0; s < this.loadedSets.length; s++)
{
for (m=0; m < this.loadedSets[s].length; m++)
{
if (this.loadedSets[s][m])
{
this.marchers[m].loadSet(this.loadedSets[s][m]);
}
}
if (! this.setConfig[s])
{
this.setConfig[s] = [0,0];
}
}
for (m=0; m < this.loadedSets[0].length; m++)
{
if (this.marcherIsDeleted[ this.marchers[m].id ])
{
this.marchers[m].dodelete();
}
}
if (EDITOR.mode == MODE_VIEW && ! EDITOR.isPreview && ! EDITOR.isGroupSnapshot)
{
}
for (m=0; m < this.loadedSets[0].length; m++)
{
this.marchers[m].move(this.marchers[m].sets[0][0], this.marchers[m].sets[0][1]);
this.marchers[m].setFlag(this.marchers[m].sets[0][3]);
this.marchers[m].setState(this.marchers[m].sets[0][2]);
}
if (EDITOR.mode == MODE_VIEW && this.editorVersion <= 1.26)
{
for (m=0; m < this.loadedSets[0].length; m++)
{
if (this.marchers[m].isOutOfBounds)
{
this.marchers[m].dodelete();
}
}
}
if (EDITOR.mode == MODE_EDIT)
{
EDITOR.addExtraSets();
if (EDITOR.isPremium)
{
NUM_HORN_TYPES = NUM_HORN_TYPES_PREMIUM;
}
EDITOR.redrawSetPanel();
EDITOR.show.redrawSetConfig();
EDITOR.clearHistory();
EDITOR.spawnSetPins();
EDITOR.redrawSetBlock(0);
EDITOR.highlightSetBlock(0);
EDITOR.setIsChanged = true;
}
if (EDITOR.mode == MODE_VIEW && ! EDITOR.isGroupSnapshot)
{
this.hornsDown();
this.title = LOADED.showTitle;
this.authorID = LOADED.authorID;
this.authorName = LOADED.authorName;
this.authorURL = LOADED.authorURL;
$('title').innerHTML = '' + LOADED.showTitle + '';
$('titledrop').innerHTML = '' + LOADED.showTitle + '';
if (! EDITOR.isDemo)
{
if (this.authorID > 0)
{
$('author').innerHTML = 'by <a href="' + this.authorURL + '">' + this.authorName + "</a>";
}
else
{
$('author').innerHTML = 'by ' + this.authorName;
}
$('authordrop').innerHTML = 'by ' + this.authorName;
if (EDITOR.isJudge)
{
$('author').style.visibility = 'hidden';
$('authordrop').style.visibility = 'hidden';
}
}
$('editoroverlay').style.visibility = "visible";
}
$('showloading').style.display = 'none';
fix_png();
};
this.loadDefault = function (startingSize)
{
this.showConfig[SHOW_UNIFORM] = 0;
this.showConfig[SHOW_FLAG1] = 0;
this.showConfig[SHOW_GUARD_UNIFORM] = 0;
this.isSetup = true;
this.setConfig[0] = [];
if ($('bandsetup'))
{
$('bandsetup').style.display = "none";
hide('help');
}
this.resetPace();
if (! IS_DEMO) //  && startingSize >= GROUP_SIZE_NORMAL
{
show('groupselect');
}
this.marchers = [];
if (EDITOR.groupType == GROUP_TYPE_CORPS)
{
this.loadFullCorps(startingSize);
}
else if (EDITOR.groupType == GROUP_TYPE_BRASS)
{
this.loadBrass(startingSize);
}
else if (EDITOR.groupType == GROUP_TYPE_GUARD)
{
this.loadGuard(startingSize);
}
else if (EDITOR.groupType == GROUP_TYPE_DRUMLINE)
{
this.loadDrumline(startingSize);
}
fix_png();
newHelp("Drag marchers to their first spot, then click \"New Set\"");
this.saveSet();
EDITOR.clearHistory();
EDITOR.spawnSetPins();
};
this.loadFullCorps = function (startingSize)
{
var aid = 0;
if (EDITOR.trialGroup > 0)
{
startingSize = GROUP_SIZE_FAN;
}
if (IS_DEMO)
{
for (cx=0; cx < 14; cx++)
{
for (cy=0; cy < 4; cy++)
{
if (cx != 5 && cx != 6 && cx != 7 && cx != 8)
{
this.addMarcher(aid, [SECTION_BRASS, 0], [snapX(180 + cx * 36), snapY(130 + cy * 44), FRAME_BRASS_PLAY]);
aid ++;
}
}
}
$('showloading').style.display = 'none';
MAX_SETS = MAX_SETS_DEMO;
MIN_SETS = MIN_SETS_DEMO;
}
else if (USE_DEFAULT_SHOW_DATA)
{
this.loadSaved(GROUP_SHOW_DATA[GROUP_TYPE_CORPS][startingSize]);
}
else if (false)
{
for (cx=0; cx < 8; cx++)
{
for (cy=0; cy < 8; cy++)
{
this.addMarcher(aid, [SECTION_BRASS, 0], [snapX(72 + cx * 18), snapY(100 + cy * 18), FRAME_BRASS_PLAY]);
aid ++;
}
}
}
else
{
this.loadRaw();
}
};
this.loadRaw = function ()
{
var aid = 0;
for (cx=0; cx < 8; cx++)
{
for (cy=0; cy < 8; cy++)
{
this.addMarcher(aid, [SECTION_BRASS, 0], [snapX(72 + cx * 18), snapY(100 + cy * 18), FRAME_BRASS_PLAY]);
aid ++;
}
}
for (cx=0; cx < 9; cx++)
{
this.addMarcher(aid, [SECTION_SNARE, 0], [snapX((6 * 72) + cx * 18 - 16), snapY(100), FRAME_SNARE_SET]);
aid ++;
}
for (cx=0; cx < 5; cx++)
{
this.addMarcher(aid, [SECTION_TENOR, 0], [snapX((7 * 72) + cx * 18 - 16), snapY(172), FRAME_TENOR_SET]);
aid ++;
}
for (cx=0; cx < 5; cx++)
{
this.addMarcher(aid, [SECTION_BASS, 0], [snapX((7 * 72) + cx * 18 - 16), snapY(230), FRAME_BASS_LEFT]);
aid ++;
}
for (cx=0; cx < 25; cx++)
{
this.addMarcher(aid, [SECTION_GUARD, 0], [snapX((2 * 72) + cx * 18 - 16), snapY(300), FRAME_GUARD_SET]);
aid ++;
}
};
this.loadBrass = function (startingSize)
{
var aid = 0;
if (USE_DEFAULT_SHOW_DATA)
{
this.loadSaved(GROUP_SHOW_DATA[GROUP_TYPE_BRASS][GROUP_SIZE_NORMAL]);
}
else
{
for (cx=0; cx < 8; cx++)
{
for (cy=0; cy < 8; cy++)
{
this.addMarcher(aid, [SECTION_BRASS, 0], [snapX(72 + cx * 18), snapY(100 + cy * 18), FRAME_BRASS_PLAY]);
aid ++;
}
}
}
};
this.loadGuard = function (startingSize)
{
var aid = 0;
if (USE_DEFAULT_SHOW_DATA)
{
this.loadSaved(GROUP_SHOW_DATA[GROUP_TYPE_GUARD][startingSize]);
}
else
{
for (cx=0; cx < 6; cx++)
{
for (cy=0; cy < 5; cy++)
{
this.addMarcher(aid, [SECTION_GUARD, 0], [snapX((3 * 72) + cx * 36 - 16), snapY(100 + cy * 36), FRAME_GUARD_SET]);
aid ++;
}
}
}
};
this.loadDrumline = function (startingSize)
{
var aid = 0;
if (USE_DEFAULT_SHOW_DATA)
{
this.loadSaved(GROUP_SHOW_DATA[GROUP_TYPE_DRUMLINE][startingSize]);
}
else
{
for (cx=0; cx < 9; cx++)
{
this.addMarcher(aid, [SECTION_SNARE, 0], [snapX((7 * 72) + cx * 18 - 16), snapY(100), FRAME_SNARE_SET]);
aid ++;
}
for (cx=0; cx < 5; cx++)
{
this.addMarcher(aid, [SECTION_TENOR, 0], [snapX((7 * 72) + cx * 18 - 16), snapY(172), FRAME_TENOR_SET]);
aid ++;
}
for (cx=0; cx < 5; cx++)
{
this.addMarcher(aid, [SECTION_BASS, 0], [snapX((7 * 72) + cx * 18 - 16), snapY(230), FRAME_BASS_LEFT]);
aid ++;
}
for (cx=0; cx < 5; cx++)
{
this.addMarcher(aid, [SECTION_PLATES, 0], [snapX((7 * 72) + cx * 18 - 16), snapY(160), FRAME_PLATES_SET]);
aid ++;
}
}
};
this.spawnMarchers = function ()
{
var aid = 0;
for (m=0; m < this.loadedSets[0].length; m++)
{
if (this.loadedSets[0][m])
{
var marcher = this.addMarcher(aid, this.marcherConfig[aid]) // this.loadedSets[0][m]
aid ++;
}
}
};
this.togglePace = function ()
{
this.setConfig[this.FFPJVV][SET_CONFIG_PACE] = (this.setConfig[this.FFPJVV][SET_CONFIG_PACE] + 1) % NUM_STEPS_PACE;
this.redrawSetConfig();
};
this.togglePause = function ()
{
this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] = (this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] + 1) % NUM_STEPS_PAUSE;
this.redrawSetConfig();
EDITOR.redrawSetBlock(this.FFPJVV);
};
this.resetPace = function ()
{
this.setConfig[this.FFPJVV] = [];
this.setConfig[this.FFPJVV][SET_CONFIG_PACE] = 0;
this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] = 0;
this.redrawSetConfig();
};
this.redrawSetConfig = function ()
{
if (EDITOR.mode == MODE_EDIT)
{
if (this.setConfig[this.FFPJVV])
{
var bar = this.setConfig[this.FFPJVV][SET_CONFIG_PACE] * (100 / (NUM_STEPS_PACE - 1));
$('pacebar').style.width = bar + "%";
bar = this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] * (100 / (NUM_STEPS_PAUSE - 1));
$('pausebar').style.width = bar + "%";
}
}
};
this.jumpToSet = function (num)
{
if (num > this.maxSet)
{
return false;
}
this.FFPJVV = num;
var delayHornsDown = false;
if (EDITOR.isPlaying && this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] > 0)
{
delayHornsDown = true;
}
for (i=0; i < this.marchers.length; i++)
{
this.marchers[i].jumpToSet(num, delayHornsDown);
}
this.setLongestPath();
if (EDITOR.mode == MODE_EDIT)
{
EDITOR.highlightSetBlock(num);
EDITOR.show.redrawSetConfig();
updateAddSetLink();
if (this.FFPJVV == 0 && EDITOR.isRestored)
{
hide('help');
}
}
else if (EDITOR.mode == MODE_VIEW && EDITOR.isAnalyze)
{
EDITOR.hideOverlay();
EDITOR.updateStatus('Set ' + (this.FFPJVV + 1));
}
};
this.forceJumpToSet = function (num, refresh)
{
if (EDITOR.show.FFPJVV == num && ! refresh)
return false;
if (EDITOR.mode == MODE_EDIT)
{
if (! EDITOR.isPlaying)
{
EDITOR.show.saveSet();
}
}
this.jumpToSet(num);
EDITOR.updateSetPins();
if (EDITOR.isPlaying)
{
this.stop();
return false;
}
if (EDITOR.mode == MODE_EDIT)
{
if (! EDITOR.FFEQJR[EDITOR.show.FFPJVV])
{
EDITOR.FFEQJR[ EDITOR.show.FFPJVV ] = [];
EDITOR.FFJBQV[ EDITOR.show.FFPJVV ] = [];
}
}
};
this.play = function ()
{
if (this.hasDescription)
{
show('showdesc');
setAlpha('showdesc', 95);
this.hasDescription = false;
return false;
}
else
{
EDITOR.hideOverlay();
if (this.maxSet == 0)
return false;
if (EDITOR.isPlaying)
return false;
show('stoplink');
hide('playlink');
this.jumpToSet(0);
this.hornsDown();
var delayMS = 750;
if (EDITOR.isRecordMode)  delayMS = 0;
setTimeout("EDITOR.show.hornsUp()", delayMS);
setTimeout("EDITOR.show.playSet()", delayMS + 750);
setAlpha('editorbuttons', 25);
EDITOR.isPlaying = true;
}
this.frameCount = 0;
this.showStartTime = new Date().getTime();
};
this.stop = function ()
{
if (! EDITOR.isPlaying)
return false;
EDITOR.isPlaying = false;
EDITOR.isSlowPlay = false;
EDITOR.isFastPlay = false;
EDITOR.lockAutoSave = true;
setTimeout("EDITOR.lockAutoSave = false", 3000);
this.jumpToSet(this.FFPJVV, true);
clearInterval(this.intervalID);
this.intervalID = 0;
setAlpha('editorbuttons', 100);
if (EDITOR.mode == MODE_VIEW)
{
setTimeout("EDITOR.showOverlay()", 1250);
setTimeout("EDITOR.show.hornsDown()", 750);
if (EDITOR.isJudge && ! EDITOR.hasVoted)
{
setTimeout("show('votepanel')", 1800);
setTimeout("hide('abortlink')", 1800);
}
}
if (this.maxSet == 1 && EDITOR.helpLevel < 2)
{
EDITOR.helpLevel = 2;
if (! IS_DEMO)
newHelp("When you're done adding sets, click \"Publish Show\" (Menu)");
}
hide('stoplink');
show('playlink');
reset_anims(true);
EDITOR.updateSetPins();
};
this.guardLastSetIsOK = function ()
{
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
if (marcher.section == SECTION_GUARD && ! marcher.isDeleted)
{
if (marcher.getStateForLastSet() > NUM_FLAG_POSES - 1)
{
return false;
}
}
}
return true;
};
this.drumlineLastSetIsOK = function ()
{
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
if ((marcher.section == SECTION_SNARE || marcher.section == SECTION_TENOR) && ! marcher.isDeleted)
{
if (marcher.getStateForLastSet() == 4)
{
return false;
}
}
}
return true;
};
this.stopAndVote = function ()
{
if (EDITOR.isPlaying)
{
this.stop();
}
else
{
show('votepanel');
}
hide('abortlink');
};
this.abortShow = function ()
{
if (EDITOR.isPlaying)
{
this.stop();
}
};
this.launchPreview = function (previewURL)
{
EDITOR.postSaveAction = "preview";
EDITOR.previewURL = previewURL;
this.ajaxSave(false, true);
};
this.manualSave = function (previewURL)
{
EDITOR.postSaveAction = "confirmsave";
this.ajaxSave();
};
this.freezeShow = function (freezerURL)
{
EDITOR.showTitle = prompt("Work-in-Progress Title", EDITOR.showTitle);
if (! EDITOR.showTitle)
{
return false;
}
EDITOR.postSaveAction = "freezer";
EDITOR.freezerURL = freezerURL;
EDITOR.freezerURL += "&showTitle=" + escape(EDITOR.showTitle);
this.ajaxSave(false, true);
};
this.pressPlay = function ()
{
if (EDITOR.isPlaying)
return false;
if (this.maxSet == 0)
{
alert('You need more than one set.');
return false;
}
this.saveSet();
EDITOR.isPlaying = true;
show('stoplink');
hide('playlink');
hide('help');
this.saveSet();
this.hornsUp();
if (this.FFPJVV == this.maxSet)
{
if (this.FFPJVV > 0)
{
-- this.FFPJVV;
this.jumpToSet(this.FFPJVV);
}
setTimeout('EDITOR.show.startPlaySet()', 500);
}
else
{
setTimeout('EDITOR.show.playSet()', 500);
}
};
this.playSet = function ()
{
if (this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] > 0)
{
var now = new Date().getTime();
var delayMS = this.setConfig[this.FFPJVV][SET_CONFIG_PAUSE] * 200;
var endHalt = now + delayMS;
setTimeout('EDITOR.show.startPlaySet()', delayMS);
this.playHalt(endHalt);
}
else
{
this.startPlaySet();
}
};
this.playHalt = function (endHalt)
{
var ms = 1000 / FRAMES_PER_SEC;
var now = new Date().getTime();
if (now < endHalt - ms)
{
this.animateMarchers(now);
setTimeout('EDITOR.show.playHalt(' + endHalt + ')', ms);
}
else
{
EDITOR.show.startPlaySet()
}
};
this.startPlaySet = function ()
{
if (! EDITOR.isPlaying)
return false;
if (this.intervalID)
{
return false;
}
var ms = 1000 / FRAMES_PER_SEC;
this.startTime = new Date().getTime();
this.lastTweenTime = this.startTime;
this.intervalID = setInterval('EDITOR.show.advanceFrame()', ms);
this.setLongestPath();
this.setDelayedAnims();
reset_anims(false);
};
this.setDelayedAnims = function ()
{
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
marcher.nextAnimMS = 0;
marcher.nextAnimState = 0;
marcher.nextAnimFired = false;
}
var ripples = this.ripples[this.FFPJVV];
var longestRipple = 0;
if (ripples)
{
for (var r=0, ripple; ripple = ripples[r]; r++)
{
if (ripple.length > longestRipple)
{
longestRipple = ripple.length;
}
}
for (var r=0, ripple; ripple = ripples[r]; r++)
{
var numMarchers = ripple.length;
var rippleTime = 0;
for (var m=0; m < numMarchers; m++)
{
var marcher = EDITOR.marcherById[ripple[m]];
var stepTime = 120;
if (marcher.section == SECTION_GUARD)
{
if (marcher.equipment.currentAnim.doToss) stepTime = 300;
}
else if (numMarchers >= 20)
{
stepTime = 90;
}
rippleTime += stepTime;
}
if (rippleTime > longestRipple) longestRipple = rippleTime;
}
if (longestRipple > this.timeInterval)
{
this.timeInterval = longestRipple;
}
for (var r=0, ripple; ripple = ripples[r]; r++)
{
var numMarchers = ripple.length;
var interval = (this.timeInterval / numMarchers) >> 0;
for (var m=0; m < numMarchers; m++)
{
var marcher = EDITOR.marcherById[ripple[m]];
var nextSet = marcher.sets[this.FFPJVV + 1];
if (marcher.section == SECTION_GUARD)
{
if (marcher.flagNum != nextSet[3]) continue;
if (nextSet[2] > NUM_FLAG_POSES - 1) continue;
}
else
{
if (nextSet[2] == 3 && marcher.x != nextSet[0] && marcher.y != nextSet[1]) continue;
}
var animMS = (m+1) * interval;
if (! marcher.nextAnimMS || animMS < marcher.nextAnimMS)
{
marcher.nextAnimState = nextSet[2] || 0;
marcher.nextAnimMS = (m+1) * interval;
}
}
}
}
};
this.animateMarchers = function (now, elapsedMS, setDuration)
{
var animChecked = {};
var doAnimate = {};
var animExists = {};
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
if (marcher.section == SECTION_GUARD)
{
var FFAISF = marcher.equipment.equipmentType + ":" + marcher.equipment.animNum;
animExists[FFAISF] = true;
}
}
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
if (marcher.nextAnimMS > 0 && ! marcher.nextAnimFired)
{
if (elapsedMS > marcher.nextAnimMS)
{
if (marcher.section == SECTION_GUARD)
{
var FFXOOH = marcher.equipment.currentAnim;
if (! FFXOOH.doToss)
{
marcher.setState( marcher.nextAnimState );
}
}
else
{
marcher.setState( marcher.nextAnimState );
}
marcher.nextAnimFired = true;
}
}
if (marcher.section == SECTION_PROP || marcher.section == SECTION_METRONOME)
{
continue;
}
else if (marcher.section == SECTION_GUARD)
{
var FFXOOH = marcher.equipment.currentAnim;
var FFAISF = marcher.equipment.equipmentType + ":" + marcher.equipment.animNum;
if (marcher.nextAnimMS && marcher.nextAnimFired) FFAISF += ":" + marcher.id;
if (FFXOOH.frames.length < 2 && ! FFXOOH.doToss) continue;
if (! FFMAJI[FFAISF]) FFMAJI[FFAISF] = { lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 };
if (FFXOOH.doToss)
{
var tossMS = 1400 - FFXOOH.tossDelayMS;
var timeLeft = setDuration - elapsedMS;
if (marcher.nextAnimMS)
{
var calcAnimMS = marcher.nextAnimMS - FFXOOH.tossDelayMS;
var pos = calcAnimMS / setDuration;
var newPos = pos * (setDuration-1400);
tossMS = setDuration - newPos;
}
if (! marcher.equipment.isInAir && setDuration > tossMS)
{
if (timeLeft > tossMS-400 && timeLeft < tossMS)
{
marcher.tossEquipment();
FFXOOH = marcher.equipment.currentAnim;
FFAISF = marcher.equipment.equipmentType + ":" + marcher.equipment.animNum;
if (marcher.nextAnimMS && marcher.nextAnimFired) FFAISF += ":" + marcher.id;
marcher.nextAnimFired = true;
if (! FFMAJI[FFAISF]) FFMAJI[FFAISF] = { lastAnimTime : 0, frameNum : 0, FFPJVV : 0, loopNum : 0 };
}
else if (timeLeft > tossMS && timeLeft < tossMS+300  && marcher.preTossFrame == 1)
{
marcher.pretoss(2);
}
else if (timeLeft > tossMS+300 && timeLeft < tossMS+600  && ! marcher.preTossFrame && ! FFXOOH.smoothToss)
{
marcher.pretoss(1);
}
}
}
if (! animChecked[FFAISF])
{
if (FFXOOH.animSpeedMS > 0 && EDITOR.show.FFPJVV != FFMAJI[FFAISF].FFPJVV)
{
if (FFXOOH.fnf || EDITOR.show.FFPJVV - FFMAJI[FFAISF].FFPJVV > 1)
{
FFMAJI[FFAISF].frameNum = 0;
if (! FFXOOH.fnf)
{
var matchFrame = marcher.equipment.currentFrame;
for (var i = 0; i < FFXOOH.frames.length; i ++)
{
if (matchFrame == FFXOOH.frames[i])
{
FFMAJI[FFAISF].frameNum = i + 1;
}
}
}
else
{
FFMAJI[FFAISF].lastAnimTime = 0;
}
FFMAJI[FFAISF].FFPJVV = EDITOR.show.FFPJVV;
FFMAJI[FFAISF].loopSpeedMS = FFXOOH.animSpeedMS;
FFMAJI[FFAISF].loopNum = 0;
}
}
if (! FFXOOH.loopSpeedMS) {  FFXOOH.loopSpeedMS = FFXOOH.animSpeedMS; }
if (FFXOOH.animSpeedMS > 0 && now - FFMAJI[FFAISF].lastAnimTime > FFXOOH.loopSpeedMS)
{
FFMAJI[FFAISF].frameNum = FFMAJI[FFAISF].frameNum + 1;
if (FFMAJI[FFAISF].frameNum > FFXOOH.frames.length - 1)
{
if (FFXOOH.fnf)
{
FFMAJI[FFAISF].frameNum = FFXOOH.frames.length - 1;
}
else
{
FFMAJI[FFAISF].frameNum = FFMAJI[FFAISF].frameNum % FFXOOH.frames.length;
}
}
if (FFMAJI[FFAISF].frameNum == 0 || (FFXOOH.subloopFrame && FFMAJI[FFAISF].frameNum % FFXOOH.subloopFrame == 0))
{
FFMAJI[FFAISF].loopNum += 1;
var variation = 0;
if (! FFXOOH.doToss && ! FFXOOH.tossSpeed)
{
var variations = [0,2,-1];
variation = variations[(EDITOR.show.FFPJVV + FFMAJI[FFAISF].loopNum) % variations.length];
variation = (variation * (FFXOOH.animSpeedMS * 0.12)) >> 0;
}
FFXOOH.loopSpeedMS = FFXOOH.animSpeedMS + variation;
}
FFMAJI[FFAISF].lastAnimTime = now;
doAnimate[FFAISF] = true;
}
animChecked[FFAISF] = true;
}
if (FFXOOH.syncOffset)
{
var otherAnimNum = marcher.equipment.animNum + FFXOOH.syncOffset;
var oanid = marcher.equipment.equipmentType + ":" + otherAnimNum;
var otherAnim = ANIM[marcher.equipment.equipmentType][otherAnimNum];
if (animExists[oanid] && animChecked[oanid])
{
FFMAJI[FFAISF].frameNum = FFMAJI[oanid].frameNum;
doAnimate[FFAISF] = doAnimate[oanid];
}
}
if (doAnimate[FFAISF] && ! marcher.preTossFrame)
{
if (marcher.equipment.equipmentType == EQUIPMENT_FLAG && ! marcher.isTossing)
{
marcher.gotoFrame(FFDKIM[marcher.equipment.equipmentType][ FFXOOH.frames[FFMAJI[FFAISF].frameNum] ]);
}
marcher.equipment.gotoFrame(FFMAJI[FFAISF].frameNum);
}
}
else if (marcher.section == SECTION_SNARE || marcher.section == SECTION_TENOR)
{
var manim = FFOHUL[marcher.state];
if (manim)
{
var aid = "drum" + marcher.state;
if (! animChecked[aid])
{
if (now - manim.lastAnimTime > manim.animSpeedMS)
{
if (now - manim.lastAnimTime > 500)
{
manim.currentFrame = 0;
}
else
{
manim.currentFrame = (manim.currentFrame + 1) % manim.numFrames;
}
manim.lastAnimTime = now;
doAnimate[aid] = true;
}
animChecked[aid] = true;
}
if (doAnimate[aid])
{
marcher.playFrame = manim.currentFrame;
marcher.gotoFrame(manim.currentFrame, true);
}
}
}
else
{
marcher.animate(now, elapsedMS, setDuration);
}
}
};
this.advanceFrame = function ()
{
var now = new Date().getTime();
if (now - this.lastTweenTime < 10)
{
return false;
}
if (now - this.lastTweenTime > MAX_TWEEN_GAP_MS)
{
this.startTime += ((now - this.lastTweenTime) - MAX_TWEEN_GAP_MS);
}
this.frameCount ++;
this.lastTweenTime = now;
var elapsedMS = (now - this.startTime);
var progress = elapsedMS / this.timeInterval;
this.animateMarchers(now, elapsedMS, this.timeInterval);
if (progress < 1.0)
{
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
marcher.tween(this.FFPJVV, progress);
}
}
else
{
if (this.FFPJVV < this.maxSet)
{
this.FFPJVV ++;
this.jumpToSet(this.FFPJVV);
}
clearInterval(this.intervalID);
this.intervalID = 0;
if (this.FFPJVV < this.maxSet)
{
this.playSet();
}
else
{
this.stop();
}
}
};
this.publish = function ()
{
if (EDITOR.isPublished)
{
alert("This show has already been published.");
return false;
}
else if ($('showTitle').value.match(/(bored|first show|1st show|my 1st|my first|untitled|idk)/i))
{
alert("Please try to think of a more imaginative title. =\)");
return false;
}
else if ($('showDescription').value.length < 24 && $('showDescription').value.match(/(comment)/i))
{
alert("Please don't ask for comments in your show description.");
return false;
}
else if ($('showDescription').value.match(/youtube\.com/i))
{
if (! confirm("IMPORTANT\n\nIf you used a timekeeper marcher to sync the show, it MUST be deleted before publishing.\n\nPublish the show now?"))
{
return false;
}
}
else if ($('showTitle').value.match(/\brandom/i))
{
alert("Please try to think of something without 'random' in it. =\)");
return false;
}
else if ($('showTitle').value.match(/premium|subscri/i))
{
alert("Please don't base your title on the topic of subcriptions.  Thanks!");
return false;
}
else if ($('exhibition') && $('exhibition').checked)
{
if (! confirm("Note:  As an exhibition show,\nyou will NOT be able to re-publish it for judging.\n\nIf you want others to preview this show,\nuse \"Menu > Preview Show\", instead.\n\nPublish this show as exhibition?"))
{
return false;
}
}
clearInterval(EDITOR.saveIntervalID);
hideSavebox();
if (EDITOR.isPostEdit || IS_DEMO)
{
this.saveSet();
this.saveToForm();
this.finishPublish();
}
else
{
EDITOR.doPublishAfterSave = true;
this.ajaxSave();
}
};
this.publishSnapshot = function ()
{
this.saveSet();
this.saveToForm();
this.finishPublish();
};
this.finishPublish = function ()
{
if (EDITOR.isPostEdit)
{
$('saving').innerHTML = "Re-Publishing Updated Show...";
this.saveSet();
this.saveToForm('republish');
}
else if ($('exhibition') && $('exhibition').checked)
{
$('saving').innerHTML = "Publishing Show for Exhibition...";
}
else if (EDITOR.isGroupSnapshot)
{
$('saving').innerHTML = "Saving Snapshot...";
}
else if (IS_DEMO)
{
$('saving').innerHTML = "Publishing Show...";
}
else
{
$('saving').innerHTML = "Sending Show to Judging Queue...";
}
this.showIsChanged = false;
show('saving');
$('saveForm').submit();
EDITOR.isPublished = true;
};
this.toggleAutoSave = function ()
{
EDITOR.doAutoSave = EDITOR.doAutoSave ? false : true;
SAVE_HEARTBEATS = EDITOR.doAutoSave ? SAVE_HEARTBEATS_NORMAL : SAVE_HEARTBEATS_SLOW;
action_message("Auto Save: Every " + Math.floor(SAVE_HEARTBEATS * SAVE_HEARTBEAT_MINS) + " Mins");
EDITOR.numSaveHeartbeats = 0;
};
this.ajaxSave = function (heartbeat, fromPreview)
{
if (EDITOR.isSaving) return false;
if (EDITOR.isPublished) return false;
if (IS_DEMO) return false;
if (EDITOR.isPlaying) return false;
if (! this.isSetup) return false;
if (EDITOR.isPostEdit) return false;
if (heartbeat)
{
if (! EDITOR.showIsChanged)
return false;
++ EDITOR.numSaveHeartbeats;
if (EDITOR.numSaveHeartbeats < SAVE_HEARTBEATS)
return false;
if (EDITOR.lockAutoSave)
{
return false;
}
}
else if (! heartbeat && ! fromPreview)
{
var now = new Date().getTime();
if (EDITOR.lastSaveTime > 0 && now - EDITOR.lastSaveTime < 10000)
{
alert("Please wait at least 10 seconds between saves.");
EDITOR.postSaveAction = "";
return true;
}
}
else if ((fromPreview || EDITOR.doPublishAfterSave) && EDITOR.saveBlockedByStudio)
{
alert("Please click 'Update Designs' first, to upgrade\nyour show graphics to the latest version.");
EDITOR.postSaveAction = "";
return true;
}
EDITOR.isSaving = true;
show('saving');
var time0 = get_now();
this.saveSet();
this.saveToForm();
AJAX_TIMEOUT_ID = setTimeout('ajax_problem()', AJAX_TIMEOUT_SECS * 1000);
if (true)
{
try
{
var remoteDoc = get_rpc_doc();
var html = "<form id=\"remoteForm\" method=\"post\" action=\"/remote/save_show.php?ts=" +get_now() + "\">";
html += "<textarea name=\"showData\">";
html += $('showData').innerHTML;
html += "</textarea>";
html += "<input type=\"hidden\" name=\"wipID\" value=\"" + EDITOR.wipID + "\">";
html += "</form>";
remoteDoc.write(html);
remoteDoc.getElementById('remoteForm').submit();
}
catch (e)
{
spawn_rpc();
}
}
else
{
var ajax = get_ajax();
var params = "wipID=" + EDITOR.wipID;
params += "&showData=" + $('showData').innerHTML;
ajax.open("POST", "/remote/save_show.php", true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.setRequestHeader("Content-length", params.length);
ajax.setRequestHeader("Connection", "close");
var ajaxTime = 0;
ajax.onreadystatechange = function ()
{
if (ajax.readyState == 4 && ajax.status == 200)
{
save_response('saved');
var response = ajax.responseText;
}
}
ajax.send(params);
ajaxTime = get_now();
}
EDITOR.lastSaveTime = new Date().getTime();
};
this.saveToForm = function (rm)
{
var dump = this.createShowData();
if (rm) {  $('rm').value = rm; }
$('numSets').value = this.maxSet + 1;
$('showData').innerHTML = dump;
};
this.createShowData = function ()
{
var dump = "[begin]" + LINE_DELIM;
dump += "show=" + this.showConfig.join("|") + LINE_DELIM;
var numMarchers = this.marchers.length;
dump += "marcher=";
for (m=0; m < numMarchers; m++)
{
dump += this.marchers[m].section + "" + this.marchers[m].hornType;
if (m < numMarchers - 1)  { dump += "|" }
}
dump += LINE_DELIM;
dump += "deleted=";
var deleted = [];
for (m=0; m < numMarchers; m++)
{
if (this.marchers[m].isDeleted)
{
deleted.push(this.marchers[m].id);
}
}
dump += deleted.join("|");
dump += LINE_DELIM;
for (s=0; s <= this.maxSet; s++)
{
var line = "set=";
var sc = this.setConfig[s].join("");
line += sc + "|";
for (var m=0, marcher; marcher = this.marchers[m]; m++)
{
var set = marcher.sets[s];
var lastByte = "";
if (EDITOR.isPremium && marcher.section == SECTION_GUARD)
{
lastByte = set[3];
}
line += dec_to_base62(set[0]) + "" + dec_to_base62(set[1]) + "" + char_dec_to_base62(set[2]) + "" + lastByte;
if (m < numMarchers - 1)   line += "|";
}
var extElements = [];
var ripples = this.ripples[s] || [];
for (var r=0, ripple; ripple = ripples[r]; r++)
{
var ripEl = "r,0," + ripple.join(',');
extElements.push(ripEl);
}
if (extElements.length)
{
line += "!!" + extElements.join('|');
}
line += LINE_DELIM;
dump += line;
}
dump += "[end]";
return dump;
};
this.changeUniforms = function ()
{
var numUniforms = NUM_UNIFORMS;
if (EDITOR.trialGroup > 0) {  -- numUniforms; }
if (EDITOR.trialGroup >= 3) {  numUniforms -= 2; }
this.showConfig[SHOW_UNIFORM] = ((this.showConfig[SHOW_UNIFORM] >> 0) + 1) % numUniforms;
if (! EDITOR.isPremium)
{
this.showConfig[SHOW_GUARD_UNIFORM] = this.showConfig[SHOW_UNIFORM];
}
for (m=0; m < this.marchers.length; m++)
{
if (EDITOR.isPremium && this.marchers[m].section == SECTION_GUARD)
{
}
else
{
this.marchers[m].changeUniform(this.showConfig[SHOW_UNIFORM]);
}
}
};
this.changeGuardUniforms = function ()
{
this.showConfig[SHOW_GUARD_UNIFORM] = ((this.showConfig[SHOW_GUARD_UNIFORM] >>0) + 1) % NUM_GUARD_UNIFORMS;
for (var m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_GUARD)
{
this.marchers[m].changeGuardUniform(this.showConfig[SHOW_GUARD_UNIFORM]);
}
}
};
this.changeGuardUniformsMulti = function ()
{
var first = EDITOR.FFFMJP[0];
if (! first || first.section != SECTION_GUARD)
{
alert("Please select the guard members you wish to change.");
return false;
}
var uniformNum = first.uniformNum >> 0;
uniformNum = (uniformNum + 1) % NUM_GUARD_UNIFORMS;
for (var m=0; m < this.marchers[m].length; m++)
{
if (this.marchers[m].section == SECTION_GUARD)
{
this.marchers[m].changeGuardUniform(uniformNum);
}
}
};
this.changeFlags = function ()
{
if (EDITOR.isPremium)
{
var first = EDITOR.FFFMJP[0];
if (! first || first.section != SECTION_GUARD)
{
alert("Please select the guard members you wish to change.");
return false;
}
var flagNum = first.flagNum >> 0;
flagNum = (flagNum + 1) % (EDITOR.numFlags + 2);
for (var m=0; m < EDITOR.FFFMJP.length; m++)
{
if (EDITOR.FFFMJP[m].section == SECTION_GUARD)
{
EDITOR.FFFMJP[m].setFlag(flagNum, true);
}
}
}
else
{
this.showConfig[SHOW_FLAG1] = (this.showConfig[SHOW_FLAG1] + 1) % EDITOR.numFlags;
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_GUARD)
{
this.marchers[m].setFlag(this.showConfig[SHOW_FLAG1], true);
}
}
}
};
this.hornsDown = function ()
{
for (m=0; m < this.marchers.length; m++)
{
this.marchers[m].hornDown();
}
};
this.hornsUp = function ()
{
for (m=0; m < this.marchers.length; m++)
{
this.marchers[m].hornUp();
}
};
this.hornsUpBrass = function ()
{
for (m=0; m < this.marchers.length; m++)
{
if (this.marchers[m].section == SECTION_BRASS)
{
this.marchers[m].hornUp();
}
}
};
}
function oMarcher (aid, marcherConfig, bassNum)
{
this.id = aid;
this.x = 0;
this.y = 0;
this.prevZ = 0;
this.section = marcherConfig[0];
this.hornType = marcherConfig[1];
this.uniformNum = marcherConfig[2];
this.bassNum = bassNum;
this.flagNum = 0;
this.isHighlighted = false;
this.isQHighlighted = false;
this.FFBTPK = false;
this.isDeleted = false;
this.sets = [];
this.flatSets = [];
this.prevSection = this.section;
this.imgSizeX = MARCHER_SIZE_X;
this.imgSizeY = MARCHER_SIZE_Y;
this.frameOffset = 0;
this.preTossFrame = 0;
this.isTossing = false;
var uniform = 0;
if (defined( EDITOR.show.showConfig[SHOW_UNIFORM] ))
uniform = EDITOR.show.showConfig[SHOW_UNIFORM];
this.animRow = 0;
this.frames = [];
this.framesPlaying = [];
this.equipment = false;
this.lastTossSet = 0;
this.lastAnimTime = 0;
this.nextAnimMS = 0;
this.nextAnimFired = false;
this.nextAnimState = [];
this.state = MARCHER_STATE_SET;
this.playFrame = 0;
this.dragOriginX = 0;
this.dragOriginY = 0;
this.FFCIBA = null;
this.dragOffX = 0;
this.dragOffY = 0;
this.FFIFIX = 0;
this.FFPHLH = 0;
this.scaleOffsetIsSet = 0;
this.isOutOfBounds = true;
this.div = document.createElement('div');
this.div.setAttribute('id', aid + "d");
this.div.style.position = "absolute";
this.div.style.left = "0px";
this.div.style.top = "0px";
if (! ie6)
{
this.highlightDiv = document.createElement('div');
this.highlightDiv.className =  'marcherhighlight';
this.div.appendChild(this.highlightDiv);
}
$('editor').appendChild(this.div);
this.init = function (startSet)
{
if (this.section == SECTION_BRASS)
{
this.setHornType(this.hornType);
}
if (this.section == SECTION_GUARD)
{
this.changeGuardUniform(this.uniformNum);
}
if (defined(startSet))
{
this.move(startSet[0], startSet[1]);
this.setFlag(startSet[3]);
this.setState(MARCHER_STATE_PLAYING);
this.saveSet(0);
}
else
{
this.setFrame(this.frames[0]);
}
}
this.toggleSection = function (newSection)
{
this.section = newSection;
this.hornType = 0;
this.setSprite();
this.setFlag(0);
this.setState(MARCHER_STATE_PLAYING);
for (var i = 0; i <= EDITOR.show.maxSet; i ++)
{
this.sets[i][2] = MARCHER_STATE_PLAYING;
this.sets[i][3] = 0;
}
if (this.equipment)
{
this.move(this.x, this.y, true);
}
}
this.setSprite = function ()
{
if (this.img)
{
this.div.removeChild(this.img);
}
if (this.equipment)
{
this.equipment.destroySprite();
this.equipment = null;
}
if (this.section == SECTION_BRASS)
{
this.frames = [FRAME_BRASS_SET, FRAME_BRASS_PLAY, 0, 0, 0];
this.framesPlaying = [FRAME_BRASS_PLAY];
this.frame = FRAME_BRASS_SET;
this.imgSizeX = 18;
this.imgSizeY = 36;
this.animRow = 0;
this.frameOffset = 0;
}
else if (this.section == SECTION_SNARE)
{
this.frames = [FRAME_SNARE_SET, FRAME_SNARE_PLAY1, 0, 0, 0];
this.framesPlaying = [FRAME_SNARE_PLAY1, FRAME_SNARE_PLAY2];
this.frame = FRAME_SNARE_SET;
this.imgSizeX = 18;
this.imgSizeY = 36;
this.animRow = 1;
this.frameOffset = 0;
}
else if (this.section == SECTION_TENOR)
{
this.frames = [FRAME_TENOR_SET, FRAME_TENOR_PLAY1, 0, 0, 0];
this.framesPlaying = [FRAME_TENOR_PLAY1, FRAME_TENOR_PLAY2];
this.frame = FRAME_TENOR_SET;
this.imgSizeX = 18;
this.imgSizeY = 36;
this.animRow = 1;
this.frameOffset = 0;
}
else if (this.section == SECTION_BASS)
{
this.frames = [FRAME_BASS_LEFT, FRAME_BASS_RIGHT, 0, 0, 0];
this.framesPlaying = [FRAME_BASS_RIGHT];
this.frame = FRAME_BASS_LEFT;
this.imgSizeX = 36;
this.imgSizeY = 36;
this.animRow = 2 + (((this.bassNum-1) / 2) >> 0);
this.frameOffset = ((this.bassNum-1) % 2) * 2;
}
else if (this.section == SECTION_PLATES)
{
this.frames = [FRAME_PLATES_SET, FRAME_PLATES_PLAY2, 0, 0, 0];
this.framesPlaying = [FRAME_PLATES_PLAY1, FRAME_PLATES_PLAY2];
this.frame = FRAME_PLATES_SET;
this.animRow = 1;
this.frameOffset = 0;
}
else if (this.section == SECTION_PROP)
{
this.frames = [0];
this.framesPlaying = [0];
this.frame = 0;
this.imgSizeX = 52;
this.imgSizeY = 48;
this.animRow = 0;
this.frameOffset = 0;
EDITOR.hasProps = true;
}
else if (this.section == SECTION_GUARD)
{
this.frames = [1, 1, 0, 0, 3, 0];
this.framesPlaying = [1];
this.frame = 0;
this.imgSizeX = 18;
this.imgSizeY = 36;
this.animRow = 1;
this.frameOffset = 0;
this.equipment = new oEquipment(aid);
this.equipment.move(this.x, this.y, this.y+1);
}
else if (this.section == SECTION_METRONOME)
{
this.frames = [0, 0, 0, 0, 0];
this.framesPlaying = [0];
this.frame = 0;
this.imgSizeX = 18;
this.imgSizeY = 36;
this.animRow = 0;
this.frameOffset = 0;
EDITOR.metronome = this;
if (EDITOR.isPreview)
{
EDITOR.metronome.hide();
}
else if (EDITOR.mode == MODE_VIEW)
{
EDITOR.metronome.dodelete();
}
}
if (this.section == SECTION_GUARD)
{
this.img = new Image();
this.img.src = EDITOR.spriteURL['guard'];
this.imgSizeX = 18;
this.imgSizeY = 36;
if (EDITOR.isPremium)
{
this.uniformNum = 0;
uniform = 0;
}
this.animRow = uniform;
}
else if (this.section == SECTION_PROP)
{
this.img = new Image();
this.img.src = EDITOR.spriteURL['prop'];
}
else if (this.section == SECTION_METRONOME)
{
this.img = new Image();
if (EDITOR.mode == MODE_EDIT)
{
this.img.src = imageUrl("sprites/metronome.png");
this.img.style.left = '-1px';
}
}
else
{
this.img = new Image();
var uniUrl = EDITOR.spriteURL['musician'];
if (! uniUrl)
{
uniUrl = imageUrl("sprites/m" + (uniform + 1) + "_uniform.png");
}
this.img.src = uniUrl;
}
this.img.style.top = (-1 * this.animRow * this.imgSizeY) - 1;
this.img.className = "marcher";
this.img.id = aid + "i";
if (this.img.attachEvent) {  this.img.attachEvent("ondragstart", function () { return false; }); }
this.div.style.width = this.imgSizeX + 0;
this.div.style.height = this.imgSizeY + 2;
this.div.style.clip = "rect(0px, " + (this.imgSizeX) + "px, " + (this.imgSizeY + 2) + "px, 0px)";
this.div.appendChild(this.img);
if (! ie6)
{
this.highlightDiv.style.width = this.imgSizeX;
this.highlightDiv.style.height = this.imgSizeY;
}
this.setState(MARCHER_STATE_PLAYING);
};
this.undelete = function ()
{
this.isDeleted = false;
this.unhide();
};
this.dodelete = function ()
{
this.isDeleted = true;
this.hide();
};
this.spawnSetPin = function ()
{
var pin = document.createElement('div');
pin.setAttribute('id', this.id + "pin");
pin.className = "setpin";
pin.height = px(2);
pin.width = px(2);
$('editor').appendChild(pin);
if (this.isDeleted)
{
this.hidePin();
}
};
this.showPin = function ()
{
if (! this.isDeleted)
{
var pinid = this.id + "pin";
show(pinid);
}
};
this.hidePin = function ()
{
var pinid = this.id + "pin";
hide(pinid);
}
this.setState = function (newState)
{
var prevState = this.state;
this.state = newState;
if (this.section == SECTION_GUARD)
{
if (this.equipment)
{
this.equipment.setAnim(newState);
}
var pose = 1;
if (this.equipment.currentAnim.pose != undefined)
{
pose = this.equipment.currentAnim.pose;
if (EDITOR.show.editorVersion <= 1.40 && pose > 3)
{
pose = 0;
}
}
this.setFrame(pose);
}
else
{
if (prevState == newState && EDITOR.isPlaying)
{
}
else
{
this.setFrame(this.frames[this.state]);
}
}
};
this.setGhost = function (isOn)
{
if (isOn)
{
setAlpha(this.div.id, 25);
this.isGhost = true;
this.div.style.zIndex = 5;
this.img.style.cursor = 'default';
}
else
{
setAlpha(this.div.id, 100);
this.isGhost = false;
this.move(this.x, this.y, true);
this.img.style.cursor = 'move';
}
if (this.equipment)
{
this.equipment.setGhost(isOn);
}
};
this.move = function (ax, ay, forceUpdate)
{
if (this.isDeleted && EDITOR.isPlaying) return false;
if (EDITOR.mode == MODE_EDIT)
{
if (ax > 864 + 400  || ax < -400) ax = FIELD_SIZE_X / 2
if (ay > 450 + 350  || ay < -350) ay = FIELD_SIZE_Y / 2
}
var isMoved = false;
if (this.x != ax || forceUpdate)
{
this.x = ax;
var offX = 0;
if (this.section == SECTION_BASS)
{
offX = -9;
}
else if (this.section == SECTION_PROP)
{
offX = -17;
}
this.div.style.left = ax + offX;
isMoved = true;
}
var equipmentZ = 0;
if (this.y != ay || forceUpdate)
{
this.y = ay;
var offY = 0;
if (this.section == SECTION_PROP)
{
offY = -10;
}
this.div.style.top = ay + offY;
var z = 200 + this.y;
if (EDITOR.leader && EDITOR.leader.id == this.id)
z += 6;
checkZ = ((z / 6) >> 0) * 6;
if (this.section == SECTION_GUARD)
{
checkZ -= 2;
}
if (checkZ != this.prevZ || forceUpdate || this.section == SECTION_PROP)
{
this.div.style.zIndex = checkZ;
this.prevZ = checkZ;
equipmentZ = checkZ;
}
isMoved = true;
}
if (this.equipment)
{
this.equipment.move(ax, ay, equipmentZ, forceUpdate);
if (this.equipment.catchMe)
{
this.gotoFrame(FFILEM[this.equipment.equipmentType]);
this.equipment.catchMe = false;
}
}
}
this.addPivot = function (pivotKey)
{
this.pivotKey = pivotKey;
};
this.clearPivot = function ()
{
this.pivotKey = "";
};
this.saveSet = function (setNum)
{
if (this.section == SECTION_PROP)
{
this.propagateSets();
}
this.sets[setNum] = [  this.x >> 0, this.y >> 0, this.state, this.flagNum ];
};
this.propagateSets = function ()
{
for (var i = 0; i <= EDITOR.show.maxSet; i ++)
{
this.sets[i] = [  this.x >> 0, this.y >> 0, this.state, this.flagNum  ];
}
};
this.hide = function ()
{
this.div.style.display = 'none';
this.div.style.visibility = 'hidden';
if (this.equipment)
{
this.equipment.hide();
}
this.hidePin();
};
this.unhide = function ()
{
this.div.style.display = 'block';
this.div.style.visibility = 'visible';
if (this.equipment)
{
this.equipment.unhide();
}
this.showPin();
};
this.addSet = function (setNum)
{
var prevSet = this.sets[setNum-1].slice();
if (this.section == SECTION_GUARD && this.equipment.currentAnim.doToss)
{
prevSet[2] = 0;
}
this.sets[setNum] = prevSet;
this.setFlag(this.sets[setNum][3]);
this.setState(this.sets[setNum][2]);
};
this.insertSet = function (setNum)
{
this.sets.splice(setNum+1,0, [ this.sets[setNum][0], this.sets[setNum][1], this.sets[setNum][2], this.sets[setNum][3] ]);
};
this.resetSet = function (setNum, fromSet)
{
this.sets[setNum] = [ this.sets[fromSet][0], this.sets[fromSet][1], this.sets[fromSet][2], this.sets[setNum][3] ];
this.move(this.sets[setNum][0], this.sets[setNum][1]);
this.setFlag(this.sets[setNum][3]);
this.setState(this.sets[setNum][2]);
};
this.deleteSet = function (setNum)
{
this.sets.splice(setNum, 1);
};
this.getStateForLastSet = function ()
{
return this.sets[ this.sets.length - 1 ][2];
};
this.loadSet = function (set)
{
if (set.length < 3)
set[2] = MARCHER_STATE_PLAYING;
if (set.length < 4)
set[3] = 0;
if ((EDITOR.mode == MODE_VIEW && EDITOR.show.editorVersion <= 1.26) || EDITOR.fieldSizeOffsetFix)
{
set[0] += 72;
set[1] += 20;
}
if (EDITOR.is3D)
{
this.flatSets.push(set.slice());
var yOffset = -15;
var slopeX2 = 284.0;
var shrinkX = -0.011;
var slopeY = 35;
if (EDITOR.groupType == GROUP_TYPE_GUARD || EDITOR.groupType == GROUP_TYPE_DRUMLINE)
{
yOffset = 15;
slopeX2 = 300.0;
shrinkX = +0.03;
slopeY = 15;
}
if (this.isOutOfBounds && EDITOR.show.editorVersion <= 1.26)
{
if (! this.getOutOfBounds(set[0], set[1]))
{
this.isOutOfBounds = false;
}
}
var fieldCenterX = ((FIELD_SIZE_X - 12)/ 2 - this.imgSizeX / 2) + 6.0;
var slopeX = (246.0 / slopeX2);
distortX = 1.0 - ((1.0 - slopeX) * ((FIELD_SIZE_Y-set[1]) / FIELD_SIZE_Y));
distortX += shrinkX;
if (set[0] > fieldCenterX)
{
set[0] = fieldCenterX + (set[0] - fieldCenterX) * distortX;
}
else
{
set[0] = fieldCenterX - (fieldCenterX - set[0]) * distortX;
}
var distortY = (FIELD_SIZE_Y - set[1]) / FIELD_SIZE_Y * slopeY;
set[1] = (0.0 + (420.0 / FIELD_SIZE_Y) * set[1]) + distortY + yOffset;
}
if (EDITOR.isGroupSnapshot && EDITOR.mode != MODE_EDIT)
{
if (set[0] < 144 || set[0] > FIELD_SIZE_X - 144)
{
EDITOR.show.marcherIsDeleted[ this.id ] = true;
}
else
{
set[0] += 144;
}
}
this.sets.push(set);
};
this.getOutOfBounds = function (ax, ay)
{
if (ax > 72 && ax < 720 + 72 && ay > 20 && ay < 440)
{
return false;
}
else
{
return true;
}
};
this.jumpToSet = function (num, delayHornsDown)
{
var toSet = this.sets[num];
if (this.equipment)
{
this.catchEquipment();
}
this.move(toSet[0], toSet[1]);
this.setFlag(toSet[3]);
if (! this.checkKneel(num))
{
return false;
}
this.setState(toSet[2]);
};
this.checkKneel = function (setNum)
{
var toSet = this.sets[setNum];
if (EDITOR.isPlaying && toSet[2] == ANIM_KNEEL && this.section == SECTION_BRASS)
{
var nextSet = this.sets[setNum+1];
if (nextSet)
{
var isMoving = (nextSet[0] != toSet[0] || nextSet[1] != toSet[1]) ? true : false;
if (isMoving)
{
this.setState(0);
return false;
}
}
}
return true;
};
this.comparitiveDistToNextSet = function (startSet)
{
var flatSets = this.sets;
if (EDITOR.is3D && EDITOR.show.editorVersion >= 1.41)
{
flatSets = this.flatSets;
}
if (! defined(flatSets[startSet+1]))
{
return 0;
}
var dx = Math.pow(flatSets[startSet+1][0] - flatSets[startSet][0], 2);
var dy = Math.pow(flatSets[startSet+1][1] - flatSets[startSet][1], 2);
var len = dx + dy;
return len;
};
this.tween = function (startSet, progress)
{
if (this.section == SECTION_PROP) {  return false; }
var from = this.sets[startSet];
var to = this.sets[startSet+1];
var pivotKey = to[4];
pivotKey = '';
var subsets = [];
var tweenX = 0;
var tweenY = 0;
if (false && pivotKey)
{
var pivot = EDITOR.show.pivots[startSet+1][pivotKey];
var pivotPos = pivot[4]['tweenPoint'];
var direction = pivot[4]['direction'];
var midRadius = this.pivotStartRadius + (this.pivotEndRadius - this.pivotStartRadius) * progress;
var midAngle = this.pivotStartAngle + (this.pivotEndAngle - this.pivotStartAngle) * progress;
var tweenX = pivotPos[0] + Math.sin(midAngle * Math.PI / 180) * midRadius;
var tweenY = pivotPos[1] + Math.cos(midAngle * Math.PI / 180) * midRadius * -1.0;
}
else if (false && subsets.length)
{
var numSteps = subsets.length + 1;
var progressPerStep = 100.0 / numSteps;
var stepNum = Math.floor(progress / progressPerStep);
var stepProgress = progress % progressPerStep;
subfrom = subsets[stepNum];
subto = (stepNum == numSteps) ? to : subsets[stepNum + 1];
tweenX = subfrom[0] + (subto[0] - subfrom[0]) * stepProgress;
tweenY = subfrom[1] + (subto[1] - subfrom[1]) * stepProgress;
}
else
{
tweenX = from[0] + (to[0] - from[0]) * progress;
tweenY = from[1] + (to[1] - from[1]) * progress;
}
this.move(tweenX, tweenY);
};
this.setSpecialBorder = function ()
{
this.setBorder("solid 1px #ff0");
};
this.setBorder = function (astyle)
{
if (ie && ! ie6)
{
this.div.style.borderTop = astyle;
this.div.style.borderBottom = astyle;
}
else
{
this.div.style.border = astyle;
}
this.div.style.padding = "1px";
};
this.removeBorder = function ()
{
this.setBorder("solid 1px transparent");
if (ie6)
{
this.setBorder("solid 0px " + BORDER_COLOR);
this.div.style.padding = "1px";
}
};
this.deselect = function ()
{
this.removeBorder();
if (! ie6)
this.highlightDiv.style.backgroundColor = "transparent";
this.isLeader = false;
this.FFBTPK = false;
this.isDark = false;
if (this.isHighlighted)
{
this.unhighlight();
}
};
this.select = function (force, isDark)
{
if (this.isDeleted && ! force) return false;
if (this.section == SECTION_PROP && EDITOR.show.propsHidden)
{
}
if (this.isGhost)
{
return false;
}
if (! this.isHighlighted)
{
this.setBorder("solid 1px " + BORDER_COLOR);
if (! ie6)
{
this.isDark = isDark;
this.highlightDiv.style.backgroundColor = 'green';
}
}
this.FFBTPK = true;
};
this.highlight = function ()
{
if (this.section == SECTION_PROP && EDITOR.show.propsHidden)
{
}
if (this.isGhost || this.isQHighlighted)
{
return false;
}
this.setBorder("solid 1px #D82113");
if (! ie6)
{
this.highlightDiv.style.backgroundColor = "#D82113";
}
this.isHighlighted = true;
};
this.unhighlight = function ()
{
this.removeBorder();
if (! ie6)
this.highlightDiv.style.backgroundColor = "transparent";
this.isHighlighted = false;
if (this.FFBTPK)
{
this.select(false, this.isDark);
}
};
this.FFHDRP = function ()
{
if (this.isGhost || this.FFBTPK)
{
return false;
}
this.setBorder("solid 1px #91B672");
if (! ie6)
{
this.highlightDiv.style.backgroundColor = "#C5DCB3";
}
this.isQHighlighted = true;
};
this.quickUnhighlight = function ()
{
this.removeBorder();
if (! ie6)
{
this.highlightDiv.style.backgroundColor = "transparent";
}
this.isQHighlighted = false;
if (this.FFBTPK)
{
this.select(false, this.isDark);
}
};
this.drag = function (offX, offY)
{
var toX = this.dragOriginX + offX;
var toY = this.dragOriginY + offY;
if (EDITOR.hashState == HASH_HORIZONTAL)
{
var hashY = parseInt($('hashX').style.top) - this.imgSizeY + 3;
if (Math.abs(toY - hashY) < 20)
{
toY = hashY;
}
if (EDITOR.snapX > 0)
{
toX = snapX(toX);
}
}
else if (EDITOR.hashState == HASH_VERTICAL)
{
var hashX = parseInt($('hashY').style.left) - ((this.imgSizeX / 2) >> 0) + 1;
hashX += (this.section == SECTION_BASS) ? +9 : 0;
if (Math.abs(toX - hashX) < 20)
{
toX = hashX;
}
if (EDITOR.snapY > 0)
{
toY = snapY(toY);
}
}
else if (EDITOR.snapX > 0)
{
toX = snapX(toX);
toY = snapY(toY);
}
this.move(toX, toY);
};
this.setDragOrigin = function ()
{
this.dragOriginX = this.x;
this.dragOriginY = this.y;
};
this.FFDCCO = function (point)
{
var dx = Math.pow(point[0] - this.x, 2);
var dy = Math.pow(point[1] - this.y, 2);
var len = Math.sqrt(dx + dy);
return len;
};
this.distanceToMarcher = function (marcher)
{
return this.FFDCCO([marcher.x, marcher.y]);
};
this.angleToMarcher = function (marcher)
{
return FFMBEJ([this.x, this.y], [marcher.x, marcher.y]);
};
this.rotate = function (centerPoint, direction, isFine)
{
var len = this.FFDCCO(centerPoint);
var angle = FFMBEJ([this.x, this.y], centerPoint);
var step = 11.25;
if (isFine)
step = step / 8.0;
var newAngle = (angle + direction * step) % 360;
newX = centerPoint[0] + Math.sin(newAngle * Math.PI / 180) * len;
newY = centerPoint[1] + Math.cos(newAngle * Math.PI / 180) * len * -1.0;
this.move(newX, newY);
};
this.FFDQOR = function (centerPoint, offsetAngle)
{
offsetAngle = (offsetAngle + 180) % 360;
this.FFIFIX = FFMBEJ([this.x, this.y], centerPoint);
if (offsetAngle > 270 || offsetAngle < 90)
{
turn = (360 - offsetAngle) + 180;
offsetAngle = (offsetAngle + turn) % 360;
this.FFIFIX = (this.FFIFIX + turn) % 360;
}
};
this.FFQBJV = function (endPoint)
{
this.FFPHLH = this.FFDCCO(endPoint);
};
this.scale = function (centerPoint, directionX, directionY, isFine)
{
var newX = this.x;
var newY = this.y;
var step = 0.05;
if (isFine)
step = 0.01;
if (directionX != 0)
{
var lenX = this.x - centerPoint[0];
var offX = lenX * step * directionX;
newX = centerPoint[0] + lenX + offX;
}
if (directionY != 0)
{
var lenY = this.y - centerPoint[1];
var offY = lenY * step * directionY;
newY = centerPoint[1] + lenY + offY;
}
this.move(newX, newY);
};
this.FFLBTD = function (dhm)
{
this.FFCIBA = dhm;
this.dragOffX = this.x - dhm.x;
this.dragOffY = this.y - dhm.y;
};
this.moveRelativeToHandle = function ()
{
newX = this.FFCIBA.x + this.dragOffX;
newY = this.FFCIBA.y + this.dragOffY;
this.move(newX, newY);
};
this.nudge = function (offX, offY)
{
this.move(this.x + offX, this.y + offY);
};
this.setFrame = function (num)
{
if (! num) {  num = 0; }
this.frame = num;
this.gotoFrame(num);
};
this.togglePlayState = function (num, isReverse)
{
if (! num) {  num = 0; }
if (this.section == SECTION_GUARD)
{
if (EDITOR.isPremium)
{
var diff = 1;
if (isReverse)
{
diff = -1;
}
num += diff;
var numAnims = NUM_ANIMS[this.equipment.equipmentType];
if (num > numAnims - 1)
{
num = 0;
}
else if (num < 0)
{
num = numAnims - 1;
}
}
else
{
num = (num + 1) % NUM_DEFAULT_FLAG_ANIMS;
}
}
else
{
var numAnims = 2;
if (EDITOR.isPremium)
{
numAnims += 3;
if (this.section == SECTION_BASS || this.section == SECTION_PLATES)
{
numAnims -= 1;
}
}
var diff = 1;
if (isReverse)
{
diff = -1;
}
num += diff;
if (num > numAnims - 1)
{
num = 0;
}
else if (num < 0)
{
num = numAnims - 1;
}
}
this.setState(num);
return num;
};
this.toggleEquipment = function (num)
{
if (this.section == SECTION_BRASS)
{
this.toggleHornType(num);
}
};
this.toggleHornType = function (num)
{
if (this.section == SECTION_BRASS)
{
this.setHornType(num);
}
};
this.setHornType = function (hornType)
{
this.hornType = hornType;
var animRow = 0;
var animCol = hornType % 4;
if (hornType > 3)
{
animRow = 5;
}
if (animRow != this.animRow)
{
this.img.style.top = (-1 * animRow * this.imgSizeY) - 1;
}
this.animRow = animRow;
this.frames = [FRAME_BRASS_SET + animCol * 2, FRAME_BRASS_PLAY + animCol * 2];
this.framesPlaying = [FRAME_BRASS_PLAY + animCol * 2];
this.gotoFrame(this.frames[this.state]);
};
this.catchEquipment = function ()
{
this.preTossFrame = 0;
this.isTossing = false;
if (this.equipment.isInAir)
{
this.equipment.catchIt();
this.gotoFrame(this.equipment.currentAnim['pose']);
this.equipment.catchMe = false;
}
};
this.pretoss = function (num)
{
if (this.equipment)
{
this.preTossFrame = num;
this.gotoFrame(6);
this.equipment.pretoss(num);
}
};
this.tossEquipment = function ()
{
if (this.equipment)
{
this.isTossing = true;
this.preTossFrame = 0;
this.gotoFrame((this.equipment.currentAnim.tossRight) ? 4 : 5);
this.lastTossSet = EDITOR.FFPJVV + 1;
this.equipment.toss();
}
};
this.animate = function (now, elapsedMS, endSetTime)
{
if (this.section == SECTION_GUARD)
{
}
else if (this.state == MARCHER_STATE_PLAYING)
{
if (ANIM_SPEED_MS[this.section] > 0)
{
if (now - this.lastAnimTime > ANIM_SPEED_MS[this.section])
{
if (this.framesPlaying.length > 1)
{
this.playFrame = (this.playFrame + 1) % this.framesPlaying.length;
this.gotoFrame(this.framesPlaying[this.playFrame]);
}
if (this.equipment)
{
this.equipment.nextFrame()
}
this.lastAnimTime = now;
}
}
}
else if ((this.section == SECTION_SNARE || this.section == SECTION_TENOR) &&  this.state == 4)
{
var animSpeed = ANIM_SPEED_MONKEY;
if (animSpeed > 0)
{
if (now - this.lastAnimTime > animSpeed)
{
if (this.framesPlaying.length > 1)
{
this.playFrame = (this.playFrame + 1) % 6;
this.gotoFrame(this.playFrame);
}
this.lastAnimTime = now;
}
}
}
};
this.loadCustomFlag = function (url)
{
EDITOR.numFlags = NUM_PREMIUM_FLAG_COLORS;
this.equipment.loadCustomFlag(url);
};
this.loadCustomProp = function (url)
{
this.img.src = url;
};
this.loadCustomUniform = function (url)
{
if (this.section == SECTION_METRONOME)
{
return false;
}
else if (this.section == SECTION_GUARD)
{
this.img.src = url;
}
else
{
this.img.src = url;
}
};
this.changeUniform = function (uniform)
{
if (this.section == SECTION_METRONOME)
{
return false;
}
else if (this.section == SECTION_GUARD)
{
this.changeGuardUniform(uniform);
}
else
{
uniUrl = imageUrl("sprites/m" + (uniform + 1) + "_uniform.png");
this.img.src = uniUrl;
}
};
this.changeGuardUniform = function (num)
{
if (! num) {  num = 0; }
this.animRow = num;
this.img.style.top = (-1 * this.animRow * this.imgSizeY) - 1;
this.uniformNum = num;
};
this.setFlag = function (num, isManualChange)
{
if (this.section == SECTION_GUARD)
{
if (! EDITOR.isPremium)
{
num = EDITOR.show.showConfig[SHOW_FLAG1];
}
this.flagNum = num;
var eqType = EQUIPMENT_FLAG
if (EDITOR.isPremium)
{
if (this.flagNum == 4)
{
eqType = EQUIPMENT_RIFLE;
}
else if (this.flagNum == 5)
{
eqType = EQUIPMENT_SABRE;
}
}
var newAnim = 0;
var resetAnim = false;
if (isManualChange && eqType != this.equipment.equipmentType)
{
var nextEqType = eqType;
var prevEqType = this.equipment.equipmentType;
if (nextEqType == EQUIPMENT_SABRE) {  nextEqType = EQUIPMENT_RIFLE; }
if (prevEqType == EQUIPMENT_SABRE) {  prevEqType = EQUIPMENT_RIFLE; }
this.equipment.prevAnim[prevEqType] = this.equipment.animNum;
if (this.equipment.prevAnim[nextEqType])
{
newAnim = this.equipment.prevAnim[nextEqType];
}
resetAnim = true;
}
this.equipment.setEquipmentType(eqType, this.flagNum);
if (resetAnim)
{
this.setState(newAnim);
}
}
};
this.hornDown = function ()
{
if (this.section != SECTION_BASS && this.section != SECTION_GUARD)
{
this.gotoFrame(this.frames[MARCHER_STATE_SET], false, true);
}
};
this.hornUp = function ()
{
if (this.state == MARCHER_STATE_PLAYING && this.section != SECTION_GUARD)
{
this.gotoFrame(this.frames[MARCHER_STATE_PLAYING]);
}
this.checkKneel(EDITOR.show.FFPJVV);
};
this.gotoFrame = function (num, xanim, isHornsDown)
{
if (this.section == SECTION_PROP || this.section == SECTION_METRONOME)
{
return false;
}
var col = num + this.frameOffset;
var row = this.animRow;
if (isHornsDown && (this.section == SECTION_SNARE || this.section == SECTION_TENOR) && this.state == 4)
{
this.updateSpriteFrame(col, row);
return true;
}
if (EDITOR.mode == MODE_VIEW && num == 0 && (this.section == SECTION_SNARE || this.section == SECTION_TENOR))
{
}
if (xanim && this.state == 1 && (this.section == SECTION_SNARE || this.section == SECTION_TENOR))
{
col = 1;
row = 1;
if (this.section == SECTION_SNARE) {  col = 1 + (num % 2); }
else if (this.section == SECTION_TENOR) {  col = 4 + Math.floor(num / 2); }
}
else if (this.state == 2 && this.section != SECTION_GUARD)
{
col = 0;
row = 6;
if (this.section == SECTION_SNARE) {  col = 4; }
else if (this.section == SECTION_TENOR) {  col = 5; }
else if (this.section == SECTION_BASS) {  col = 3; }
else if (this.section == SECTION_PLATES) {  col = 0; }
else if (this.hornType == 2) {  col = 1; }
else if (this.hornType == 4) {  col = 2; }
else if (this.hornType == 7) {  col = 3; }
}
else if (this.state == ANIM_KNEEL && this.section != SECTION_GUARD)
{
col = 0;
row = 7;
if (this.section == SECTION_SNARE) {  row = 8;  col = 4; }
else if (this.section == SECTION_TENOR) {  row = 8;  col = 5; }
else if (this.section == SECTION_PLATES) {  row = 8;  col = 6; }
else if (this.section == SECTION_BASS)
{
row = 9;
col = Math.floor((this.bassNum - 1) / 2);
}
else if (this.section == SECTION_BRASS) {  col = this.hornType; }
}
else if (this.state == 4 && this.section != SECTION_GUARD)
{
col = 0;
row = 10;
if (this.section == SECTION_SNARE)
{
if (! num) { num = 0; }
switch (num)
{
case 0 : row = 8;  col = 0;  break;
case 1 : row = 1;  col = 2;  break;
case 2 : row = 1;  col = 1;  break;
case 3 : row = 8;  col = 1;  break;
case 4 : row = 1;  col = 1;  break;
case 5 : row = 1;  col = 2;  break;
}
}
else if (this.section == SECTION_TENOR)
{
if (! num) { num = 0; }
switch (num)
{
case 0 : row = 8;  col = 2;  break;
case 1 : row = 1;  col = 4;  break;
case 2 : row = 1;  col = 5;  break;
case 3 : row = 8;  col = 3;  break;
case 4 : row = 1;  col = 5;  break;
case 5 : row = 1;  col = 4;  break;
}
}
else if (this.section == SECTION_PLATES) { } // not allowed
else if (this.section == SECTION_BASS)
{
}
else if (this.section == SECTION_BRASS) {  col = this.hornType; }
}
this.updateSpriteFrame(col, row);
};
this.updateSpriteFrame = function (col, row)
{
var borderOffset = -1;
if (ie && ! ie6)
{
borderOffset = 0;
}
this.img.style.left = (-1 * col * this.imgSizeX) + borderOffset;
var rowY =  (-1 * row * this.imgSizeY) - 1;
if (rowY != this.img.style.top)
{
this.img.style.top = rowY;
}
};
this.select();
this.deselect();
}
function oEquipment (aid)
{
this.img = new Image();
this.img.src = EDITOR.spriteURL['flag'];
this.img.className = "equipment";
this.img.id = aid + "eqi";
this.aid = aid;
this.equipmentType = EQUIPMENT_FLAG;
if (this.img.attachEvent)
this.img.attachEvent("ondragstart", function () { return false; });
this.animNum = 0;
this.currentAnim = {};
this.prevAnim = {};
this.imgSizeX = 36;
this.imgSizeY = 36;
this.x = -100;
this.y = -100;
this.baseZ = -100;
this.isInAir = false;
this.airHeight = 0;
this.airSpeed = 0;
this.catchMe = false;
this.isPretoss = false;
this.animOffset = [0,0,0];
this.frame = 0;
this.frameOffset = 0;
this.numSpinFrames = 8;
this.currentFrame = 0;
this.div = document.createElement('div');
this.div.setAttribute('id', aid + "eq");
this.div.style.position = "absolute";
this.div.style.left = "0px";
this.div.style.top = "0px";
this.div.style.zIndex = 1000;
this.div.style.width = this.imgSizeX + 1;
this.div.style.height = this.imgSizeY + 2;
this.div.style.clip = "rect(0px, " + (this.imgSizeX) + "px, " + (this.imgSizeY) + "px, 0px)";
this.div.appendChild(this.img);
$('editor').appendChild(this.div);
var self = this;
this.setEquipmentType = function (eqType, flagNum)
{
this.equipmentType = eqType;
this.changeFlagColor(flagNum);
this.currentAnim = ANIM[this.equipmentType][this.animNum];
};
this.loadCustomFlag = function (url)
{
if (ie)
{
this.img.width = FLAG_IMG_SIZE_X;
this.img.height = FLAG_IMG_SIZE_Y;
}
this.img.src = url;
};
this.destroySprite = function ()
{
this.div.removeChild(this.img);
$('editor').removeChild(this.div);
};
this.hide = function ()
{
this.div.style.display = 'none';
this.div.style.visibility = 'hidden';
};
this.unhide = function ()
{
this.div.style.display = 'block';
this.div.style.visibility = 'visible';
};
this.changeFlagColor = function (num)
{
this.img.style.top = (-1 * num * this.imgSizeY);
};
this.resetZ = function (az)
{
if (az > 0)
{
this.baseZ = az;
}
this.div.style.zIndex = (this.baseZ + 1) >> 0;
};
this.setAnim = function (newAnim)
{
this.animNum = newAnim;
this.isPretoss = false;
this.currentAnim = ANIM[this.equipmentType][newAnim];
if (this.currentAnim.offset && ! (EDITOR.show.editorVersion < 1.38 && EDITOR.isPremium))
{
this.animOffset[0] = this.currentAnim.offset[0];
this.animOffset[1] = this.currentAnim.offset[1];
this.animOffset[2] = this.currentAnim.offset[2];
}
else
{
this.resetOffset();
}
this.updatePos();
if (EDITOR.isPlaying && this.currentAnim.frames.length > 1) //  && this.animNum == newAnim
{
return false;
}
else
{
this.defaultFrame();
}
};
this.resetOffset = function ()
{
this.animOffset = [0,0,0];
};
this.defaultFrame = function ()
{
this.gotoFrame(0);
this.updatePos();
};
this.updatePos = function ()
{
this.move(this.x, this.y, 0, true);
};
this.nextFrame = function ()
{
var anim = this.animNum;
if (this.isInAir && this.equipmentType == EQUIPMENT_RIFLE)
{
anim = 5;
}
var frames = this.currentAnim.frames;
if (frames.length > 1)
{
this.frame = (this.frame + 1) % frames.length;
this.gotoFrame(this.frame);
}
};
this.gotoFrame = function (num, FFXOOH)
{
var anim = this.animNum;
if (this.isInAir)
{
anim = 5;
}
if (! FFXOOH)
{
FFXOOH = this.currentAnim;
}
var spriteFrame = FFXOOH.frames[num];
var frameRow = 0;
var frameCol = spriteFrame;
this.currentFrame = frameCol;
if (EDITOR.show.editorVersion < 1.38 && EDITOR.isPremium)
{
var oldToNew = { 0:0, 8:1, 6:2, 14:3, 17:5, 16:4 };
frameCol = oldToNew[spriteFrame];
if (! frameCol) { frameCol = 0; }
}
this.img.style.left = px(-1 * frameCol * this.imgSizeX);
};
this.forceFrame = function (frameCol)
{
this.img.style.left = px(-1 * frameCol * this.imgSizeX);
};
this.pretoss = function (num)
{
this.isPretoss = true;
this.forceFrame((num == 1) ? 0 : 7);
};
this.toss = function ()
{
this.isPretoss = false;
this.airHeight = 0;
this.isInAir = true;
var tossAnimNum = this.currentAnim['tossAnimNum'];
this.currentAnim = TOSS_ANIM[this.equipmentType][tossAnimNum];
this.airSpeed = this.currentAnim['tossSpeed'];
};
this.airUpdate = function ()
{
this.airSpeed -= TOSS_GRAVITY;
var flatSpeed = this.airSpeed;
if (flatSpeed > 3.0)
{
flatSpeed = 3.0;
}
else if (flatSpeed < -3.0)
{
flatSpeed = -3.0;
}
this.airHeight += flatSpeed;
if (this.airHeight <= 0)
{
this.catchIt();
}
};
this.catchIt = function ()
{
this.catchMe = true;
this.isInAir = false;
this.airSpeed = 0;
this.airHeight = 0;
var catchFrame = this.currentAnim.catchFrame;
this.currentAnim = TOSS_ANIM[this.equipmentType][0];
if (catchFrame == -1)
{
}
else
{
this.currentFrame = catchFrame;
this.setAnim(0);
}
};
this.move = function (ax,ay,az, doForce)
{
var offX = -9;
var offY =  2;
if (! this.isInAir)
{
if (this.isPretoss)
{
offY += 1;
doForce = true;
}
else
{
offX += this.animOffset[0];
offY += this.animOffset[1];
}
}
if (doForce || this.x != ax)
{
this.x = ax;
this.div.style.left = (ax + offX);
}
if (this.isInAir)
{
this.airUpdate();
}
if (doForce || this.y != ay || this.isInAir)
{
this.y = ay;
this.div.style.top = ay + offY - this.airHeight;
if (az > 0)
{
this.resetZ(az);
}
}
};
this.setGhost = function (isOn)
{
if (isOn)
{
setAlpha(this.div.id, 25);
this.isGhost = true;
this.div.style.zIndex = 6;
this.img.style.cursor = 'default';
}
else
{
setAlpha(this.div.id, 100);
this.isGhost = false;
this.move(this.x, this.y, true);
this.img.style.cursor = 'move';
this.resetZ();
}
};
}
function snapX (toX)
{
var interval = GRID_X[ EDITOR.snapX ];
var offX = GRID_X_NUDGE[ EDITOR.snapX ];
toX = (toInt(toX / interval) * interval) + 8 + offX;
return toX;
}
function snapY (toY)
{
var interval = 9;
toY = (toInt(toY / interval) * interval);
return toY;
}
function newHelp (inner, doForce)
{
if (EDITOR.mode == MODE_EDIT && (doForce || (! EDITOR.isRestored && EDITOR.doShowHelp)))
{
$('help').innerHTML = inner;
show('help');
}
}
function newSetNumber (num)
{
if (EDITOR.mode == MODE_EDIT)
{
var msg = "Set " + (num + 1);
if (num == MAX_SETS)
msg = "Last Set";
$('setnumber').innerHTML = msg;
show('setnumber');
setAlpha('setnumber', 100);
setTimeout("fadeOut('setnumber')", 500);
}
}
function updateAddSetLink ()
{
if (EDITOR.mode == MODE_EDIT && ! EDITOR.isPlaying)
{
if (EDITOR.show.maxSet < MAX_SETS) // EDITOR.show.FFPJVV == EDITOR.show.maxSet && EDITOR.setIsChanged
{
lightAddSetLink();
}
else
{
darkAddSetLink();
}
}
}
function lightAddSetLink ()
{
$('addsetlink').style.color = "#DFD13A";
}
function darkAddSetLink ()
{
$('addsetlink').style.color = "#17391E";
}
function ajax_vote (showID, score)
{
if (EDITOR.hasVoted) return false;
if (score == 10)
{
if (! confirm("Are you sure this show is among the very best of MML?"))
{
return false;
}
}
else if (score == 1)
{
if (! confirm("A score of 1 means this show has absolutely no merit.\n\nAre you sure about this?"))
{
return false;
}
}
EDITOR.hasVoted = true;
if (EDITOR.isPlaying) EDITOR.show.stop();
if (score == 0)
{
$('voting').innerHTML = "Reporting Show to Moderators...";
$('votepanel').style.visibility = "hidden";
}
else
{
$('votepanel').style.visibility = "hidden";
}
show('voting');
params = "showID=" + showID + "&score=" + score + "&rand=" + Math.random();
AJAX_TIME = new Date().getTime();
$('rpc').src = "/remote/vote.php?" + params;
AJAX_TIMEOUT_ID = setTimeout('ajax_problem()', AJAX_TIMEOUT_SECS * 1000);
}
function post_vote ()
{
EDITOR.didVote = true;
hide('voting');
hide('votepanel');
show('nextshowlink');
show('showinforight');
$('commentslink').style.visibility = 'visible';
$('author').style.visibility = 'visible';
$('authordrop').style.visibility = 'visible';
open_comments(EDITOR.showID, EDITOR.show.authorName);
increment_judged_shows();
location.hash = rand(200000,999999);
}
function draw_votepanel (showID, doDisqual)
{
var inner = "";
var start = 1;
if (doDisqual) { start = 0; };
for (i=start; i <= 10; i++)
{
var label = i;
var isdiqual = "true";
if (i == 0)
{
label = 'X';
isdiqual = "confirm('Disqualify this show for being inappropriate?')";
}
inner += '<a class="votenum" href="#" onClick="if (' + isdiqual + ') { ajax_vote(' + showID + ',' + i + '); }; return false">' + label + '</a>'
}
$('voterow').innerHTML = inner;
}
function draw_votepanel_new (showID, doDisqual)
{
isdisqual = "confirm('Disqualify this show for being inappropriate?')";
var inner = "";
if (doDisqual)
inner += '<a class="votenum" href="#" onClick="if (' + isdisqual + ') { ajax_vote(' + showID + ', 0); }; return false">&#10008;</a>'
inner += '<a class="votenum" href="#" onClick="ajax_vote(' + showID + ', 1); return false">&#9733;</a>';
inner += '<a class="votenum" href="#" onClick="ajax_vote(' + showID + ', 4); return false">&#9733;&#9733;</a>';
inner += '<a class="votenum" href="#" onClick="ajax_vote(' + showID + ', 7); return false">&#9733;&#9733;&#9733;</a>';
inner += '<a class="votenum" href="#" onClick="ajax_vote(' + showID + ', 10); return false">&#9733;&#9733;&#9733;&#9733;</a>';
$('voterow').innerHTML = inner;
}
function increment_judged_shows ()
{
if ($('judgecountnum'))
$('judgecountnum').innerHTML = toInt($('judgecountnum').innerHTML) + 1;
}
var IS_FAVORITE = false;
function ajax_favorite (loggedIn, showID, authorID, isRookie)
{
if (! loggedIn)
{
alert("Please log in to Favorite this show.");
return false;
}
if (! isRookie)
{
alert("Sorry, you must be a Rookie (100 XP) to Favorite a show.");
return false;
}
if (EDITOR.isJudge && ! EDITOR.didVote)
{
alert("Please judge the show before adding it as a Favorite.");
return false;
}
if (IS_FAVORITE) return false;
if (! confirm("It will cost 5 XP to add this show to your Favorites.\n\nContinue?"))
{
return false;
}
IS_FAVORITE = true;
$('favoriteLabel').innerHTML = "One Sec...";
var params = "showID=" + showID + "&authorID=" + authorID + "&rand=" + Math.random();
$('rpc').src = "/remote/favorite.php?" + params;
}
function favorite_response (status)
{
setTimeout("buy_favorite()", 400);
}
function buy_favorite ()
{
$('favoriteLabel').innerHTML = 'Favorite!';
$('favoriteLabel').style.color = '#fff';
$('favorite_icon').style.backgroundPosition = '-32px 0px';
$('favoriteCell').style.cursor = 'default';
$('favoriteCell').onclick = null;
$('favoriteCell').onmouseover = null;
}
var ACTION_MESSAGE_ID = 0;
var ACTION_MESSAGE_ON = false;
var ACTION_BG = "";
var ___BB = 0;
function action_message (msg, delay, clearMS)
{
$('actionmessage').innerHTML = msg;
if (! delay) { delay = 10; }
if (! clearMS) { clearMS = 600; }
clearTimeout(ACTION_MESSAGE_ID);
if (___BB == 1)
{
___BB = 2;
ACTION_BG = $('actionmessage').style.backgroundColor;
$('actionmessage').style.backgroundColor = "#000";
$('actionmessage').style.color = "#c00";
}
ACTION_MESSAGE_ON = true;
setTimeout("show('actionmessage')", delay);
ACTION_MESSAGE_ID = setTimeout("clear_action_message()", clearMS + delay);
}
function show_action_message (msg)
{
action_message(msg,0,0);
clearTimeout(ACTION_MESSAGE_ID);
ACTION_MESSAGE_ID = 0;
}
function clear_action_message ()
{
hide('actionmessage');
ACTION_MESSAGE_ON = false;
if (___BB == 2)
{
___BB = 3;
$('actionmessage').style.backgroundColor = ACTION_BG;
$('actionmessage').style.color = "#fff";
}
if (ACTION_MESSAGE_ID)
{
clearTimeout(ACTION_MESSAGE_ID);
ACTION_MESSAGE_ID = 0;
}
}
var OPTION_CLICKED = false;
var PREV_OPTION = null;
function option_click (url)
{
OPTION_CLICKED = true;
location.href = url;
document.onfocus = function () { OPTION_CLICKED = false; };
}
function option_over (option, isBright, isIcon)
{
if (OPTION_CLICKED) return false;
var bg = getElementsByClass(option, 'featurebg');
if (bg[0]) { bg[0].style.backgroundColor = "#067616"; } else { option.style.backgroundColor= (isBright) ? '#3A9E47' : '#66AB6F'; }
if (isIcon)
{
var icons = getElementsByClass(option, 'showicon');
var nowX = parseInt(icons[0].style.backgroundPosition);
var offsetY = (isBright) ? -64 : -32;
icons[0].style.backgroundPosition = nowX + " " + offsetY + "px";
}
}
function option_out (option, isBright, isIcon)
{
if (OPTION_CLICKED) return false;
var bg = getElementsByClass(option, 'featurebg');
if (bg[0]) { bg[0].style.backgroundColor = "transparent"; } else { option.style.backgroundColor='transparent'; }
if (isIcon)
{
var icons = getElementsByClass(option, 'showicon');
var nowX = parseInt(icons[0].style.backgroundPosition);
icons[0].style.backgroundPosition = nowX + " 0px";
}
}
function playbutton_over (option)
{
option.style.borderColor='#fff';
document.body.style.cursor='pointer';
}
function playbutton_out (option)
{
option.style.borderColor='#AAD6AE';
document.body.style.cursor ='default';
}
function toptab_over (option)
{
document.body.style.cursor='pointer';
}
function toptab_out (option)
{
document.body.style.cursor ='default';
}
function group_badge_over (option)
{
option.style.borderColor='#ff0';
}
function group_badge_out (option)
{
option.style.borderColor='#9FDAA6';
}
var STACK_DUMPED = false;
function printStackTrace (passed) {
if (STACK_DUMPED)
{
return false;
}
STACK_DUMPED = true;
var callstack = [];
var isCallstackPopulated = false;
try {
i.dont.exist+=0;
} catch(e) {
if (e.stack) { //Firefox
var lines = e.stack.split("\n");
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
callstack.push(lines[i]);
}
}
callstack.shift();
isCallstackPopulated = true;
}
else if (window.opera && e.message) { //Opera
var lines = e.message.split("\n");
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
var entry = lines[i];
if (lines[i+1]) {
entry += " at " + lines[i+1];
i++;
}
callstack.push(entry);
}
}
callstack.shift();
isCallstackPopulated = true;
}
}
if (!isCallstackPopulated) { //IE and Safari
var currentFunction = arguments.callee.caller;
while (currentFunction) {
var fn = currentFunction.toString();
var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous";
callstack.push(fname);
currentFunction = currentFunction.caller;
}
}
output(callstack, passed);
}
function output (arr, passed) {
var dump = arr.join("\n");
dump += "\n\n" + "[num=" + passed + ", current=" + EDITOR.show.FFPJVV + ", max=" + EDITOR.show.maxSet + "]";
var addit = "<br /><b>Please send this to the admin: </b><br /><textarea style=\"width: 500px; height: 300px\">" + dump + "</textarea> <br /><br />";
document.body.innerHTML += addit;
window.scrollBy(200000, 0);
}
function addListener (event, elID, func)
{
var elem = $(elID);
if (elem.addEventListener) // W3C DOM
{
elem.addEventListener(event, func, false);
}
else if (elem.attachEvent)  // IE DOM
{
elem.attachEvent("on" + event, func);
}
}
function FFMBEJ (p1, p2)
{
r = Math.atan2(p2[1] - p1[1], p2[0] - p1[0]);
degrees = r * 180 / Math.PI;
degrees = (degrees + 270) % 360;
return degrees;
}
function get_distance (p1, p2)
{
var dx = Math.pow(p2[0] - p1[0], 2);
var dy = Math.pow(p2[1] - p1[1], 2);
var len = Math.sqrt(dx + dy);
return len;
}
function angle_difference (a0, a1)
{
return (a0 + 180 -  a1) % 360 - 180;
}
var AJAX_TIME = 0;
var AJAX_TIMEOUT_ID = 0;
function get_ajax ()
{
var request = null;
try
{
request = new XMLHttpRequest();
}
catch (e)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return request;
}
function ajax_request_get (url)
{
var ajax = get_ajax();
ajax.open("GET", url, true);
ajax.onreadystatechange = function ()
{
if (ajax.readyState == 4)
{
alert(ajax.responseText);
}
}
ajax.send(null);
}
function ajax_problem ()
{
if (EDITOR.isSaving)
{
alert("There is a temporary problem connecting to the server.\n\nPlease try again in another minute.\n\nDo NOT leave this page or you will lose your unsaved changes.\n\nIf the problem continues, check twitter.com/micromarching for any updates on server maintenance.");
hide('saving');
EDITOR.isSaving = false;
}
else if (EDITOR.hasVoted)
{
alert("There is a temporary problem connecting to the server.\n\nPlease try again in another minute.");
hide('voting');
show('votepanel');
EDITOR.hasVoted = false;
}
}
function keyCommandUp (evt)
{
if (EDITOR.pauseKeyListener)
return true;
var key = (evt.which || evt.keyCode || evt.charCode);
var stringKey = String.fromCharCode(key).toLowerCase();
stopEvent = false;
if (stringKey == "`" || stringKey == "~" || key == 192)
{
EDITOR.fakeCtrl = false;
stopEvent = true;
}
else if (stringKey == "q")
{
EDITOR.quickSelect = false;
EDITOR.quickUnhighlight();
stopEvent = true;
}
else if (stringKey == '1')
{
EDITOR.disableWandSelect();
stopEvent = true;
}
if (stopEvent)
{
if (evt.preventDefault)
{
evt.preventDefault();
evt.stopPropagation();
}
else
{
evt.returnValue = false;
evt.cancelBubble = true;
}
return false;
}
return true;
}
function keyCommand (evt)
{
if (EDITOR.pauseKeyListener)
{
return true;
}
var key = (evt.which || evt.keyCode || evt.charCode);
var stringKey = String.fromCharCode(key).toLowerCase();
stopEvent = true;
if (evt.shiftKey)
{
var isFine = (evt.ctrlKey || EDITOR.fakeCtrl);
if (key == 39 || key == 102)
{
EDITOR.show.scaleMarchers(1,0,isFine)
}
else if (key == 37 || key == 100)
{
EDITOR.show.scaleMarchers(-1,0,isFine)
}
else if (key == 38 || key == 104)
{
EDITOR.show.scaleMarchers(0,1,isFine)
}
else if (key == 40 || key == 98 || key == 101)
{
EDITOR.show.scaleMarchers(0,-1,isFine)
}
else if (stringKey == "2" || stringKey == "@")
{
EDITOR.show.showRippleStatus();
}
else if (stringKey == 's')
{
EDITOR.show.toggleAutoSave();
}
else if (stringKey == "f")
{
EDITOR.show.followTheLeader(true);
}
else if (stringKey == 'a')
{
EDITOR.show.toggleMarcherState(true);
}
else
{
stopEvent = false;
}
}
else if (evt.altKey)
{
if (key == 39)
{
}
else if (key == 37)
{
}
else if (key == 38)
{
}
else if (key == 40)
{
}
else
{
stopEvent = false;
}
}
else if (evt.ctrlKey || EDITOR.fakeCtrl)
{
if (key == 39)
{
EDITOR.show.nudgeMarchers(9,0);
}
else if (key == 37)
{
EDITOR.show.nudgeMarchers(-9,0);
}
else if (key == 38)
{
EDITOR.show.nudgeMarchers(0,-9);
}
else if (key == 40)
{
EDITOR.show.nudgeMarchers(0,9);
}
else if (key == 33)
{
EDITOR.show.jumpToLastSet();
}
else if (key == 34)
{
EDITOR.show.jumpToFirstSet();
}
else if (key == 8)
{
EDITOR.show.resetMarchers(true);
}
else if (key == 46 || stringKey == 'd')
{
EDITOR.show.deleteMarchers(true);
}
else if (stringKey == ']' || key == 221)
{
EDITOR.show.rotateMarchers(1, true);
}
else if (stringKey == '[' || key == 219)
{
EDITOR.show.rotateMarchers(-1, true);
}
else if (stringKey == '=' || key == 187)
{
if (! EDITOR.fakeCtrl && webkit && ! isChrome)
{
alert("In Safari, you'll need to hold the ~ key instead of Ctrl.");
}
else
{
EDITOR.show.scaleMarchers(1,1, true);
}
}
else if (stringKey == '-' || key == 189)
{
if (! EDITOR.fakeCtrl && webkit && ! isChrome)
{
alert("In Safari, you'll need to hold the ~ key instead of Ctrl.");
}
else
{
EDITOR.show.scaleMarchers(-1,-1, true);
}
}
else if (stringKey == "2")
{
EDITOR.show.clearRipples();
}
else if (stringKey == '9' || stringKey == '(')
{
EDITOR.show.arcMarchers(-1, true);
}
else if (stringKey == '0' || stringKey == ')')
{
EDITOR.show.arcMarchers(1, true);
}
else if (stringKey == 'a')
{
EDITOR.show.selectAllMarchers();
}
else if (stringKey == "g")
{
EDITOR.show.ghostMarchers(true);
}
else if (stringKey == "m")
{
EDITOR.show.addMetronome();
}
else if (stringKey == "b")
{
EDITOR.show.cleanBlock(true);
}
else if (stringKey == "i")
{
EDITOR.show.cleanLine(true);
}
else if (stringKey == 'o')
{
EDITOR.show.circleMarchers(true, false);
}
else if (stringKey == "c")
{
EDITOR.show.copyDots();
}
else if (stringKey == "v")
{
EDITOR.show.pasteDots();
}
else if (stringKey == 'e')
{
}
else if (stringKey == 's')
{
if (! EDITOR.isGroupSnapshot)
{
EDITOR.show.manualSave();
}
}
else if (stringKey == 'z')
{
EDITOR.undo();
}
else if (stringKey == 'y')
{
EDITOR.redo();
}
else if (key == 32)
{
if (! THROTTLE_SPACE_BAR)
{
if (EDITOR.isPlaying)
{
EDITOR.show.stop();
}
else
{
EDITOR.isSlowPlay = true;
EDITOR.show.pressPlay();
}
THROTTLE_SPACE_BAR = true;
setTimeout("THROTTLE_SPACE_BAR = false;", 500);
}
}
else if (stringKey == "5" || stringKey == "%")
{
EDITOR.show.selectEveryOtherMarcher(true);
}
else if (stringKey == "3" || stringKey == "#")
{
EDITOR.toggleHashes(true);
}
else
{
stopEvent = false;
}
}
else
{
if (key == 39)
{
EDITOR.show.nudgeMarchers(1,0);
}
else if (key == 37)
{
EDITOR.show.nudgeMarchers(-1,0);
}
else if (key == 38)
{
if (EDITOR.animScroll)
{
EDITOR.show.toggleMarcherState(false);
}
else
{
EDITOR.show.nudgeMarchers(0,-1);
}
}
else if (key == 40)
{
if (EDITOR.animScroll)
{
EDITOR.show.toggleMarcherState(true);
}
else
{
EDITOR.show.nudgeMarchers(0,1);
}
}
else if (key == 8)
{
EDITOR.show.resetMarchers(false);
}
else if (key == 46 || stringKey == 'd')
{
EDITOR.show.deleteMarchers(false);
}
else if (key == 33)
{
EDITOR.show.jumpToNextSet();
}
else if (key == 34)
{
EDITOR.show.jumpToPrevSet();
}
else if (stringKey == 'o')
{
EDITOR.show.circleMarchers(false, false);
}
else if (stringKey == '9' || stringKey == '(')
{
EDITOR.show.arcMarchers(-1);
}
else if (stringKey == '0' || stringKey == ')')
{
EDITOR.show.arcMarchers(1);
}
else if (stringKey == 's')
{
}
else if (key == 59 || key == 186)
{
EDITOR.toggleSetPins();
}
else if (stringKey == 'p')
{
}
else if (stringKey == 'z')
{
}
else if (stringKey == 'a')
{
EDITOR.show.toggleMarcherState(false);
}
else if (stringKey == 'e')
{
EDITOR.show.toggleMarcherEquipment(false);
}
else if (stringKey == 'l')
{
EDITOR.show.selectLongestMarcher();
}
else if (stringKey == 'r')
{
EDITOR.recoverLostMarchers();
}
else if (stringKey == '1')
{
EDITOR.enableWandSelect();
}
else if (stringKey == ']' || key == 221)
{
EDITOR.show.rotateMarchers(1,false);
}
else if (stringKey == '[' || key == 219)
{
EDITOR.show.rotateMarchers(-1,false);
}
else if (stringKey == '=' || key == 187)
{
EDITOR.show.scaleMarchers(1,1,false);
}
else if (stringKey == '-' || key == 189)
{
EDITOR.show.scaleMarchers(-1,-1,false);
}
else if (key == 32)
{
if (! THROTTLE_SPACE_BAR)
{
if (EDITOR.isPlaying)
{
EDITOR.show.stop();
}
else
{
EDITOR.show.pressPlay();
}
THROTTLE_SPACE_BAR = true;
setTimeout("THROTTLE_SPACE_BAR = false;", 500);
}
}
else if (stringKey == "i")
{
EDITOR.show.cleanLine(false);
}
else if (stringKey == "b")
{
EDITOR.show.cleanBlock();
}
else if (stringKey == "t")
{
EDITOR.show.tradeSets();
}
else if (stringKey == "g")
{
EDITOR.show.ghostMarchers(false);
}
else if (stringKey == "y")
{
EDITOR.toggleSnap();
}
else if (stringKey == "f")
{
EDITOR.show.followTheLeader(false);
}
else if (stringKey == "`" || stringKey == "~" || key == 192)
{
EDITOR.fakeCtrl = true;
}
else if (stringKey == "q")
{
if (! EDITOR.quickSelect)
{
EDITOR.quickSelect = true;
EDITOR.quickHighlightGroup();
}
}
else if (stringKey == "5")
{
EDITOR.show.selectEveryOtherMarcher(false);
}
else if (stringKey == "2")
{
EDITOR.show.addRipple();
}
else if (stringKey == "c")
{
EDITOR.show.toggleMarcherCaption();
}
else if (stringKey == "x")
{
}
else if (stringKey == "3")
{
EDITOR.toggleHashes(false);
}
else if (stringKey == "7")
{
EDITOR.show.cleanCurve(false);
}
else if (stringKey == "/" || key == 191)
{
}
else
{
stopEvent = false;
}
}
if (stopEvent)
{
if (evt.preventDefault)
{
evt.preventDefault();
evt.stopPropagation();
}
else
{
evt.returnValue = false;
evt.cancelBubble = true;
evt.keyCode = 0;
}
return false;
}
return true;
}
function keyCommandView (evt)
{
if (EDITOR.pauseKeyListener) {  return true; }
var key = (evt.which || evt.keyCode || evt.charCode);
var stringKey = String.fromCharCode(key).toLowerCase();
stopEvent = true;
if (key == 33)
{
if (EDITOR.isJudge && ! EDITOR.didVote)
{
}
else
{
EDITOR.isAnalyze = true;
EDITOR.show.stop();
if (evt.ctrlKey || EDITOR.fakeCtrl)
{
EDITOR.show.jumpToLastSet();
}
else
{
EDITOR.show.jumpToNextSet();
}
}
}
else if (key == 34)
{
if (EDITOR.isJudge && ! EDITOR.didVote)
{
}
else
{
EDITOR.isAnalyze = true;
EDITOR.show.stop();
if (evt.ctrlKey || EDITOR.fakeCtrl)
{
EDITOR.show.jumpToFirstSet();
}
else
{
EDITOR.show.jumpToPrevSet();
}
}
}
else if (key == 32)
{
if (EDITOR.isJudge && ! EDITOR.didVote)
{
}
else
{
if (! THROTTLE_SPACE_BAR)
{
if (EDITOR.isPlaying)
{
EDITOR.show.stop();
}
else
{
if (evt.ctrlKey || EDITOR.fakeCtrl)
{
EDITOR.isSlowPlay = true;
}
EDITOR.isAnalyze = true;
EDITOR.show.pressPlay();
}
THROTTLE_SPACE_BAR = true;
setTimeout("THROTTLE_SPACE_BAR = false;", 500);
}
}
}
else if (stringKey == 'r' && evt.ctrlKey)
{
EDITOR.toggleRecordMode();
}
else
{
stopEvent = false;
}
if (stopEvent)
{
if (evt.preventDefault)
{
evt.preventDefault();
evt.stopPropagation();
evt.returnValue = false;
}
else
{
evt.returnValue = false;
evt.cancelBubble = true;
}
return false;
}
return true;
}
function listenForKeyPress ()
{
EDITOR.pauseKeyListener = false;
if (document.addEventListener)
{
var keyevent = (webkit) ? "keydown" : "keypress";
document.addEventListener(keyevent, keyCommand, true);
document.addEventListener("keyup", keyCommandUp, true);
}
else if (document.attachEvent)
{
document.attachEvent("onkeydown", function(evt) {keyCommand(evt)});
document.attachEvent("onkeyup", function(evt) {keyCommandUp(evt)});
}
}
function listenForKeyPressView ()
{
EDITOR.pauseKeyListener = false;
if (document.addEventListener)
{
var keyevent = (webkit) ? "keydown" : "keypress";
document.addEventListener(keyevent, keyCommandView, true);
}
else if (document.attachEvent)
{
document.attachEvent("onkeydown", function(evt) {keyCommandView(evt)});
}
}
var __RPC_ID = 'rpc';
function get_rpc_doc (rpcID)
{
if (! rpcID)
{
rpcID = __RPC_ID;
}
if ($(rpcID).contentDocument)
{
return $(rpcID).contentDocument;
}
else if ($(rpcID).contentWindow)
{
return $(rpcID).contentWindow.document;
}
else if ($(rpcID).document)
{
return $(rpcID).document;
}
else
{
return true;
}
}
function spawn_rpc ()
{
var iframe = document.createElement('IFRAME');
iframe.id = 'rpc' + get_now();
iframe.style.display = "none";
document.body.appendChild(iframe);
__RPC_ID = iframe.id;
return iframe;
}
var __THROTTLE = {};
function throttle (actionID, delayMS)
{
var now = get_now();
if (! __THROTTLE[actionID]) { __THROTTLE[actionID] = 0; }
if (now > __THROTTLE[actionID])
{
__THROTTLE[actionID] = now + delayMS;
return false;
}
else
{
return true;
}
}
var _dec_to_base62 = [];
var _base62_to_dec = [];
var base62offset = 62 * 62 / 2;
init_base62();
function init_base62 ()
{
for (i=0; i <= 9; i++)
{
_dec_to_base62[''+i] = i;
}
for (i=10; i <= 35; i++)
{
_dec_to_base62[i] = String.fromCharCode(87 + i);
}
for (i=36; i <= 61; i++)
{
_dec_to_base62[i] = String.fromCharCode(i + 29);
}
for (i=0; i <= 61; i++)
{
_base62_to_dec[ '' + _dec_to_base62[i] ] = i;
}
}
function dec_to_base62 (dec)
{
if ( dec_to_base62.cache[ dec ] != null )
return dec_to_base62.cache[ dec ];
var dec2 = dec + base62offset;
var ones = dec2 % 62;
var tens = (dec2 / 62) >> 0;
var final = _dec_to_base62[tens] + "" + _dec_to_base62[ones];
dec_to_base62.cache[dec] = final;
return final;
}
dec_to_base62.cache = {};
function base62_to_dec (base62)
{
var tens = base62.charAt(0);
var ones = base62.charAt(1);
var total = (_base62_to_dec[tens] * 62) + _base62_to_dec[ones] - base62offset;
return total;
}
function char_dec_to_base62 (dec)
{
return _dec_to_base62[dec];
}
function char_base62_to_dec (base62)
{
return _base62_to_dec[base62];
}
function toInt (str)
{
return str >> 0;
}
var numAlerts = 0;
function debug (msg)
{
if (numAlerts > 10) {  return false; }
alert(msg);
numAlerts ++;
}
function imageUrl ($fileName)
{
return RELEASE_DIR + "/images/" + $fileName;
}
function fix_png ()
{
if (ie6)
{
if (document.all && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
{
document.styleSheets[0].addRule('img', 'behavior: url('+ RELEASE_DIR +'/js/iepngfix.htc)');
}
}
}
function rand (min, max)
{
return min + Math.floor(Math.random() * ((max - min) + 1));
}
function stress ()
{
var numFrames = 500;
var startTime = new Date().getTime();
for (frame=0; frame <= numFrames; frame++)
{
for (m=0; m < EDITOR.show.marchers.length; m++)
{
var nx = 100 + Math.ceil(Math.random() * 300);
var ny = 100 + Math.ceil(Math.random() * 200);
EDITOR.show.marchers[m].move(nx, ny);
EDITOR.show.marchers[m].img.style.left = -1 * nx;
}
}
var endTime = new Date().getTime();
var totalSecs = (endTime - startTime) / 1000;
var fps = numFrames / totalSecs;
alert(totalSecs + " secs  ---- " + fps + " fps");
}
//------------------------------------------------ EXTERNAL -------------------------------------------------
function addCSSRule (selector, attributes)
{
var ss = document.styleSheets[document.styleSheets.length-1];
if (ss.insertRule)
{
ss.insertRule(selector + '{' + attributes + '}', ss.cssRules.length);
}
else if (ss.addRule)
{
ss.addRule(selector, attributes);
}
}
function fadeOut (elID, alpha)
{
show(elID);
if (! defined(alpha))
alpha = 100;
setAlpha(elID, alpha);
if (alpha > 0)
{
setTimeout("fadeOut('"+ elID +"', "+ (alpha - 25) +")", 100);
}
else
{
$(elID).style.display = "none";
}
}
function max_length(obj, maxlen)
{
return (obj.value.length <= maxlen);
}
function validate_form (fields)
{
for (var i=0,f; f=fields[i]; i++)
{
$(f).style.border="solid 1px #bbb";
}
for (var i=0,f; f=fields[i]; i++)
{
if ($(f).value == "")
{
$(f).style.border="solid 1px #900";
$(f).focus();
alert('Please fill out the entire form.');
return false;
}
}
if ($('email').value.indexOf('@') == -1)
{
$('email').style.borderColor="red";
$('email').focus();
alert('Please provide a valid e-mail address.');
return false;
}
return true;
}
function get_cookie ( name )
{
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) );
{
return null;
}
if ( start == -1 ) return null
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length
return unescape( document.cookie.substring( len, end ) );
}
function set_cookie (name,value,ex)
{
expires = ex * 1000 * 60 * 60 * 24;
var today = new Date();
today.setTime( today.getTime() );
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" + value + ";expires=" + expires_date.toGMTString();
}
function clear_cookie (name)
{
var today = new Date();
today.setTime( today.getTime() );
var expires_date = new Date( today.getTime() - 1);
document.cookie = name + "=;expires=" + expires_date.toGMTString();
}
function $ (elementID)
{
return document.getElementById(elementID);
}
function px (val)
{
if (! defined(val)) { return "0px"; }
return (val >> 0) + "px";
}
function get_now ()
{
return new Date().getTime();
}
function getnum (val)
{
if (! defined(val))
return 0;
return parseInt(val);
}
function setAlpha (elID, value)
{
if (! defined($(elID)) )
return false;
if (ns6)
{
$(elID).style.opacity = value / 100;
}
else
{
if (value == 100)
{
$(elID).style.filter = "";
}
else
{
$(elID).style.filter = "alpha(opacity=" + value + ")";
}
}
}
function setAlphaDirect (el, value)
{
if (ns6)
{
el.style.opacity = value / 100;
}
else
{
el.style.filter = "alpha(opacity=" + value + ")";
}
}
function defined (arg)
{
return (typeof arg != "undefined" && arg != null);
}
function hide (elID)
{
if ($(elID))
{
if ($(elID))
$(elID).style.visibility = "hidden";
}
}
function show (elID)
{
if ($(elID))
{
$(elID).style.visibility = "visible";
if ($(elID).style.display != "inline")
$(elID).style.display = "block";
}
}
var toggled = [];
function toggle (elID)
{
if (! toggled[elID])
{
show(elID);
toggled[elID] = 1;
}
else
{
hide(elID);
toggled[elID] = 0;
}
}
var COMMENTS_LOADED = false;
var COMMENTS_OPEN = false;
function open_comments (nodeID, authorUserName)
{
if (EDITOR.isJudge && ! EDITOR.didVote)
{
alert("Please judge the show before leaving a comment.");
return false;
}
if (! COMMENTS_LOADED)
{
show('commentloading');
$('commentsframe').src = "/comments.php?sid=" + nodeID + "&authorUserName=" + encodeURIComponent(authorUserName) + "&rand=" + Math.random();
}
if (COMMENTS_OPEN)
{
close_comments();
}
else
{
show('commentsdiv');
hide('showdesc');
EDITOR.show.abortShow();
COMMENTS_LOADED = true;
COMMENTS_OPEN = true;
}
}
function close_comments ()
{
hide('commentsdiv');
COMMENTS_OPEN = false;
}
var COMMENT_ADDED = false;
function submit_comment ()
{
$('commentbutton').value = "Please Wait...";
if (COMMENT_ADDED)
return false;
COMMENT_ADDED = true;
return true;
}
function open_show_results ()
{
show('showresultspopup');
}
function open_share_show ()
{
if (EDITOR.isJudge && ! EDITOR.didVote)
{
alert("Please judge the show before sharing it.");
return false;
}
else
{
show('showsharepopup');
}
}
function submit_show_comment ()
{
var checkComment = $('commentfield').value.toLowerCase();
checkComment = checkComment.replace(/[^a-z!]/g, "");
if (checkComment.length > 0 && checkComment.length < 3)
{
alert("Please say something a little more than that. =)");
return false;
}
else if (checkComment.match(/^(nice|good|goodjob|nicejob|cool|niceshow|goodshow)$/))
{
alert("Please say something a little more specific. =)");
return false;
}
else if (checkComment.length < 60 && checkComment.match(/[ck]o(l+)i(s+)(h*)(i*)[ou]n/))
{
alert("Please do not comment on collisions.  Thanks!");
return false;
}
else if (checkComment.length < 60 && checkComment.match(/crash/))
{
alert("Please do not comment on crashes.  Thanks!");
return false;
}
else if (checkComment.length < 60 && checkComment.match(/cali(tion|sh(i|o|a)n)/))
{
alert("Please do not comment on collisions.  Thanks!");
return false;
}
else
{
return submit_comment();
}
}
function crit_link (isAllowed, hasXP)
{
if (! isAllowed)
{
alert("This player does NOT want any critical feedback for this show.\n\nThanks for your cooperation.");
return false;
}
else if (! hasXP)
{
alert("To make sure feedback is of high quality, players need to be a Lead (3,000 XP) to offer advice.\n\nAny criticism added as a 'Like' will be automatically deleted.\n\nThanks for your cooperation.");
return false;
}
else
{
return confirm("Note: When leaving feedback, please provide specific, actionable advice.\n\nSaying 'Watch your transitions' is not enough!\n\nContinue?");
}
}
function comment_tab_add (isLoggedIn, age, xp)
{
age = 100;
xp = 1000;
if (! isLoggedIn)
{
alert('Please log in to add comments.');
return false;
}
else if (xp < 100)
{
alert('Sorry, you must be at least a Rookie (100 XP) to leave a comment.');
return false;
}
else if (age < 14)
{
if (xp <= 1000)
{
alert('Sorry, you must be a Veteran (1000 XP) to leave a comment.');
return false;
}
else
{
alert('Sorry, you must be at least 14 years old to leave a comment.');
return false;
}
}
$('commentlink').style.display = "none";
$('comments').style.display = "none";
$('newcomment').style.display = "block";
$('readlink').style.display = "block";
$('commentfield').focus();
}
function comment_tab_read ()
{
$('commentlink').style.display = "block";
$('comments').style.display = "block";
$('newcomment').style.display = "none";
$('readlink').style.display = "none";
}
function profile_comment_tab_add (isLoggedIn, age, xp)
{
if (! isLoggedIn)
{
alert('You must be logged in to add comments.');
return false;
}
else if (age < 14)
{
if (xp <= 100)
{
alert('You must be a Rookie (100 XP) to leave a comment.');
return false;
}
else
{
alert('You must be at least 14 years old to leave a comment.');
return false;
}
}
else if (xp < 100)
{
alert('You must be at least a Rookie (100 XP) to leave a comment.');
return false;
}
$('commentlink').style.display = "none";
$('commentlist').style.display = "none";
$('commentpost').style.display = "block";
$('readlink').style.display = "block";
$('forumtextarea').focus();
}
function profile_comment_tab_read ()
{
$('commentlink').style.display = "block";
$('commentlist').style.display = "block";
$('commentpost').style.display = "none";
$('readlink').style.display = "none";
}
function play_link_over (el)
{
el.style.color = "#F3EDAD";
el.style.border = "solid 1px #69A374";
}
function play_link_out (el)
{
el.style.color = "#DFD13A";
el.style.border = "solid 1px #467C50";
}
function menu_link_over (el)
{
el.style.color = "#fff";
el.style.border = "solid 1px #69A374";
}
function menu_link_out (el)
{
el.style.color = "#A1CCA9";
el.style.border = "solid 1px #467C50";
}
var addStyled = false;
function add_link_over (el)
{
el.style.color = "#F3EDAD";
el.style.border = "solid 1px #69A374";
addStyled = true;
}
function add_link_out (el)
{
if (addStyled)
{
el.style.color = "#DFD13A";
el.style.border = "solid 1px #467C50";
addStyled = false;
}
}
function abandon_show ()
{
if (confirm("Throw away this show and start a new one?"))
{
EDITOR.showIsChanged = false;
document.location.href="/design.php?rm=menu";
}
}
function save_response (status)
{
clearInterval(AJAX_TIMEOUT_ID);
EDITOR.isSaving = false;
if (status == "resave")
{
if (EDITOR.numSaveAttempts < 3)
{
++ EDITOR.numSaveAttempts;
EDITOR.show.ajaxSave();
}
else
{
hide('saving');
alert("There is a problem saving your show.\n\nFor some reason, all of your show data is not being sent to the server.");
EDITOR.numSaveAttempts = 0;
}
}
else if (status == "logged_out")
{
hide('saving');
EDITOR.numSaveAttempts = 0;
EDITOR.numSaveHeartbeats = 0;
}
else if (status == "cancel")
{
hide('saving');
EDITOR.numSaveAttempts = 0;
EDITOR.numSaveHeartbeats = 0;
EDITOR.showIsChanged = false;
if (ie)
{
document.execCommand('Stop');
}
else
{
var rpc = get_rpc_doc();
try {  rpc.stop(); } catch (e) {};
}
}
else
{
EDITOR.numSaveAttempts = 0;
EDITOR.numSaveHeartbeats = 0;
EDITOR.showIsChanged = false;
if (EDITOR.doPublishAfterSave)
{
EDITOR.show.finishPublish();
}
else if (EDITOR.postSaveAction == "preview")
{
if (true)
{
location.replace(EDITOR.previewURL);
}
EDITOR.postSaveAction = "";
}
else if (EDITOR.postSaveAction == "freezer")
{
hide('saving');
EDITOR.postSaveAction = "";
location.href = EDITOR.freezerURL;
}
else if (EDITOR.postSaveAction == "confirmsave")
{
var defaultMsg = $('saving').innerHTML;
var defaultColor = $('saving').style.backgroundColor;
$('saving').style.backgroundColor = "#3E427F";
$('saving').innerHTML = "Show Saved";
setTimeout(function () {  hide('saving'); $('saving').innerHTML = defaultMsg; $('saving').style.backgroundColor = defaultColor; }, 800);
EDITOR.postSaveAction = "";
}
else
{
var now = new Date().getTime();
if (now - AJAX_TIME < 500)
{
setTimeout("hide('saving')", 500 - (now - AJAX_TIME));
}
else
{
hide('saving');
}
}
}
}
function vote_response (status)
{
clearInterval(AJAX_TIMEOUT_ID);
var now = new Date().getTime();
var ms = 1;
if (now - AJAX_TIME < 500)
{
ms = 500 - (now - AJAX_TIME);
}
setTimeout('post_vote()', ms);
}
function showSavebox ()
{
if (EDITOR.isPlaying)
return false;
EDITOR.show.saveSet();
if (SHOW_TOOL_MENU)
{
toggleToolMenu();
}
if (EDITOR.isPublished)
{
alert("This show has already been published.");
return false;
}
if (EDITOR.show.maxSet < MIN_SETS - 1)
{
alert("You need at least " + MIN_SETS + " sets to publish a show.");
return false;
}
if (EDITOR.isPremium)
{
if (! EDITOR.show.guardLastSetIsOK())
{
alert("All guard members must end the show in a pose (Animations 1-" + NUM_FLAG_POSES + ").");
return false;
}
}
$('savebox').style.display = "block";
$('showTitle').focus();
EDITOR.pauseEvents();
}
function design_menu_loading (groupType, isBlocked)
{
if (isBlocked)
{
alert('This option is available to premium members.\n\nYou can visit the Shop (below) to upgrade any time.');
return false;
}
$('groupselectoptions').style.visibility = "hidden";
show('menuloading');
document.location.href="/design.php?rm=startnew&groupType=" + groupType;
}
function hideSavebox ()
{
if (! EDITOR.isPlaying)
$('savebox').style.display = "none";
EDITOR.initEvents();
}
function toggleToolMenu ()
{
SHOW_TOOL_MENU = 1 - SHOW_TOOL_MENU;
$('toolmenu').style.display = (SHOW_TOOL_MENU) ? 'block' : 'none';
}
function toggleToolMenu2 ()
{
SHOW_TOOL_MENU2 = 1 - SHOW_TOOL_MENU2;
$('toolmenu2').style.display = (SHOW_TOOL_MENU2) ? 'block' : 'none';
}
function confirmExit ()
{
if (EDITOR.mode == MODE_EDIT && EDITOR.show.maxSet > 1)
{
if (ie)
{
return confirm("Abandon your changes?");
}
else
{
return true;
}
}
else
{
return true;
}
}
function deepObjCopy (dupeObj) {
var retObj = new Object();
if (typeof(dupeObj) == 'object') {
if (typeof(dupeObj.length) != 'undefined')
var retObj = [];
for (var objInd in dupeObj) {
if (typeof(dupeObj[objInd]) == 'object') {
retObj[objInd] = deepObjCopy(dupeObj[objInd]);
} else if (typeof(dupeObj[objInd]) == 'string') {
retObj[objInd] = dupeObj[objInd];
} else if (typeof(dupeObj[objInd]) == 'number') {
retObj[objInd] = dupeObj[objInd];
} else if (typeof(dupeObj[objInd]) == 'boolean') {
((dupeObj[objInd] == true) ? retObj[objInd] = true : retObj[objInd] = false);
}
}
}
return retObj;
}
if (typeof Object.create !== 'function')
{
Object.create = function (o)
{
function F() {}
F.prototype = o;
return new F();
};
}
function getElementsByClass (rootobj, classname)
{
var els = [];
var inc = 0;
var children = rootobj.childNodes;
for (i=0; i < children.length; i++)
{
if (children[i].className == classname)
{
els.push(children[i]);
}
}
return els;
}
var oBridge =
{
xinit_show : function (args)
{
EDITOR = new oEditor();
EDITOR.is3D = args.is3D;
EDITOR.isJudge = args.isJudge;
EDITOR.isPreview = args.isPreview;
EDITOR.showID = args.showID;
EDITOR.groupType = args.groupType;
EDITOR.isPremium = args.isPremium;
EDITOR.isDemo = args.isDemo;
EDITOR.isGroupSnapshot = args.isGroupSnapshot;
EDITOR.initViewMode();
if (args.spriteURL)
{
EDITOR.spriteURL = args.spriteURL;
}
},
xinit_loaded : function (data)
{
LOADED = data;
var fnLoad = function ()
{
EDITOR.show.loadSaved();
EDITOR.show.hasDescription = data.hasDescription;
if (EDITOR.isGroupSnapshot)
{
EDITOR.show.hornsUp();
}
};
EDITOR.load_sprites(fnLoad);
},
xplay_show : function ()
{
EDITOR.show.play();
},
xdraw_votepanel : function (showID, doDisqual)
{
draw_votepanel(showID, doDisqual);
},
xstop_and_vote : function ()
{
EDITOR.show.stopAndVote();
},
xreload_sprite : function (spriteType, imageURL)
{
EDITOR.reload_sprite(spriteType, imageURL);
},
xplay_fast : function ()
{
if (! EDITOR.isFastPlay)
{
EDITOR.isFastPlay = true;
EDITOR.show.play();
}
}
}
function username_okay (userName)
{
if (userName.length < 4)
{
alert("Your name must be at least 4 letters long.");
return false;
}
else if (userName.match(/[0-9]/g) && userName.match(/[0-9]/g).length > 2)
{
alert("Your name can't have more than 2 numbers.");
return false;
}
else if (userName.match(/[^a-zA-Z0-9 ]/))
{
alert("Your name may only have letters, numbers, and spaces.");
return false;
}
else if (userName.split(/ /g).length - 1 > 1)
{
alert("Sorry, you can't have more than 1 space in your name.");
return false;
}
else if (userName.match(/^a |^the /i))
{
alert("Please start your name with something other than 'a' or 'the'.");
return false;
}
else if (userName.match(/regiment|cavies|band|sax|brass|tbone|trombone|baritone|tuba|snare|bass|flute|trumpet|soprano|euph|mello|contra|cntra|tenor|quad|quint|clarinet|oboe|drum|guard|flag|rifle|sabre/i))
{
alert("We already have a lot of people with band-related names.\n\nPlease pick something more unique. =)");
return false;
}
return true;
}
var ANIM_SCROLL_ID = 0;
var THROTTLE_SCROLL = false;
var IS_SCROLLING = false;
var IS_SCROLLING_ID = 0;
function handle(delta, event)
{
if (! IS_SCROLLING && (EDITOR.FFFMJP.length == 0 || ! EDITOR.cursorInEditor))
{
return true;
}
if (THROTTLE_SCROLL)
{
return false;
}
if (EDITOR.animScroll)
{
EDITOR.show.toggleMarcherState((delta < 0) ? true : false);
throttleScroll(50);
}
else if (event.shiftKey)
{
if (delta < 0)
{
EDITOR.show.scaleMarchers(-3,-3, true);
}
else
{
EDITOR.show.scaleMarchers(3,3, true);
}
}
else if (event.ctrlKey || EDITOR.fakeCtrl)
{
if (webkit && ! EDITOR.fakeCtrl)
{
var agent = (isChrome) ?  " Chrome" : "Safari";
alert("In " + agent + ", you'll need to hold the ~ key instead of Ctrl.");
throttleScroll(1000);
}
else
{
if (delta < 0)
{
EDITOR.show.arcMarchers(1);
}
else
{
EDITOR.show.arcMarchers(-1);
}
}
}
else
{
if (delta < 0)
{
EDITOR.show.rotateMarchers(2,2, true);
}
else
{
EDITOR.show.rotateMarchers(-2,-2, true);
}
}
IS_SCROLLING = true;
clearTimeout(IS_SCROLLING_ID);
IS_SCROLLING_ID = setTimeout("IS_SCROLLING = false;", 1200);
return false;
}
function throttleScroll (delayMS)
{
if (! delayMS) { delayMS = 50; }
THROTTLE_SCROLL = true;
setTimeout("THROTTLE_SCROLL = false", delayMS);
}
function wheel (event) {
var doPropagate = true;
var delta = 0;
if (! event) {  event = window.event; }
if (event.wheelDelta)
{
delta = event.wheelDelta / 120;
if (window.opera) {  delta = -delta; }
}
else if (event.detail)
{
delta = -event.detail / 3;
}
if (delta)
{
doPropagate = handle(delta, event);
}
if (event.preventDefault && ! doPropagate)
{
event.preventDefault();
}
event.returnValue = doPropagate;
}
function round_corners (el, color)
{
if (ie6 || ! ie) {  return false; }
if (! el) {  return false; }
var parent = el.parentNode;
var topStrip = make_strip(el, "top", color);
var bottomStrip = make_strip(el, "bottom", color);
parent.insertBefore(topStrip, el);
parent.insertBefore(bottomStrip, el.nextSibling);
}
function make_strip (el, side, color, width)
{
var s = document.createElement("DIV");
s.className = "borderStrip";
s.style.width = getStyle(el, "width");
s.style.position = "relative";
s.style.height = "0";
s.style.zIndex = el.style.zIndex + 10;
s.style.top = (side == 'top') ? "0px" : "-3px";
var marginType = "margin" + ucfirst(side);
s.style[marginType] = getStyle(el, marginType);
el.style[marginType] = 0;
var cornerL = make_corner(side, 'left', color);
var cornerR = make_corner(side, 'right', color);
s.appendChild(cornerL);
s.appendChild(cornerR);
return s;
}
function make_corner (vdirection, hdirection, color)
{
var c = get_rect(3);
c.style.zIndex = 10;
c.style.top = 0;
c.style[hdirection] = 0;
var inner = get_rect(3);
inner.style.position = 'relative';
c.appendChild(inner);
for (var y = 0; y < 3; y++)
{
if (y == 0 && vdirection == 'bottom') {  continue; }
if (y == 2 && vdirection == 'top') {  continue; }
for (var x = 0; x < 3; x++)
{
if (x == 1 && y == 1) {  continue; }
if (x == 0 && hdirection == 'right') {  continue; }
if (x == 2 && hdirection == 'left') {  continue; }
var p = get_rect(1);
p.style.left = x;
p.style.top = y;
p.style.backgroundColor = color;
inner.appendChild(p);
}
}
return c;
}
function get_rect (size)
{
var r = document.createElement('DIV');
r.style.position = 'absolute';
r.style.height = size;
r.style.width = size;
r.style.overflow = "hidden";
r.style.lineHeight = "1";
return r;
}
function ucfirst (string)
{
return string.charAt(0).toUpperCase() + string.slice(1);
}
function set_cursor (el, pos)
{
if (el.setSelectionRange)
{
el.setSelectionRange(pos, pos);
}
else if (el.createTextRange)
{
var range = el.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
function getStyle(oElm, strCssRule){
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
}
else if(oElm.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
return p1.toUpperCase();
});
strValue = oElm.currentStyle[strCssRule];
}
return strValue;
}
Array.prototype.map = function (fn)
{
var vals = [];
for (var el,i=0; el = this[i]; i++)
{
vals.push( fn(el) );
}
return vals;
};
