/*************************/
/* js by gonchuki - 2007 */
/*************************/
/*         mootools 1.11 */
/*************************/

var gs_site = {
	throbber: new Asset.image('images/misc/throbber.gif', {id: 'throbber'})
};

window.addEvent('domready', function() {
	
	/* get external links and add js needed to open in new window and icon to text links */
	$$('a').filterByAttribute('rel', '*=', 'external').each( function(anchor) {
		if (!$E('img', anchor))	anchor.addClass('external');
		
		anchor.addEvent('click', function(e) {
			new Event(e).stop();
			window.open(anchor.getAttribute('href'));
		});
		
	});
	
	/* capture contact form to extend into an ajax driven form */
	if ($('contact_form')) {
		var form = $('contact_form').getParent();
		
		form.addEvent('submit', function(e) {
			new Event(e).stop();
			
			if (!CEO.Validator.validate(this, true)) return;
			
			new Fx.Slide($E('div#contact_form dl')).slideOut().chain( function() {
				
				$E('div#contact_form *').setStyle('display', 'none');
				$('contact_form').addClass('with_throbber');
				$('contact_form').adopt(gs_site.throbber);
				
				this.send({
					onFailure: function() {
						$('contact_form').addClass('error');
						$('contact_form').setHTML('there has been an unexpected error while sending your message, please try again later');
					},
					onComplete: function() {
						$('contact_form').addClass('success');
						$('contact_form').setHTML('<p>thanks for your feedback <br />if your message needs a response you will be contacted soon</p>');
					}
				});
			
			}.bind(this));
			
		});
		
	}

});