// Copyright (C) 2008 Robert W. Clarke Consulting, all rights reserved.// do not remove this copyright noticefunction updateLegend(data_type){ // called from pull down menu on control panel	// this function updates the legend below the map according to data type	var legend_div = document.getElementById('legend_div');	legend_div.innerHTML = ary_legend[data_type]; // tpop or dpop	if(system_init){		sendXML(ary_frames[current_frame][data_type]);	}}var interval_run;var run_pause = "pause";function setControl(directive){	var run_pause_btn = document.getElementById("btn_runpause");	var form_obj = document.forms.control_form;		switch(directive){		case "toggle":			if(run_pause == "pause"){ 				run_pause = "run";				var int_rate = getSelectedRadioValue(form_obj.rate)				interval_run = setInterval('runSequence(1)', int_rate);				run_pause_btn.src="btn_pause.gif";			} else { // pause				run_pause = "pause"; 				clearInterval(interval_run);				run_pause_btn.src="btn_run.gif";			}		break;				case "run":			run_pause = "run";			var int_rate = getSelectedRadioValue(form_obj.rate)			interval_run = setInterval('runSequence(1)', int_rate);			run_pause_btn.src="btn_pause.gif";		break;				case "pause":			clearInterval(interval_run);			run_pause = "pause"; 			run_pause_btn.src="btn_run.gif";		break;				case "leftstop":			clearInterval(interval_run);			run_pause = "pause"; 			run_pause_btn.src="btn_run.gif";			runSequence(0);		break;				case "rightstop":			clearInterval(interval_run);			run_pause = "pause"; 			run_pause_btn.src="btn_run.gif";			runSequence(ary_frames.length-1);		break;				case "prev":			clearInterval(interval_run);			run_pause = "pause"; 			run_pause_btn.src="btn_run.gif";			runSequence(-1);		break;				case "next":			clearInterval(interval_run);			run_pause = "pause"; 			run_pause_btn.src="btn_run.gif";			runSequence(1);		break;			}	}var current_frame = 0;function runSequence(direction){ // called when page loads, by control panel buttons, or interval	if(direction == 0){ // go to beginning		current_frame = 0;	} else { // backwards or forwards		current_frame += direction;		if(direction > 0){			if(current_frame >= ary_frames.length){ // reached end				current_frame = ary_frames.length -1;				if(document.forms.control_form.loop.checked){ // loop enabled, start over					if(run_pause == "run"){ // only if auto-play frames						current_frame = 0;					}				} else { // don't loop					clearInterval(interval_run);					run_pause = "pause";					var run_pause_btn = document.getElementById("btn_runpause");					run_pause_btn.src="btn_run.gif";				}			}		}		if(direction < 0){			if(current_frame <= 0){				current_frame = 0;			}		}	}	var dtype = getSelectedRadioValue(document.forms.control_form.dtype);	sendXML(ary_frames[current_frame][dtype]); // sends current frame xml to map	updateStateData(current_frame);}function getSelectedRadioValue(radio_obj){	var i;	for(i=0;i<radio_obj.length;i++){		if(radio_obj[i].checked){			return radio_obj[i].value;		}	}}function updateStateData(frame){ // called from runSequence()	// this function updates the state data in the control panel box	// txt_obj = document.forms.control_form.statedata;	var year = ary_years[frame];	var tpop, dpop, prev_year,state_info;	if(selected_state_id == null){ // no state clicked on (initial value)		state_info = "Click on state\nto show data here";	} else {		tpop = ary_popdat[selected_state_id][year];		state_info = selected_state_id + ' - ' + ary_state[selected_state_id] + "\n";		state_info += "Year: " + year + "\n";		state_info += "Pop: " + formaThousands(tpop) + "\n";		if(frame > 0){			prev_year = ary_years[frame-1]			dpop = ary_popdat[selected_state_id][year]-ary_popdat[selected_state_id][prev_year];			dpop_percent = dpop/ary_popdat[selected_state_id][prev_year] * 100;			state_info += "Change: " + formaThousands(dpop) + "\n";			state_info += "Change: " + dpop_percent.toFixed(1) + "%";		}	}	// txt_obj.value = state_info;	document.getElementById("statedata_div").innerHTML = nlToBR(state_info);}var selected_state_id = "AL";function selectState(state_id){ // called from the map when user clicks on state	selected_state_id = state_id;	updateStateData(current_frame);}function nlToBR(str){	var re = /\n/g;	return str.replace(re,'<br />');}