// JavaScript Document
$id = function (el) {
	return document.getElementById(el);	
}
$tn = function (el) {
	return document.getElementsByTagName(el);	
}
var toggleAccords = function(el) {
	
	if (typeof oldNum == 'undefined') { // if not yet defined
			oldNum = -1;
	}
	for ( i=0; i< divArray.length; i++ ) { // cycle through the array to close the open ones
		if ( divArray[i] == el.parentNode ) { // if the el element (from the this keyword in the funcs) is the same as the div[i] element - then that's the one we're openning
			var num = i; // keep track of which one to open
		} else {
			// set classname to none
			divArray[i].getElementsByTagName('h2')[0].className = 'plus';
			
			$(divArray[i].getElementsByTagName('div')[0]).animate(
			{
				height: 0   // close all other divs
			}, 1000);
		} // end if else animate
	}
	
	if ( oldNum == num && divArray[num].getElementsByTagName('div')[0].style.height != '0px' ) { // if this num is the same as the last one openned then close this one too - second click
		// set classname to none
		divArray[num].getElementsByTagName('h2')[0].className = 'plus';
		$(divArray[num].getElementsByTagName('div')[0]).animate( 
		{
			height: 0
		}, 1000);
		oldNum = num;
	} else { 
		oldNum = num;
		// set classname to none
		divArray[num].getElementsByTagName('h2')[0].className = 'minus';
		$(divArray[num].getElementsByTagName('div')[0]).animate( 
		{
			height: offHt[num]
		}, 1000);
		
	}
	
}
var divArray = Array();
var offHt = Array();
$(document).ready(function()
{
	// add a function to open or close the sibling with the correct classname
	divArray = $('.section_container');
	var i=0;
	while( divArray[i] ) {
		
		$(divArray[i].getElementsByTagName('h2')[0]).bind('click', function()
			{
				toggleAccords(this) 
			});
		var holdHt = divArray[i].getElementsByTagName('div')[0].offsetHeight;
		offHt.push(holdHt);
		divArray[i].getElementsByTagName('div')[0].style.height = '0px';
		i++;
	}

});

