function toggle_project_details() {
  button = $('expand_project_button').childNodes[0];
	if(button.src.match(/expand/)) {	// we're expanding the details
		button.src='/images/interview_collapse_project.png';
		$('project_details').style.display = 'block'
		if(  !$('project_name').hasClassName('show_bold')  ) {
			$('project_name').className='show_bold';
			$('project_client').className='show';
			renderSIFR();
		}
	} else {  // we're contracting/hiding the details
		button.src='/images/interview_expand_project.png';
		Effect.Fade('project_details', { transition: Effect.Transitions.sinoidal, duration: 0.1 });
	}
}


function show_box(section) {
	tabs_to_unselect = $('box_tabs').childNodes;
	divs_to_hide = $('tabbed_box').childNodes;
	
	for(i=0; i<tabs_to_unselect.length; i++) {
		if (tabs_to_unselect[i].nodeType == 1) { //an "Element" node
//			tabs_to_unselect[i].setAttribute('class', 'unselected');
			tabs_to_unselect[i].className = 'unselected';
                }
        }
	
	
	for(i=0; i<divs_to_hide.length; i++) {
		if (divs_to_hide[i].nodeType == 1) { //an "Element" node
			divs_to_hide[i].style.display = 'none';
		}
	}

	preselected_tab = $('current_tab');
	if (preselected_tab != null) {
		preselected_tab.value = section;
	}
	tab = $('tab_'+section);
	if (tab != null) {
//		tab.setAttribute('class','selected');
		tab.className = 'selected';
	}

	condiment = $('content_'+section);
	if (condiment != null) {
		condiment.style.display='block';
	}

}

function recursive_checkbox_click(node) {
	boxes = node.parentNode.parentNode.getElementsByTagName('input');
	for(var i=0; i<boxes.length; i++) 
		boxes[i].checked = node.checked;
}

function aggregate_table_output(node) {
  boxes = node.parentNode.parentNode.getElementsByTagName('input');
  output = boxes[1].value + "~";
  for(var i = 2; i < boxes.length; i++)
  {
    output += boxes[i].value;
    if((i-1)%3 == 0) {
      output += "~";
    } else {
      output += ";";
    }
  }
  boxes[0].value = output;
}

function remove_table_row(node) {
  aggregator=node.parentNode.parentNode.getElementsByTagName('input')[1];
  node.parentNode.parentNode.removeChild(node.parentNode)
  aggregate_table_output(aggregator);
}

function aggregate_chart_output(node) {
  boxes = node.parentNode.parentNode.getElementsByTagName('input');
  output = boxes[1].value + "~";
  for(var i = 2; i < boxes.length; i++)
  {
    output += boxes[i].value;
    if((i-1)%2 == 0) {
      output += "~";
    } else {
      output += ";";
    }
  }
  boxes[0].value = output;
}

function remove_chart_row(node) {
  aggregator=node.parentNode.parentNode.getElementsByTagName('input')[1];
  node.parentNode.parentNode.removeChild(node.parentNode)
  aggregate_chart_output(aggregator);
}

function select_tab(tab_name) {
  tabs_to_hide = $(tab_name).parentNode.childNodes;
  
  unselect_array(tabs_to_hide);
  
  select_element($(tab_name))
}

function show_employee(employee_num) {
  images_to_hide = $('employee_pics').childNodes;
  details_to_hide = $('employee_details').childNodes;
  links_to_unselect = $('employee_links').childNodes;
  
  hide_array(images_to_hide);
  hide_array(details_to_hide);
  unselect_array(links_to_unselect);
  
  show_element('employee_' + employee_num + '_pic');
  show_element('employee_' + employee_num + '_details');
  select_element('employee_' + employee_num + '_link');
  $('employee_'+employee_num+'_name').addClassName('show');
  $('employee_'+employee_num+'_tagline').addClassName('show');
}

function get_next_image() {
  src_list=$('project-thumbnails').getElementsByTagName("span");
  // NOTE: if at end of list, loop back to beginning of image list
  for(i=0; i<src_list.length; i++) {
    if(src_list[i].className=='active') {
      //Adjust new index so images loop
      new_index = (i + 1)%src_list.length;
      src_list[i].className="";
      src_list[new_index].className="active"
      $('image-holder').innerHTML = src_list[new_index].innerHTML
      break;
    }
  }
}

function get_prev_image() {
  src_list=$('project-thumbnails').getElementsByTagName("span");
  // NOTE: if at beginning of list, loop to end of image list
  for(i=0; i<src_list.length; i++) {
    if(src_list[i].className=='active') {
      //Adjust new index so images loop
      new_index = (i + src_list.length - 1)%src_list.length;
      src_list[i].className="";
      src_list[new_index].className="active"
      $('image-holder').innerHTML = src_list[new_index].innerHTML
      break;
    }
  }
}

// Helper functions

function hide_array(arr) {
  for(i=0; i<arr.length; i++) {
		if (arr[i].nodeType == 1) { //an "Element" node
			arr[i].style.display = 'none';
		}
	}
}

function unselect_array(arr) {
  for(i=0; i<arr.length; i++) {
		if (arr[i].nodeType == 1) { //an "Element" node
			arr[i].className = 'unselected';
    }
  }
}

function show_element(elem_name) {
  elem = $(elem_name)
  if(elem != null) {
    elem.style.display = 'block';
  }
}

function select_element(elem_name) {
  elem = $(elem_name)
  if(elem != null) {
    elem.className = 'selected';
  }
}

function set_active(elem_list, elem_name) {
  for(i=0; i<elem_list.length; i++) {
		if (elem_list[i].nodeType == 1) { //an "Element" node
			elem_list[i].className = '';
		}
	}
	
	elem = $(elem_name)
  if(elem != null) {
    elem.className = 'active';
  }
}

function renderSIFR() {
  if(typeof sIFR == "function"){
    //Intro page & Title Pages
  	sIFR.replaceElement(named({sSelector:"body h1.grey", sFlashSrc:"/dinpro_medium.swf", sColor:"#737373", sBgColor:"#4D4D4D", sWmode:"transparent"}));
  	sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"/dinpro_medium.swf", sColor:"#FFFFFF", sBgColor:"#4D4D4D", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body div.proj_num h2", sFlashSrc:"/dinpro_medium.swf", sColor:"#AFAFB0", sBgColor:"#4D4D4D", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body div.proj_date h2", sFlashSrc:"/dinpro_mediumitalic.swf", sColor:"#AFAFB0", sBgColor:"#4D4D4D", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body div.proj_title h2", sFlashSrc:"/dinpro_medium.swf", sColor:"#FFFFFF", sBgColor:"#4D4D4D", sWmode:"transparent"}));
    
    sIFR.replaceElement(named({sSelector:"body .outline_spacer h3", sFlashSrc:"/dinpro_bold.swf", sColor:"#FFFFFF", sBgColor:"#FFFFFF", sWmode:"transparent"}));
  
    sIFR.replaceElement(named({sSelector:"body .lightbox h3", sFlashSrc:"/dinpro_medium.swf", sColor:"#5F6062", sBgColor:"#FFFFFF", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body .lightbox h4", sFlashSrc:"/dinpro_mediumitalic.swf", sColor:"#999999", sBgColor:"#FFFFFF", sWmode:"transparent"}));
  
    sIFR.replaceElement(named({sSelector:"body .whitebox h3", sFlashSrc:"/dinpro_medium.swf", sColor:"#5F6062", sBgColor:"#FFFFFF", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body .whitebox h4", sFlashSrc:"/dinpro_mediumitalic.swf", sColor:"#999999", sBgColor:"#FFFFFF", sWmode:"transparent"}));
  
    sIFR.replaceElement(named({sSelector:"body h3", sFlashSrc:"/dinpro_medium.swf", sColor:"#FFFFFF", sBgColor:"#4D4D4D", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body h4", sFlashSrc:"/dinpro_mediumitalic.swf", sColor:"#AFAFB0", sBgColor:"#4D4D4D", sWmode:"transparent"}));
    
    sIFR.replaceElement(named({sSelector:"body h5.show", sFlashSrc:"/dinpro_medium.swf", sColor:"#5F6062", sBgColor:"#FFFFFF", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body h6.show_bold", sFlashSrc:"/dinpro_bold.swf", sColor:"#5F6062", sBgColor:"#FFFFFF", sWmode:"transparent"}));
    sIFR.replaceElement(named({sSelector:"body h6.show", sFlashSrc:"/dinpro_mediumitalic.swf", sColor:"#999999", sBgColor:"#FFFFFF", sWmode:"transparent"}));
  
  }
}
