	/* SETTINGS */
	
	//Create empty-vars
	var groupNames = new Array();
	var headingNames = new Array();
	var dispStatus2 = new Array();
	var g, notAllDisp, c, a, dispStatus, imgDisp, gHeight, expand, collapse, fVal;
	
	// Animation
	var ABS_MIN = 20;
	var FRAME_PX = 40;
	var FRAME_DELAY = 5;
	var MIN_GROUP_HEIGHT = "20px";
  
	/**
	 * Opens / Closes individual groups
	 * @param {String} gId Main div ID of group to be opened/closed
	 * @param {Integer} startHeight Height of collapsed group
	 */
function toggleGroup  (gId,startHeight) {
		g = document.getElementById(gId);
		ABS_MIN = startHeight;
		notAllDisp = false;
		c = 0;
		if (g.style.height == '') { g.style.height = MIN_GROUP_HEIGHT; }
	
		//if group is closed, open it (and set expand-image & collapse-text)
		if (g.style.height == ABS_MIN + 'px') {
			g.className += " groupSelected";
			_animateGroup(g,ABS_MIN,g.scrollHeight,FRAME_PX, frameFixHeight);
		}
		//if group is open, close it (and set collapse-image & expand-text)
		else {
			g.className = g.className.replace(" groupSelected","");
			_animateGroup(g,g.scrollHeight,ABS_MIN,-FRAME_PX, frameFixHeight);
		}
	
		//determine if all groups are closed
		for (a=0; a < groupNames.length; a++) {
			dispStatus = document.getElementById(groupNames[a]).style.height;
			if (dispStatus == '') { dispStatus = MIN_GROUP_HEIGHT; }
			if (dispStatus == MIN_GROUP_HEIGHT) { c++; }
		}
		//if not all are open, prep.for Collapse All img/txt
		if (c == 1 && g.style.height == MIN_GROUP_HEIGHT) { notAllDisp = false; setHeadings("closeToggle"); }
		//if all are open, prep.for Expand All img/txt
		else { notAllDisp = true; setHeadings("openToggle"); }
	}
	
	
	/**
	 * Opens/closes all groups
	 */
function  toggleAll (el_this, thenTrigger) {
		if (typeof(el_this) == 'function') {
			thenTrigger = el_this;
			el_this = null;
		}
		notAllDisp = false;
	
		//determine if all groups are closed
		for (a=0; a < groupNames.length; a++) {
			dispStatus = document.getElementById(groupNames[a]).style.height;
			if (dispStatus == '') { dispStatus = MIN_GROUP_HEIGHT; }
			if (dispStatus == MIN_GROUP_HEIGHT) {
				notAllDisp = true;
				break;
			}
		}

		//if all groups are closed, open all
		if (notAllDisp == true) {
			_openCloseGroups(groupNames,false,thenTrigger);
			// if (el_this) el_this.className="closeToggle";
			setHeadings("closeToggle");
		}
		//otherwise, close all (and then set Expand All img/txt)
		else {
			_openCloseGroups(groupNames,true,thenTrigger);
			// if (el_this) el_this.className="openToggle";
			setHeadings("openToggle");
		}
	}
	
function setHeadings(state) {
	for (var i = 0; i < headingNames.length; i++) {
		$(headingNames[i]).className=state;
	}
}

	/**
	 * Opens all groups
	 */
function openAll () {
		//open all (and then set Collapse All img/txt)
		_openCloseGroups(groupNames,false);
	}
	
	//
	/**
	 * Add group id-name to 'groupNames' array. Launched automatically on page load.
	 * @param {String} groupID "Container" name
	 */
function addGroup (groupID) {
		groupNames.push(groupID);
		}
function addHeading (headId) {
	headingNames.push(headId);
}
	
	/**
	 * Expand group
	 */
function expandCategory () {
		//split up the URI by the ? if-present
		var URIarg = location.search.substr(1).split('?').toString();
	
		//if uri includes argument, argument-name is valid and argument-value is not blank and is numeric, open the group specified in the URI-argument
		if (URIarg != "" && URIarg.split('=')[0] == "expandCategory" && URIarg.split('=')[1] != "" && !isNaN(URIarg.split('=')[1])) { eval('toggleGroup("accordionGroup_' + URIarg.split('=')[1] + '",' + parseInt(MIN_GROUP_HEIGHT) + ')'); }
		//otherwise, open default-group
		else { _toggleGroup1(); }
	}
	
	
	/* ########################### INTERNAL FUNCTIONS ########################### */
	
	/**
	 * Animate group
	 * @param {Object} g DIV being expanded/collapsed
	 * @param {Integer} minH Minimum height, initial height and current height of section
	 * @param {Integer} maxH Maximum height, height of the fully expanded section
	 * @param {Integer} delta Controls animation interval, set with FRAME_PX var
	 * @param {Function} thenTrigger Function to fire after animation, if any
	 */
	function _animateGroup(g,minH,maxH,delta,thenTrigger) {
		if (delta > 0) {
			//open the group
			if (minH <= maxH) {
				g.style.height = minH + "px";
				setTimeout(function() { _animateGroup(g,(minH+delta),maxH,delta,thenTrigger); }, FRAME_DELAY);
			}
			else {
				g.style.height = g.scrollHeight + "px";
				if (typeof thenTrigger == "function") { thenTrigger(); }
				return;
			}
		}
		else {
			//close the group
			if (minH >= ABS_MIN) {
				g.style.height = minH + "px";
				setTimeout(function() { _animateGroup(g,(minH+delta),maxH,delta,thenTrigger); }, FRAME_DELAY);
			}
			else {
				g.style.height = ABS_MIN + "px";
				if (typeof thenTrigger == "function") { thenTrigger(); }
				return;
			}
		}
	}
	
	// Open or Close Groups
	function _openCloseGroups(items,allOpened,thenTrigger) {
		var wasTriggered = false;
		
		//if all are Not open
		if (allOpened == false) {
			for (a=0; a < items.length; a++) {
				g = document.getElementById(items[a]);
				gHeight = document.getElementById(items[a]).style.height;
				if (gHeight == "") { gHeight = MIN_GROUP_HEIGHT; }
				if (gHeight == MIN_GROUP_HEIGHT) {
					g.className += " groupSelected";
					_animateGroup(g,parseInt(MIN_GROUP_HEIGHT),g.scrollHeight,FRAME_PX,thenTrigger);
					wasTriggered=true
				}
			}
		}
		//if all are open
		else {
			for (a=0; a < items.length; a++) {
				g = document.getElementById(items[a]);
				gHeight = document.getElementById(items[a]).style.height;
				if (parseInt(gHeight) > parseInt(MIN_GROUP_HEIGHT)) {
					g.className = g.className.replace(" groupSelected","");
					_animateGroup(g,g.scrollHeight,parseInt(MIN_GROUP_HEIGHT),-FRAME_PX,thenTrigger);
					wasTriggered=true;
				}
			}
		}
		if (!wasTriggered && typeof thenTrigger == "function") { thenTrigger(); }
	}
	
	// Group1 Accordion-activator
	function _toggleGroup1() {
		toggleGroup('accordionGroup_1',parseInt(MIN_GROUP_HEIGHT));
	}



