Event.observe(window, 'load', init, false);

function init() {
	EventSelectors.start(Rules);
}

Event.onDOMReady(function() {
	$('results').style.display = 'none';
	$('extras').style.display = 'none';
});

var Rules = {
	'#flipforus:submit': function(element, event) {
		Email.process();
		Event.stop(event);
	},
	'#between:click': function(element, event) {
		Effect.toggle('extras', 'blind', {duration: .3});
	}
}

// Call/Email

var	Email	=	{

	// the following preventDefault function is from the YUI Event Utility and is Copyright (c) 2006, Yahoo! Inc. All rights reserved.
	stop		:	function(ev)	{
					if (ev.preventDefault) {
					ev.preventDefault();
					} else {
						ev.returnValue = false;
					}
					},
	indicator	:	function()	 {
					if($('loading')) {$('loading').parentNode.removeChild($('loading'));}
	
					var indicator = document.createElement('img');
					indicator.src = 'images/loading.gif';
					indicator.id = 'loading';
					$('indicatorwrapper').appendChild(indicator);
					Effect.Appear('indicatorwrapper', {duration: .5});
					},
	// send the email and return results
	process		:	function(event)	{
				//	this.indicator();
					var url = 'process.php';
					var pars = 'call='+escape($F('call'))+'&'+'between='+escape($F('between'))+'&'+'yours='+escape($F('yours'))+'&'+'theirs='+escape($F('theirs'));
					var target = 'results';
					var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars, onComplete: this.complete});
					},
	
	//do the fade stuff after it's sent
	complete	:	function() {
					//	Effect.Appear('contactresults',{duration:0.5, queue: {position: 'end', scope: 'results'}});
						$('results').show();
						new Effect.Highlight('results', {duration: 2, endcolor: '#383638', queue: {position: 'end', scope: 'results'}})
						Effect.Fade('indicatorwrapper');
					}
}