// set up the accumulators
var m_accum, d_accum, c_accum, l_accum, x_accum, v_accum, i_accum;
var active_key = {
    m : true,
    d : true,
    c : true,
    l : true,
    x : true,
    v : true,
    i : true,
};
var key_opacity = {
    m : 1.0,
    d : 1.0,
    c : 1.0,
    l : 1.0,
    x : 1.0,
    v : 1.0,
    i : 1.0,
};
var roman_array = ['m', 'd', 'c', 'l', 'x', 'v', 'i'];
var last_char = '',
    prev_char = '',
    last_2_chars = '';

$.lbl_display.text = '';

function lastPressed(char_entered) {
    // keep track of last two characters entered
    prev_char = last_char;
    last_char = char_entered;
    // combine these to faciltate switch in dimChars()
    last_2_chars = prev_char + last_char;
    // chain to function that enables/disables number keys
    dimChars(prev_char, last_char);
}
function numPress(e) {
//    Ti.API.info('e info is: '+JSON.stringify(e));
    // add value of key pressed to end of display
    $.lbl_display.text = $.lbl_display.text + e.source.text;
    // send last character entered to function keeping track
    lastPressed(e.source.text);
//    Ti.API.info('$.lbl_display.text: '+$.lbl_display.text);
    Ti.API.info('e.source.text: '+e.source.text);
}
function addPress(e) {
    // remove number from display
    clearDisplay();
}
function totalPress(e) {
    // remove number from display
    clearDisplay();
}
function clearDisplay() {
    // set the display to empty string
    $.lbl_display.text = '';
    // reset the characters pressed variables to empty string
    prev_char = '';
    last_char = '';
    last_2_chars = '';
    dimChars(null);
}
function deleteLeft() {
    // use slice method to remove last character of display
    var displayText =  $.lbl_display.text;
    var charCount = displayText.length;
    $.lbl_display.text = displayText.slice(0, -1);
    // reset the characters pressed variables to earlier characters
    // this allows backspace to be pressed several times without throwing off logic
    last_char = displayText.charAt(charCount-2);
    prev_char = displayText.charAt(charCount-3);
    last_2_chars = prev_char + last_char;
}
function dimChars(last, prev) {
    if (last == null) {
        roman_array.forEach(setActive);
    } else {
        switch (last_char) {
            case M:
                if (prev_char == 'C') {
                    ['M','D','C'].forEach(setInactive);
                [break;]

    }
}
function setActive(element, index, array) {
    active_key.element = true;
    key_opacity.element = 1.0;
}
function setInactive(element, index, array) {
    active_key.element = false;
    key_opacity.element = 0.6;
}
$.lbl_m.addEventListener(pressNum($.))
$.index.open();

@@ -91,22 +91,22 @@
 um;%0A
+%0A
 var 
-active_key
+key_state
  = %7B
@@ -118,215 +118,410 @@
 m : 
-true,%0A    d : true,%0A    c : true,%0A    l : true
+ %7B active: true, opacity: 1.0, label: '$.lbl_m' %7D,%0A    d : %7B active: true, opacity: 1.0, label: '$.lbl_d' %7D,%0A    c : %7B active: true, opacity: 1.0, label: '$.lbl_c' %7D
 ,%0A    
-x : true,%0A    v : true
+l : %7B active: true, opacity: 1.0, label: '$.lbl_l' %7D
 ,%0A    
-i : true,%0A%7D;%0Avar key_opacity = %7B%0A    m : 1.0,%0A    d : 1.0
+x : %7B active: true, opacity: 1.0, label: '$.lbl_x' %7D
 ,%0A    
-c : 1.0,%0A    l : 1.0,%0A    x : 1.0,%0A    v : 1.0,%0A    i : 1.0
+v : %7B active: true, opacity: 1.0, label: '$.lbl_v' %7D,%0A    i :%7B active: true, opacity: 1.0, label: '$.lbl_i' %7D
 ,%0A%7D;%0A
+%0A
 var 
@@ -2640,34 +2640,33 @@
 ) %7B%0A    
-active_key
+key_state
 .element
  = true;
@@ -2657,16 +2657,23 @@
 .element
+.active
  = true;
@@ -2681,31 +2681,29 @@
     key_
-opacity
+state
 .element
  = 1.0;%0A
@@ -2694,16 +2694,24 @@
 .element
+.opacity
  = 1.0;%0A
@@ -2766,26 +2766,25 @@
     
-active_key
+key_state
 .element
  = f
@@ -2779,16 +2779,23 @@
 .element
+.active
  = false
@@ -2808,23 +2808,21 @@
 key_
-opacity
+state
 .element
  = 0
@@ -2817,16 +2817,24 @@
 .element
+.opacity
  = 0.6;%0A
@@ -2872,13 +2872,10 @@
 sNum
-($.)
 )
+;
 %0A$.i

use array of objects to keep button info