//
// This creates hidden / reveal functionality for a set of given headers. 
// Content to be revealed for current header is assumed to be all HTML nodes until the next header is encountered
//
function initializeContentDropdown(tag, parentDiv) {
	var id = 0;
	if (!parentDiv) parentDiv = '.content-holder';
	jQuery(parentDiv).addClass('contentdropdown');
	jQuery(parentDiv).children().each(function(i) {
		if (id < 0) {
			return;
		} else if (this.tagName.toLowerCase() == 'hr') {
			id = -1;
			return;
		} else if (this.tagName.toLowerCase() == tag.toLowerCase()) {
			id++;
			this.id = 'content-'+id;
			jQuery(this).addClass('header').css('cursor', 'pointer');

			jQuery(this).click(function(event) {
				if (jQuery(this).hasClass('header-opened')) {
					jQuery(this).removeClass('header-opened');
					jQuery('.content-holder .'+this.id).each(function(i) { 
						if (!jQuery(this).hasClass('visible')) {
							jQuery(this).hide();
							jQuery(this).removeClass('opened');
						}
					});

				} else {
					jQuery(this).addClass('header-opened');
					jQuery('.content-holder .'+this.id).each(function(i) {
						if (!jQuery(this).hasClass('visible')) {
							jQuery(this).show();
							jQuery(this).addClass('opened');
						}
					});
				}
				return false;
			});
			
		} else if (id > 0) {
			jQuery(this).addClass('content-'+id);
			jQuery(this).addClass('content');
			if (!jQuery(this).hasClass('visible')) {
				jQuery(this).hide();
			}
		}
	});
}
