// Pre-cache pictorial images we will need.

//colors for resistors and jumpers

blk = new Image(2, 2);		blk.src = "/images/black.gif";
brn = new Image(2, 2);		brn.src = "/images/brown.gif";
red = new Image(2, 2);		red.src = "/images/red.gif";
orn = new Image(2, 2);		orn.src = "/images/orange.gif";
yel = new Image(2, 2);		yel.src = "/images/yellow.gif";
grn = new Image(2, 2);		grn.src = "/images/green.gif";
blu = new Image(2, 2);		blu.src = "/images/blue.gif";
vio = new Image(2, 2);		vio.src = "/images/violet.gif";
gra = new Image(2, 2);		gra.src = "/images/grey.gif";
whi = new Image(2, 2);		whi.src = "/images/white.gif";

gold = new Image(2, 2);		gold.src = "/images/gold.gif";
silver = new Image(2, 2);	silver.src = "/images/silver.gif";

rbody = new Image(2, 2);	rbody.src = "/images/rbody.gif";
dbody = new Image(2, 2);	dbody.src = "/images/dbody.gif";

empty = new Image(2, 2);	empty.src = "/images/empty.gif";


var end_point = 0;
var const_stage = 0;

// Initialize the assembly procedure

function initialize() {
	if (end_point > 0) {
		for (i = 1; i < end_point; i++) {
			hide("step" + i);
			if (arrow[i]) {
				hide("arrow" + i);
			}
			if (stages[i] != "") {
				hide(stages[i]);
			}
			if (onoff[i] != "") {
				hide(onoff[i]);
			}
			if (onoff[i].substring(0,4) == "old_") {
				show(onoff[i]);
			}
		}
		hide("step" + end_point);
		if (arrow[end_point]) {
			hide("arrow" + end_point);
		}
		if (onoff[end_point] != "") {
			hide(onoff[end_point]);
		}
		show(first_part);
		hide("blank");
		hide("restart");
		show("step1");
		if (arrow[1]) {
			show("arrow1");
		}
		if (onoff[0] != "") {
			show(onoff[0]);
		}
		const_stage = 1;
	}
}


// Function to advance to the next item or stage.

function advance(stage) {
	if (const_stage == stage) {
		if (const_stage == 1) {
			show("restart");
		}
		var next_stage = stage + 1;
		const_stage++;
		hide("step" + stage);
		if (arrow[stage]) {
			hide("arrow" + stage);
		}
		if (onoff[stage] != "") {
			hide(onoff[stage]);
		}
		show("step" + next_stage);
		if (arrow[next_stage]) {
			show("arrow" + next_stage);
		}
		if (onoff[next_stage] != "") {
			show(onoff["" + next_stage]);
		}
		if (stages[stage] != "") {
			show(stages[stage]);
		}
		if (const_stage == end_point) {
			show("blank");
		}
	}
}


// Function to skip some assembly steps or go back

function skip_steps(new_stage) {
	hide("step" + const_stage);
	if (arrow[const_stage]) {
		hide("arrow" + const_stage);
	}
	if (onoff[const_stage] != "") {
		hide(onoff[const_stage]);
	}
	const_stage = new_stage - 1;
	advance(const_stage);
}

