// Gate image overlays

jkf00000 = new Image(550, 275); jkf00000.src = "images/jkf00000.gif";
jkf00011 = new Image(550, 275); jkf00011.src = "images/jkf00011.gif";
jkf00100 = new Image(550, 275); jkf00100.src = "images/jkf00100.gif";
jkf00111 = new Image(550, 275); jkf00111.src = "images/jkf00111.gif";
jkf01000 = new Image(550, 275); jkf01000.src = "images/jkf01000.gif";
jkf01001 = new Image(550, 275); jkf01001.src = "images/jkf01001.gif";
jkf01010 = new Image(550, 275); jkf01010.src = "images/jkf01010.gif";
jkf01011 = new Image(550, 275); jkf01011.src = "images/jkf01011.gif";
jkf01100 = new Image(550, 275); jkf01100.src = "images/jkf01100.gif";
jkf01101 = new Image(550, 275); jkf01101.src = "images/jkf01101.gif";
jkf01110 = new Image(550, 275); jkf01110.src = "images/jkf01110.gif";
jkf10000 = new Image(550, 275); jkf10000.src = "images/jkf10000.gif";
jkf10011 = new Image(550, 275); jkf10011.src = "images/jkf10011.gif";
jkf10100 = new Image(550, 275); jkf10100.src = "images/jkf10100.gif";
jkf10111 = new Image(550, 275); jkf10111.src = "images/jkf10111.gif";
jkf11001 = new Image(550, 275); jkf11001.src = "images/jkf11001.gif";
jkf11010 = new Image(550, 275); jkf11010.src = "images/jkf11010.gif";
jkf11011 = new Image(550, 275); jkf11011.src = "images/jkf11011.gif";
jkf11101 = new Image(550, 275); jkf11101.src = "images/jkf11101.gif";
jkf11110 = new Image(550, 275); jkf11110.src = "images/jkf11110.gif";


// gate input values

var gatesIn = new Array(0);
gatesIn[0] = new Array(2);	// JK Edge-triggered flip-flop
gatesIn[0][0] = "0";
gatesIn[0][1] = "0";
gatesIn[0][2] = "0";

var gatesOut = new Array(0);	// JK Edge-triggered flip-flop
gatesOut[0] = new Array(1);
gatesOut[0][0] = "0";
gatesOut[0][1] = "0";

// gate names

var gateNames = new Array(0);
gateNames[0] = "jkf";


// Input and output counts

var gateInputs = new Array(0);
gateInputs[0] = 3;

var gateOutputs = new Array(0);
gateOutputs[0] = 2;


function findOutput(gateID, inputID) {
        myGate = gateID;
        myInput = inputID;
        // Determine output state for current inputs
        if (gatesIn[myGate][1] == "1") {
		if (gatesIn[myGate][2] == "1" && 
			gatesOut[myGate][1] == "1") {
			gatesOut[myGate][0] = "0";
		}
		if (gatesIn[myGate][0] == "1" &&
			gatesOut[myGate][1] == "0") {
			gatesOut[myGate][0] = "1";
		}
        } else {
                gatesOut[myGate][1] = gatesOut[myGate][0]
        }
}

