hierarchial state machine fpr javascript