window.addEvent('domready', function()
{
	//we add the events on our links to show the form:
	$$('.contactus').addEvent('click', function(_evt)
	{
		_evt.stop();

		//we find how much we are scrolled
		var arr_window_scroll = window.getScroll();

		//we then find our window size:
		var arr_window_size = window.getSize();

		//we set our contact form container visible:
		$('contactuscontainer').setStyle('display', 'block');

		//we then find the size of our container:
		var arr_container_size = $('contactuscontainer').getSize();

		//we then find at which position we must set our container:
		var x_pos = ((arr_window_size.x - arr_container_size.x) / 2) + arr_window_scroll.x;
		var y_pos = ((arr_window_size.y - arr_container_size.y) / 2) + arr_window_scroll.y;

		//we set our new position to our container:
		$('contactuscontainer').setStyles({'left' : x_pos, 'top' : y_pos});

		//we fadein/out:
		var objfade = new Fx.Tween($('contactuscontainer'));
		objfade.set('opacity', 0);
		objfade.start('opacity', 0, 1);
	});

	//we add our closewindow event:
	$$('.closewindow').addEvent('click', function(_evt)
	{
		_evt.stop();
		new Fx.Tween($('contactuscontainer')).start('opacity', 1, 0);
	});

	//we add our form event:
	$('contactusform').addEvent('submit', function(_evt)
	{
		_evt = new Event(_evt).stop();
		
		//we send our data:
		new Request.JSON({
			url: this.getProperty('action'),
			data: {
				'fname': $('fname').getProperty('value'),
				'lname': $('lname').getProperty('value'),
				'company': $('company').getProperty('value'),
				'email': $('email').getProperty('value'),
				'phone': $('phone').getProperty('value'),
				'comments': $('comments').getProperty('value')
			},
			onComplete: function(_obj) {
				$('contactusformlog').set('text', _obj.msg);
				new Fx.Tween($('contactusformlog'), 'opacity').start('opacity', 0, 1); 
				new Fx.Tween($('contactusformfadeout'), 'opacity').start('opacity', 1, 0);
			}
		}).send();
	});
});


