function ControlPanel_test(){
        alert ("controller functioning:");
    }

/*control_panel.html contains html elements which call functions here which set values.
These values control the logic of the dispatcher function which determines whether and how
to execute the make page function which creates a different page for each value of the 
increment counter i. The functions here are common to all pages. The last statement of make page
calls make current page which handles values specific to the calling page.*/

/*variables*/
var speed = [60000,20000,2500,1000,500];
var speed_name = ["minimum","slow","normal","fast","maximum"];
var rate_name = ["60 secs/picture","20 secs/picture","2.5 secs/picture","1 sec/picture",".5 sec/picture"];
var speed_index = 2;
var lo_limit = 0;
var hi_limit = 4;
var delay = speed[speed_index];
var auto_page_flag = "";
var started = "no";
var auto_state = "running";
var message = {
	"e_mid_top_pic":"Send a nice message",
	"e_mid_bottom_pic":"Send a neutral message",
	"w_mid_top_pic":"Send a critical message",
	"w_mid_bottom_pic":"Send a venomously vituperative screed",
	"s_mid_left_pic":"pause",
	"s_mid_right_pic":"resume"
    }
var cp_message_id = "e_mid_top_message";//nice is the default
var picture_number = i+1;//this goes last because i set by caller
var timeout_flag = "";
var control_panel_vars = "finished!";
var dialog = new Array();

function gem_call(color){
    switch(color){
    case 'green':
    window.location = "/feedback.php?color=green&page="+current_page;
    break;
    case 'red':
    window.location = "/feedback.php?color=red&page="+current_page;
    break;
    case 'yellow':
    window.location = "/feedback.php?color=yellow&page="+current_page;
    break;
    case 'blue':
    window.location = "/feedback.php?color=blue&page="+current_page;
    break;
    default:
    alert ("feedback but not a good color!");
    break;
    }
}

function page_p_m(rate){
  if ( rate == "slower" && speed_index > lo_limit || rate == "faster" && speed_index < hi_limit ){
     if (rate == "slower"){
        speed_index--;
     }
     else if (rate == "faster"){
        speed_index++;
     }
     delay = speed[speed_index];
     set_speed_control_readout();
     if (auto_state != "paused"){
     dispatcher();
     }
  }
}//function

function set_speed_control_readout(){//_l1 shows pace _l2 sets pace
   if (auto_state != "paused"){  //don't update _l1 when paused
      var newNode = document.createTextNode("speed:"+speed_name[speed_index]);
      var oldNode = document.getElementById("speed_control_readout_l1").firstChild;
      var removedNode = document.getElementById("speed_control_readout_l1").replaceChild(newNode,oldNode);
   }
   var newNode2 = document.createTextNode(rate_name[speed_index]);
   var oldNode2 = document.getElementById("speed_control_readout_l2").firstChild;
   var removedNode2 = document.getElementById("speed_control_readout_l2").replaceChild(newNode2,oldNode2);
}


function dispatcher(direction){//dispatcher exists to repetitively make the page
     if ( i < 0 || i > last_page){
      mode = "skip";
    }
     started = "yes";
    if(timeout_flag){
      clearTimeout(timeout_flag);
    }
    var enabled = "no";//if no case enables, do nothing
    switch(mode){
    case 'skip':
	break;
    case 'auto'://auto will replay dispatcher in delay seconds TIMER SET HERE
       if (auto_state == "paused") break;//unless we're paused
        enabled = "yes";
       if (current_panel.speed_control.state == "on"){//delay is set by speed control
          timeout_flag = setTimeout(dispatcher,delay);
       }
       else if (current_panel.speed_control.state == "stop_go"){//delay set by pace[] on page
          timeout_flag = setTimeout(dispatcher,pace[i]);
       }
       if (first_time == "yes"){//we want to see the 0 page
	   first_time = "no";
           break;
       }
       i++;
       break;
    case 'manual':
       if (direction == "more" && i != last_page) i++;
       else if (direction == "less" && i != 0) i--;
       else break;
       enabled = "yes";
    }
    if (enabled == "yes"){//verify that all tests met
	make_page();
    }
}//dispatcher function

function set_i(choice){//fix this
    i = choice;
    make_page();
}

function Box(state,type,text,link){
    this.state = state;//"on,"not_on",not_set
    this.type = type;//"date","text","pic",not_set
    this.text = text;//string,not_set
    this.link = link;//link,"not_on"
}

//create a control panel object for calling page
function Control_Panel(north,east,south,west,short_message,speed_control){
    this.north = north;
    this.east = east;
    this.south = south;
    this.west = west;
    this.speed_control = speed_control;
}//end control_panel

function audio_ready(){
    CurrentDialog = NextDialog;
    waiting_flag = setInterval(waiting,250);
    function waiting(){
      if (CurrentDialog.done()=="yes"){
	  clearInterval(waiting_flag);
          make_page();
       }
    }
}

function make_page(){
   if (i <= last_pic){
       if(dialog.length !== 0){
          speak(sound_directory+dialog[i]);
       }
      picture_number = i+1;
      var newNode = document.createTextNode( "page:"+picture_number);
      var oldNode = document.getElementById("s_mid_mid").firstChild;
      var removedNode = document.getElementById("s_mid_mid").replaceChild(newNode,oldNode);
      if (document.my_picture){//safari chokes on document.my_picture ff chokes on window.my_picture
         document.my_picture.setAttribute("src",picdirectory+pictures[i]);
      }
      else{
         window.my_picture.setAttribute("src",picdirectory+pictures[i]);
      }
      make_current_page();//set page specific stuff
   }
   else {//we have a separate end page
       if (end_page){
       window.location = end_page;
       }
   }//outer if/else
}//function

//load browser specfic library
function load_browser_lib(){
    var current_library = document.createElement('script');
    current_library.type="text/javascript";
    if(current_browser == "Standard"){
	current_library.src= root_dir+"js/Standard/Cpanel.js";
    }
    else{
	current_library.src= root_dir+"js/IE/Cpanel.js";
    }
   document.getElementsByTagName("head")[0].appendChild(current_library);
}
