var currentExpandedSection = 'welcome';

function collapse(section) {
	document.getElementById(section).style.display = 'none';
}

function expand(section) {
	document.getElementById(section).style.display = 'block';
}

function clickLink(newSection) {
	if (currentExpandedSection != newSection) {
		collapse(currentExpandedSection);
		expand(newSection);
		currentExpandedSection = newSection;
		setCookie('conf'+conferencePage, newSection, 3600, '/');
	}
}

function getCookie(name) {
	var dc = document.cookie;
	
	//Get the position of the start of this cookie
	var startPos = dc.indexOf(name + "=");
	if (startPos == -1) {
		//Cookie doesn't exist
		return null;
	}
	
	//Then find an "=" after the start of the cookie that indicates the start
	// of this cookie's value
	var valuePos = dc.indexOf('=', startPos) + 1;
	
	//And then find the end of the cookie's value (after the start of the value)
	var endPos = dc.indexOf(';', valuePos);
	if (endPos == -1) {
		//No ; found, so assume it goes to the end of the cookie string
		endPos = dc.length;
	}
	
	//Extract the required part of the cookie string and return it
	return unescape(dc.substring(valuePos, endPos));
}

function setCookie(name, value, durationInSecs, path) {
	if (!path) path = '/';
	var expiryDate = new Date();
	expiryDate.setTime(expiryDate.getTime() + (durationInSecs * 1000)); 
	document.cookie = name + '=' + escape(value) + '; expires=' + expiryDate.toGMTString() + "; path=" + path;
}

window.onload = function() {
	try {
		if (!conferencePage) return;
	} catch (e) {
		return;
	}
	var c = getCookie('conf'+conferencePage);
	if (c) {
		clickLink(c);
	}
}