function toggleItem(targetID, target2ID) {
	if (document.getElementById) {
		target = document.getElementById(targetID);
		target2 = document.getElementById(target2ID);
		if (target.style.display == "none") {
			target.style.display = "";
			target2.style.backgroundImage = "url('../images/triangle-open.gif')";
		} else {
			target.style.display = "none";
			target2.style.backgroundImage = "url('../images/triangle-close.gif')";
		}
	}
}

function setupURLJumperSelect() {
	// get all select elements with the class 'url_jump_select'
	var selects = getElementsByClass('url_jump_select', document, 'SELECT');
	// loop through, add event on change
	for (var i = 0; i < selects.length; i++) {
		selectElement = selects[i];
		// attach onclick function
		addEvent(selectElement, 'change', urlJumpSelect, false);
	}	
}

function urlJumpSelect(e) {
	// find the target
	var target = findTarget(e);
	var path = target.value;
	if (path.length > 0) {
		document.location.href = path;
	}
}

function setUpRadiosAndCheckboxes() {
	// get all select elements with the class 'url_jump_select'
	var inputs = document.getElementsByTagName('INPUT');
	// loop through, add class 'radio' if they are a radio or checkbox
	for (var i = 0; i < inputs.length; i++) {
		inputElement = inputs[i];
		if (inputElement.getAttribute('type') == 'checkbox' || inputElement.getAttribute('type') == 'radio') {
			// add class
			inputElement.className += ' radio';
		}
	}	
}

function toggleList(e) {
	
	// get a reference to the anchor and it's parentNode (the <li> element)
	if (window.event) {
		// IE does it differently... stores the event in a window.event object
		var thisA = window.event.srcElement;
		//alert(thisA);
		var thisLI = thisA.parentNode;
	} else {
		var thisA = this;
		var thisLI = this.parentNode;
	}
	// if this li has nested ul elements...
	if (thisLI.getElementsByTagName('ul').length > 0) {
		
		var toggleListTarget = thisLI.getElementsByTagName('ul')[0];
		//...toggle visibility of first ul
		if (toggleListTarget.style.display != 'none' ) {
			toggleListTarget.style.display = 'none';
			//thisA.style.color = '';
			thisA.style.backgroundImage = 'url(../images/arrowright.gif)';
			//closeListArrow();
		} else {
			toggleListTarget.style.display = '';
			//thisA.style.color = 'white';
			thisA.style.backgroundImage = 'url(../images/arrowdown.gif)';
			//expandListArrow();
		}
		// cancel bubble and href of this anchor
		cancelClick(e);
		// hack for Safari (stops browser following href link)
		thisA.onclick = function() { return false; }
	}
}

function setUpCollapsingList() {

	// find the toggle list
	var lists = getElementsByClass('collapsible_list', document, 'ul');
	
	for (var x = 0; x < lists.length; x++) {
		//list = document.getElementById('collapsingList');
		list = lists[x];
		// find all it's child UL elements
		var childLists = list.getElementsByTagName('ul');
		// hide them all
		for (var i = 0; i < childLists.length; i++) {
			var childList = childLists[i];
			childList.style.display = 'none';
		}
		
		// attach toggleList function to onclick of each anchor
		var childAnchors = list.getElementsByTagName('a');
		// hide them all
		for (var i = 0; i < childAnchors.length; i++) {
			var childAnchor = childAnchors[i];
			// attach toggleList function to onclick of each anchor
			addEvent(childAnchor, 'click', toggleList, false);
		}
	}
}

function resetContent() {

	showAboutContent('main');
	
	/*
	// un-highlight all other thumbs, except active one
	var thumbs = ['about_thumb_design', 'about_thumb_science', 'about_thumb_consumer', 'about_thumb_business'];
	
	for (var i = 0; i < thumbs.length; i++) {
		var temp_thumb = thumbs[i];
		document.getElementById(temp_thumb).style.backgroundPosition = '0 141px';
	}
	*/
}

function showAboutContent(cat) {

	// hide all content boxes, except active one
	var content_boxes = ['about_design', 'about_science', 'about_consumer', 'about_business', 'about_main'];
	var active_content_box = 'about_' + cat;
	
	for (var i = 0; i < content_boxes.length; i++) {
		var temp_content_box = content_boxes[i];
		if (temp_content_box == active_content_box) {
			document.getElementById(temp_content_box).style.display = '';
		} else {
			document.getElementById(temp_content_box).style.display = 'none';
		}
	}
	
	// un-highlight all other thumbs, except active one
	var thumbs = ['design', 'science', 'consumer', 'business'];
	var active_thumb = 'about_thumb_' + cat;
	
	for (var i = 0; i < thumbs.length; i++) {
		var temp_thumb = thumbs[i];
		var thumb = 'about_thumb_' + temp_thumb;
		if (cat !== 'main') {
			if (temp_thumb == cat) {
				document.getElementById(thumb).style.backgroundImage = 'url(../images/about/' + temp_thumb + '-on.jpg)';
			} else {
				document.getElementById(thumb).style.backgroundImage = 'url(../images/about/' + temp_thumb + '-off.jpg)';
			}
		} else {
			document.getElementById(thumb).style.backgroundImage = 'url(../images/about/' + temp_thumb + '-on.jpg)';
		}
	}
	
}

function preloadApproachImages() {

	if (document.getElementById('about_thumb_design')) {
	
		pic1 = new Image(121, 141); 
  		pic1.src = "../images/about/design-on.jpg";
  		
  		pic2 = new Image(121, 141); 
  		pic2.src = "../images/about/science-on.jpg";
  		
  		pic3 = new Image(121, 141); 
  		pic3.src = "../images/about/consumer-on.jpg";
  		
  		pic4 = new Image(121, 141); 
  		pic4.src = "../images/about/business-on.jpg";
	}
}

function hilite(id) {
	var titleElementID = 'title_' + id;
	if (document.getElementById(titleElementID)) {
		document.getElementById(titleElementID).style.borderColor = '#000';
		document.getElementById(titleElementID).style.color = '#000';
	}
	var thumbElementID = 'thumb_' + id;
	if (document.getElementById(thumbElementID)) {
		document.getElementById(thumbElementID).style.borderColor = '#000';
		document.getElementById(thumbElementID).style.color = '#000';
	}
}
function unhilite(id) {
	var titleElementID = 'title_' + id;
	if (document.getElementById(titleElementID)) {
		document.getElementById(titleElementID).style.borderColor = '#018E8E';
		document.getElementById(titleElementID).style.color = '#018E8E';
	}
	var thumbElementID = 'thumb_' + id;
	if (document.getElementById(thumbElementID)) {
		document.getElementById(thumbElementID).style.borderColor = '#018E8E';
		document.getElementById(thumbElementID).style.color = '#018E8E';
	}
}

addLoadEvent(setupURLJumperSelect);
addLoadEvent(setUpRadiosAndCheckboxes);
addLoadEvent(preloadApproachImages);
addLoadEvent(setUpCollapsingList);