////////////////////////////////////////////////////////////////////////////////
// CONTRA DANCE DESIGNER - graphical display of contra dances, version 2.3
// COPYRIGHT (C) 2001  GCH & FRR Productions
// COPYRIGHT (C) 2001  GCH & AC Productions
////////////////////////////////////////////////////////////////////////////////
// this reference includes the most current GNU GENERAL PUBLIC LICENSE
// available online at www.gnu.org
////////////////////////////////////////////////////////////////////////////////
// VERSION 2.3 ONLY SUPPORTS MS/IE4.0+ FOR WINDOWS, MS/IE5.0+ FOR APPLES
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
// global variables
//
////////////////////////////////////////////////////////////////////////////////

var trace_flag = false;
var trace_win = null;

var g_contras = null;
var g_contra_beats = 0;
var g_contra_count = 0;
var g_contra_skip = true;
var g_contra_selected = -1;
var g_contra_loop = -1;
var g_contra_next = -1;

var g_dancers = null;
var g_dancer_count = 0;
var g_dancer_size = 20;
var g_dancer_move = (g_dancer_size/2);

var g_floor_width = 200;
var g_floor_height = 440;
var g_floor_square = 3;
var g_floor_x_top = 8;
var g_floor_x_topedge = (g_floor_x_top + (g_dancer_size * g_floor_square));
var g_floor_x_middle = (g_floor_x_top + (g_floor_height / 2));
var g_floor_x_bottom = (g_floor_x_top + g_floor_height - g_dancer_size);
var g_floor_x_bottomedge = (g_floor_x_bottom - (g_dancer_size * (g_floor_square - 1)));
var g_floor_y_left = 510;
var g_floor_y_leftedge = (g_floor_y_left + (g_dancer_size * g_floor_square));
var g_floor_y_center = (g_floor_y_left + (g_floor_width / 2));
var g_floor_y_right = (g_floor_y_left + g_floor_width - g_dancer_size);
var g_floor_y_rightedge = (g_floor_y_right - (g_dancer_size * (g_floor_square - 1)));

var g_moves = null;
var g_move_count = 0;
var g_move_continue = true;
var g_move_selected = -1;
var g_move_delay = 250;
var g_move_increment = 50;
var g_move_id = null;
var g_move_lineup = 0;
var g_move_progression = 1;
var g_move_activesxo = 2;
var g_move_becketleft = 3;
var g_move_becketright = 4;

var g_randomize_delay = 3000;
var g_randomize_id = null;

var g_stepcode_wait = 0;
var g_stepcode_exit = 9;
var g_stepcode_moveup = 1;
var g_stepcode_moveupright = 2;
var g_stepcode_moveright = 3;
var g_stepcode_movedownright = 4;
var g_stepcode_movedown = 5;
var g_stepcode_movedownleft = 6;
var g_stepcode_moveleft = 7;
var g_stepcode_moveupleft = 8;
var g_stepcode_lwstopleft = 71;
var g_stepcode_lwstopright = 72;
var g_stepcode_lwsbottomleft = 73;
var g_stepcode_lwsbottomright = 74;
var g_stepcode_sqltop = 75;
var g_stepcode_sqlmiddle = 76;
var g_stepcode_sqlbottom = 77;
var g_stepcode_dfztophalf = 81;
var g_stepcode_dfzbottomhalf = 82;
var g_stepcode_dfzlefthalf = 83;
var g_stepcode_dfzrighthalf = 84;
var g_stepcode_dfztopedge = 85;
var g_stepcode_dfzbottomedge = 86;
var g_stepcode_dfzleftedge = 87;
var g_stepcode_dfzrightedge = 88;
var g_stepcode_dfzmiddle = 89;
var g_stepcode_lead = 91;
var g_stepcode_follow = 92;
var g_stepcode_active = 93;
var g_stepcode_inactive = 94;
var g_stepcode_in = 95;
var g_stepcode_out = 96;

////////////////////////////////////////////////////////////////////////////////

function initialize()
{
	trace("initialize begin");

	move_initialize();
	contra_initialize();
	dancer_initialize();
	screen_initialize();
	move_randomize();

	document.MAIN.COMMAND.focus();

	trace("initialize end");
}

////////////////////////////////////////////////////////////////////////////////

function info(ix,msg)
{
	var opts = null;

	opts = document.MAIN.INFO.options;
	if ((ix < 1) || (ix > opts.length))
	{
		trace("ERROR: invalid info ix");
		return;
	}
	opts[(ix-1)] = new Option(msg,msg,false,false);
}

////////////////////////////////////////////////////////////////////////////////

function show_help()
{
	stop_all();
	var help_win = null;
	help_win = window.open("readme23.txt","HELP","width=650,height=500,menubar,scrollbars,resizable");
}

////////////////////////////////////////////////////////////////////////////////

function stop_all()
{
	g_contra_beats = 0;
	g_contra_loop = -1;
	g_contra_next = -1;
	g_move_continue = false;
	contra_info();
	document.MAIN.CURRENT.selectedIndex = -1;
	document.MAIN.MOVES.selectedIndex = -1;
	if (g_move_id != null)
	{
		clearTimeout(g_move_id);
		g_move_id = null;
	}
	if (g_randomize_id != null)
	{
		clearInterval(g_randomize_id);
		g_randomize_id = null;
	}
}

////////////////////////////////////////////////////////////////////////////////

function terminate()
{
	trace("terminate begin");

	if (trace_win != null)
	{
		trace_win.close();
		trace_win = null;
	}
}

////////////////////////////////////////////////////////////////////////////////

function trace(msg)
{
	if (trace_flag != true)
	{
		return;
	}
	if ((trace_win == null) || (trace_win.closed == true))
	{
 		trace_win = window.open("","TRACE","width=400,height=400,scrollbars,resizable,menubar");
		trace_win.document.open("text/plain");
		trace("TRACE BEGIN");
		trace("////////////////////////////////////////////////////////////////////////////////");
		trace("// CONTRA DANCE DESIGNER - graphical display of contra dances, version 2.3");
		trace("// COPYRIGHT (C) 2001  GCH & FRR Productions");
		trace("// COPYRIGHT (C) 2001  GCH & AC Productions");
		trace("////////////////////////////////////////////////////////////////////////////////");
		trace("// this reference includes the most current GNU GENERAL PUBLIC LICENSE");
		trace("// available online at www.gnu.org");
		trace("////////////////////////////////////////////////////////////////////////////////");
		trace("// VERSION 2.3 ONLY SUPPORTS MS/IE4.0+ FOR WINDOWS, MS/IE5.0+ FOR APPLES");
		trace("////////////////////////////////////////////////////////////////////////////////");
		trace("");
	}
	trace_win.document.writeln(msg);
}

////////////////////////////////////////////////////////////////////////////////
// CONTRA DANCE DESIGNER - graphical display of contra dances, version 2.3
// COPYRIGHT (C) 2001  GCH & FRR Productions
// COPYRIGHT (C) 2001  GCH & AC Productions
////////////////////////////////////////////////////////////////////////////////
// this reference includes the most current GNU GENERAL PUBLIC LICENSE
// available online at www.gnu.org
////////////////////////////////////////////////////////////////////////////////
// VERSION 2.3 ONLY SUPPORTS MS/IE4.0+ FOR WINDOWS, MS/IE5.0+ FOR APPLES
////////////////////////////////////////////////////////////////////////////////
