var contactForm = Class.create ({
	
	initialize: function()
	{		
		//current form type
		this.type = 0;
		
		this.showButtons();
		
		//bind listener to buttons
		$('typeGeneral').observe("click", this.toGeneral.bind(this));
		$('typeNewsletter').observe("click", this.toNewsletter.bind(this));
	},
	
	//show button if javascript as on
	showButtons: function()
	{
		if ($('formTypeSelect'))
		{
			$('formTypeSelect').setStyle({
			   display: 'block'
			});
		}
	},
	
	//change to genreal contact form
	toGeneral: function()
	{		
		if(this.type == 1)
		{
			this.type = 0;
			this.toggleForm();
			
			//changed selected button
			$('typeGeneral').addClassName('selected')			
			$('typeNewsletter').removeClassName('selected')
			
			$$('.formBuilderListElement_message').each(function(container)
				{
					container.select('textarea').each(function(textarea){
						textarea.setValue("");
						textarea.setStyle({
							   color: '#000'
							});
					});
				});
		}
	},
	
	//change to newsletter contact form
	toNewsletter: function()
	{		
		if(this.type == 0)
		{
			this.type = 1;
			this.toggleForm();
			
			//changed selected button
			$('typeNewsletter').addClassName('selected')			
			$('typeGeneral').removeClassName('selected')
			
			$$('.formBuilderListElement_message').each(function(container)
				{
					container.select('textarea').each(function(textarea){
						textarea.setValue("I would like to sign up to the newsletter!");
						textarea.setStyle({
							   color: '#fff'
							});
					});
				});
		}
	},
	
	//toggle form
	toggleForm: function()
	{
		$$('.formBuilderFieldset_optional').each(function(container)
			{
				new Effect.toggle(container, 'blind', { duration: 0.7, transition: Effect.Transitions.sinoidal });
			});
	}
});


document.observe('dom:loaded', function()
{	
	if ($('formTypeSelect'))
	{
		new contactForm();
	}
});
