////////////////////////////////////////////////////////////////////////////////
// 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
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////

function contra_addcontra(name,author,info1,info2)
{
	var i = 0;

	for (i=0; i<g_contra_count; i+=1)
	{
		if ((g_contras[i].c_name == name) && (g_contras[i].c_author = author))
		{
			trace("ERROR: duplicate contra name & author");
			return;
		}
	}
	g_contras[g_contra_count] = new Object();
	g_contras[g_contra_count].c_name = name;
	g_contras[g_contra_count].c_author = author;
	g_contras[g_contra_count].c_info1 = info1;
	g_contras[g_contra_count].c_info2 = info2;
	g_contras[g_contra_count].c_moves = new Array();
	g_contras[g_contra_count].c_moves[0] = g_move_lineup;
	g_contras[g_contra_count].c_move_count = 1;
	g_contra_count += 1;
	trace("contra_addcontra name = " + name + " author = " + author);
}

////////////////////////////////////////////////////////////////////////////////

function contra_addmovebyindex(cix,mix)
{
	if ((cix < 0) || (cix >= g_contra_count))
	{
		trace("ERROR: invalid contra ix");
		return;
	}
	if ((mix < 0) || (mix >= g_move_count))
	{
		trace("ERROR: invalid move ix");
		return;
	}
	if (mix == g_move_lineup)
	{
		trace("ERROR: can't add move '" + g_moves[g_move_lineup].m_name + "'");
		return;
	}
	g_contras[cix].c_moves[g_contras[cix].c_move_count] = mix;
	g_contras[cix].c_move_count += 1;
	trace("contra_addmove cix = " + cix + " mix = " + mix);
}

////////////////////////////////////////////////////////////////////////////////

function contra_addmovebyname(cix,name)
{
	var i = 0;
	var mix = -1;

	if ((cix < 0) || (cix >= g_contra_count))
	{
		trace("ERROR: invalid contra ix");
		return;
	}
	for (i=0; i<g_move_count; i+=1)
	{
		if (name == g_moves[i].m_name)
		{
			mix = i;
			break;
		}
	}
	if ((mix < 0) || (mix >= g_move_count))
	{
		trace("ERROR: invalid move ix");
		return;
	}
	if (mix == g_move_lineup)
	{
		trace("ERROR: can't add move '" + g_moves[g_move_lineup].m_name + "'");
		return;
	}
	g_contras[cix].c_moves[g_contras[cix].c_move_count] = mix;
	g_contras[cix].c_move_count += 1;
	trace("contra_addmove cix = " + cix + " mix = " + mix);
}

////////////////////////////////////////////////////////////////////////////////

function contra_info()
{
	var i = 0;

	if ((g_contra_selected < 0) || (g_contra_selected >= g_contra_count))
	{
		info(1,"");
		info(2,"");
		info(3,"");
		info(4,"");
	}
	else
	{
		g_contra_beats = 0;
		for (i=0; i<g_contras[g_contra_selected].c_move_count; i+=1)
		{
			g_contra_beats += g_moves[g_contras[g_contra_selected].c_moves[i]].m_beat_count;
		}
		info(1,g_contras[g_contra_selected].c_info1);
		info(2,"by: " + g_contras[g_contra_selected].c_author);
		info(3,g_contras[g_contra_selected].c_info2);
		info(4,"total beats = " + g_contra_beats);
	}
}

////////////////////////////////////////////////////////////////////////////////

function contra_initialize()
{
	trace("contra_initialize begin");

	var name = null;
	var author = null;
	var info1 = null;
	var info2 = null;

	g_contras = new Array();
	g_contra_count = 0;

	name = "test contra 1";
	author = "GCH";
	info1 = "fast, fun & full hey-for-4";
	info2 = "vers 2.3";

	contra_addcontra(name,author,info1,info2);
	contra_addmovebyindex((g_contra_count - 1),g_move_activesxo);
	contra_addmovebyname((g_contra_count - 1),"do-si-do 1 up/down");
	contra_addmovebyname((g_contra_count - 1),"balance & swing up/down");
	contra_addmovebyname((g_contra_count - 1),"long lines forward & back");
	contra_addmovebyname((g_contra_count - 1),"follows chain across & courtesy turn");
	contra_addmovebyname((g_contra_count - 1),"full hey-for-4 across, follows start");
	contra_addmovebyname((g_contra_count - 1),"balance & swing up/down");
	contra_addmovebyname((g_contra_count - 1),"circle left 3/4");
	contra_addmovebyname((g_contra_count - 1),"passthru up/down");
	contra_addmovebyindex((g_contra_count - 1),g_move_progression);
	contra_addmovebyname((g_contra_count - 1),"outs cross over after forwards");

	name = "test contra 2";
	author = "GCH";
	info1 = "dancers go over the top";
	info2 = "vers 2.3";

	contra_addcontra(name,author,info1,info2);
	contra_addmovebyindex((g_contra_count - 1),g_move_becketright);
	contra_addmovebyname((g_contra_count - 1),"california twirl up/down");
	contra_addmovebyname((g_contra_count - 1),"balance & swing up/down");
	contra_addmovebyname((g_contra_count - 1),"slide left 2");
	contra_addmovebyname((g_contra_count - 1),"1/2 sashay across");
	contra_addmovebyname((g_contra_count - 1),"1/2 figure 8 above" );
	contra_addmovebyname((g_contra_count - 1),"circle right 1/2");
	contra_addmovebyname((g_contra_count - 1),"tops balance & swing across");


	contra_addcontra("new","","","");

	trace("contra_initialize end");
}

////////////////////////////////////////////////////////////////////////////////

function contra_show(cix)
{
	var i = 0;

	if ((cix < 0) || (cix >= g_contra_count))
	{
		trace("ERROR: invalid contra ix");
		return;
	}
	trace("");
	trace("show contra ix = " + cix);
	trace("  name = " + g_contras[cix].c_name);
	trace("  author = " + g_contras[cix].c_author);
	trace("  info1 = " + g_contras[cix].c_info1);
	trace("  info2 = " + g_contras[cix].c_info2);
	trace("  move_count = " + g_contras[cix].c_move_count);
	trace("  moves = ");
	for (i=0; i<g_contras[cix].c_move_count; i+=1)
	{
		trace("    (" + i + "," + g_contras[cix].c_moves[i] + ") " + g_moves[g_contras[cix].c_moves[i]].m_name);
	}
}

////////////////////////////////////////////////////////////////////////////////

function contra_undoadd(cix)
{
	if ((cix < 0) || (cix >= g_contra_count))
	{
		trace("ERROR: invalid contra ix");
		return;
	}
	if (g_contras[cix].c_move_count <= 1)
	{
		trace("ERROR: can't undo move '" + g_moves[g_move_lineup].m_name + "'");
		return;
	}
	g_contras[cix].c_move_count -= 1;
	g_contras[cix].c_moves[g_contras[cix].c_move_count] = null;
	trace("contra_undoadd ix = " + cix);
}

////////////////////////////////////////////////////////////////////////////////
// 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
////////////////////////////////////////////////////////////////////////////////

