window.addEvent( 'domready', function() {
	Locale.use( 'pt-PT' );
	new SmoothScroll();

	// add target _blank to external links
	$$( 'a.external' ).each( function( item, index ) {
		item.setProperty( 'target', '_blank' );
	});

	$$( '#searchForm .formSubmit' )[0].addEvent( 'click', function( e ) {
		new Event( e ).stop();
		$( 'searchForm' ).submit();
	});

	// newsletter form
	var newsSlide = new Fx.Slide( 'newsletterForm', {
		onComplete: function() {
			if( this.open ) $( 'newsletterForm' ).getParent( 'div' ).setStyle( 'height', '0px' );
			else $( 'newsletterForm' ).getParent( 'div' ).setStyle( 'height', 'auto' );
		}
	}).hide();
	if( $$( '#newsletterForm .textWrapper' ).length > 0 ) newsSlide.toggle();
	$( 'subscribeBtn' ).addEvent( 'click', function( e ) {
		new Event( e ).stop();
		newsSlide.toggle();
	});

	if( $$( '#newsletterForm .formSubmit' ).length > 0 ) {
		var formNews = new Form.Validator.Inline( 'newsletterForm' );
		$$( '#newsletterForm .formSubmit' )[0].addEvent( 'click', function( e ) {
			new Event.stop( e );
			if( formNews.validate() ) new cpscaptcha( 'newsletterForm', '#newsletterForm' );
		});
	}
	// end

	// recommend form
	var recSlide = new Fx.Slide( 'proposalForm', {
		onComplete: function() {
			if( this.open) $( 'proposalForm' ).getParent( 'div' ).setStyle( 'height', '0px' );
			else  $( 'proposalForm' ).getParent( 'div' ).setStyle( 'height', 'auto' );
		}
	}).hide();
	if( $$( '#proposalForm .textWrapper' ).length > 0 ) recSlide.toggle();
	$( 'orcamentar' ).addEvent( 'click', function( e ) {
		new Event( e ).stop();
		recSlide.toggle();
	});

	if( $$( '#proposalForm .formSubmit' ).length > 0 ) {
		var formRec = new Form.Validator.Inline( 'proposalForm' );
		$$( '#proposalForm .formSubmit' )[0].addEvent( 'click', function( e ) {
			new Event( e ).stop();
			if( formRec.validate() ) new cpscaptcha( 'proposalForm', '#proposalForm' );
		});
	}
	// end

    // contacts form
    if( $$( '#contactsForm .formSubmit' ).length > 0 ) {
		var formContact = new Form.Validator.Inline( 'contactsForm' );
		$$( '#contactsForm .formSubmit' )[0].addEvent( 'click', function( e ) {
			new Event( e ).stop();
			if( formContact.validate() ) new cpscaptcha( 'contactsForm', '#contactsForm' );
		});
	}
    // end
});
