/**
 * fwContact UIE
 *
 * Contact form animation and user interface enhancements
 * Not required to function
 *
 * @required Prototype     <prototypejs.org>
 * @required Scriptaculous <http://script.aculo.us/>
 * @required Behaviour     <http://www.bennolan.com/behaviour/>
 *
 * @author Andrew Murphy <andrew@fryewiles.com>
 *
 * @version 1.0.0a 20080107 AM
 */



var contact_uie = {
	strQuoteText : 'Get a Quote',
	elQuoteBlock : null,
	elReasonSel  : null,

	init: function() {
		contact_uie.elQuoteBlock = $('quote-fields');
		contact_uie.elReasonSel  = $('reason');

		if (
			!contact_uie.elQuoteBlock || !contact_uie.elReasonSel
		) {
			return false;
		}

		//show or hide depending on whether we are looking for a quote when the page loads
		if (
			contact_uie.elReasonSel.value && contact_uie.elReasonSel.value == contact_uie.strQuoteText
		) {
			contact_uie.elQuoteBlock.style.display = 'block';
		} else {
			contact_uie.elQuoteBlock.style.display = 'none';
		}
	},

	behaviours: {
		'#reason' : function(element) {
			element.onchange = function(event) {
				var bQuoteBlockDisplayed = (contact_uie.elQuoteBlock.style.display == 'block');

				//if we want a quote, and the quote block isn't displayed, show it
				if ( element.value == contact_uie.strQuoteText && !bQuoteBlockDisplayed  ) {
					new Effect.SlideDown(
						contact_uie.elQuoteBlock, {
							duration: 0.5,
							afterFinish: function() {
								contact_uie.elQuoteBlock.style.display = 'block';
							}
						}
					);

				//if we select something other than to get a quote, and the block is displayed, hide it
				} else if ( element.value != contact_uie.strQuoteText && bQuoteBlockDisplayed ) {
					new Effect.SlideUp(
						contact_uie.elQuoteBlock, {
							duration: 0.5,
							afterFinish: function() {
								contact_uie.elQuoteBlock.style.display = 'none';
							}
						}
					);
				}
			}
		}
	}
};


Event.observe(window, 'load', contact_uie.init, false);
Behaviour.register(contact_uie.behaviours);
