var ajaxedSections = new Array();
var myAjaxSections = new Array();

function ajaxShowSection(section) {
	itemDisplay('show-ajax-section-' + section, 'none');
	if ( ajaxedSections[section] ) {
		ajaxDisplaySectionWhenLoaded(section);
		return;
	} else {
		myAjaxSections[section] = new fx.Height('ajax-section-' + section, {duration: 600});
		myAjaxSections[section].toggle('height');
		document.getElementById('ajax-section-' + section + '-notice').innerHTML = '<p><img src="http://www.outsidethebeltway.com/wordpress/wp-content/themes/otb2007/working.gif" alt="loading" /> Loading...</p>';
		ajaxedSections[section] = new ajax('http://www.outsidethebeltway.com/wordpress/wp-content/themes/otb2007/ajax-sections.php', {postBody: 'section=' + section, update: $('ajax-section-' + section), onComplete: ajaxSectionWaitForHide(section)});
	}
}

function ajaxSectionWaitForHide(section) {
	setTimeout("ajaxDisplaySectionWhenLoaded('" + section + "')", 650);
}

function ajaxHideSection(section) {
	setTimeout("itemDisplay('show-ajax-section-" + section + "', 'inline')", 600);
	itemDisplay('hide-ajax-section-' + section, 'none');
	myAjaxSections[section].toggle('height');
}

function itemDisplay(item, display) {
	document.getElementById(item).style.display = display;
}

function ajaxDisplaySectionWhenLoaded(section) {

	if ( document.getElementById('ajax-section-' + section).innerHTML.indexOf('<!-- ajax loaded -->') < 0 ) {
		setTimeout("ajaxDisplaySectionWhenLoaded('" + section + "')", 10);
		return;
	} else {
		setTimeout("myAjaxSections['" + section + "'].toggle('height')", 180);
		document.getElementById('ajax-section-' + section + '-notice').innerHTML = '';
		setTimeout("itemDisplay('hide-ajax-section-" + section + "', 'inline')", 700);
	}
}

