var HgSubscriptionForm = new Abstract();

HgSubscriptionForm.extend({
	/************************************
		Constructor
	************************************/
	Initialize: function()
	{
		this.$_trigger = $('MailingListButton');
		this.$_form = $('HgSubscriptionForm');
		this.$_firstName = $('HgSubscriptionForm_FirstName');
		this.$_lastName = $('HgSubscriptionForm_LastName');
		this.$_phone = $('HgSubscriptionForm_Phone');
		this.$_email = $('HgSubscriptionForm_Email');
		this.$_feedback = $('HgSubscriptionForm_Feedback');
		this.$_bCancel = $('SubscriptionForm_Cancel');
		this.$_bSend = this.$_form.getElement('.Send');
		this.$_formView = this.$_form.getElement('.FormView');
		this.$_sendView = this.$_form.getElement('.SendView');
		
		this.$_modal = new Odx.ModalPopup(
				this.$_form,
				this.$_button,
				'click',
				this.$_bCancel,
				'click',
				{duration:280,backgroundColor:"#5f2270",maxOpacity:0.93,closeOnClick:false,top:70}
			)
			.addEvent('open', this._OnPopupOpen.bind(this))
			.addEvent('close', this._OnPopupClose.bind(this))
		;
		
		this.$_trigger.addEvent('click', this._OnTriggerClick.bindWithEvent(this));
		this.$_bSend.addEvent('click', this._OnSendClick.bind(this));
		
		return this;
	},
	
	
	/************************************
		Public Properties
	************************************/
	GetFirstName: function()	{ return this.$_firstName.value; },
	GetLastName: function()		{ return this.$_lastName.value; },
	GetPhone: function()		{ return this.$_phone.value; },
	GetEmail: function()		{ return this.$_email.value; },
	GetFeedback: function()		{ return this.$_feedback.value; },
	
	SetFirstName: function(value)	{ this.$_firstName.value = value; return this; },
	SetLastName: function(value)	{ this.$_lastName.value = value; return this; },
	SetPhone: function(value)		{ this.$_phone.value = value; return this; },
	SetEmail: function(value)		{ this.$_email.value = value; return this; },
	SetFeedback: function(value)	{ this.$_feedback.value = value; return this; },	
	
	
	/************************************
		Private Properties
	************************************/
	_HideForm: function()
	{
		var
			effect1 = new Fx.Styles(this.$_formView, {duration:200, transition:Fx.Transitions.Quart.easeOut}),
			effect2 = new Fx.Styles(this.$_sendView, {duration:250, transition:Fx.Transitions.Quart.easeIn});
		
		effect1.start({
			'opacity':0
		});
		
		effect2.start({
			'opacity':1
		});
		
		return this;
	},
	
	_ShowForm: function()
	{
		this.$_formView.setStyle('opacity', 1);
		this.$_sendView.setStyle('opacity', 0);
		
		return this;
	},
	
	
	/************************************
		Public Methods
	************************************/
	ClearForm: function()
	{
		return this.SetFirstName('').SetLastName('').SetPhone('').SetEmail('').SetFeedback('');
	},
	
	Send: function()
	{
		var myAjax = new Ajax(
			'/ajax/sendsubscription',
			{
				method		: 'post',
				onComplete	: this._OnSendComplete.bind(this),
				data		: {
					'FirstName'	: this.GetFirstName(),
					'LastName'	: this.GetLastName(),
					'Phone'		: this.GetPhone(),
					'Email'		: this.GetEmail(),
					'Feedback'	: this.GetFeedback()
				}
			}
		);
		
		this._HideForm();
		myAjax.request();
	},
	
	
	/************************************
		Event Handling
	************************************/
	_OnSendComplete: function()
	{
		this.$_modal.Hide();
		this.ClearForm();
	},
	
	_OnPopupOpen: function()
	{
		
	},
	
	_OnPopupClose: function()
	{
		this._ShowForm();
	},
	
	_OnTriggerClick: function(e)
	{
		e.stop();
		this.$_modal.Show();
		return this;
	},
	
	_OnSendClick: function()
	{
		return this.Send();
	}
});

window.addEvent('domready', function()
{
	HgSubscriptionForm.Initialize();
});
