function hideForm(heading, content, cookie_name)
{
	heading.removeClassName('form_open');
	content.style.overflowY = 'hidden';
	content.slideUp({duration: 0.25, queue: {position: 'end', scope: cookie_name}});
	eraseCookie(cookie_name);
}

function showForm(heading, content, cookie_name)
{
	heading.addClassName('form_open');
	content.style.visibility = 'visible';
	content.slideDown(
		{
			duration: 0.25, 
			queue: {position: 'end', scope: cookie_name}, 
			afterFinish: function()
			{
				if (this.getHeight() > 400)
				{	
					this.style.height = '400px';
					this.style.overflowY = 'auto';
				}
			}.bind(content)
		}
	);
	createCookie(cookie_name, 'yes');
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}

	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

Event.observe(window, 'load', function (e) {
	$$('#Launchpad01', '#Launchpad02', '#Launchpad03', '#Launchpad04').each(function(s){
		var launchpad = s.identify();
		s.addClassName('top_launchpad')
		if(!(s.down('.heading')==undefined))
		{
			var top_heading = s.down('.heading').addClassName('top_heading')
			if(!(top_heading.next()==undefined))
			{
				var top_content = top_heading.next().addClassName('top_content')
				top_heading.onclick = function()
					{
						if(top_heading.hasClassName('form_open'))
						{
							hideForm(top_heading, top_content, launchpad);
						}
						else
						{
							showForm(top_heading, top_content, launchpad);
						}
					};
				if(!readCookie(launchpad))
				{
					hideForm(top_heading, top_content, launchpad);
				}
				else
				{
					showForm(top_heading, top_content, launchpad);
				}
			}
			s.observe('mouseover', function(){top_heading.addClassName('active');});
			s.observe('mouseout', function(){top_heading.removeClassName('active');});
		}
	});
});
