window.addEvent( 'domready', function() {

	$$( '.textWrapper a' ).setStyle( 'text-decoration', 'underline' );
	$$( '.textWrapper a' ).addClass( 'external' );

	// adicionar target _blank a links para o exterior
	$$('a.external').each( function( item, index ) {
		item.setProperty( 'target', '_blank' );
	});

	// menu hover effect
	var els = $$( '.mainMenu a' );
	if( els.length > 0 ) {
		els.each( function( item, index ) {
			if( item.hasClass( 'active' ) ) return;
			var child = item.getChildren( 'span' )[0];
			var fx = new Fx.Tween( child, {
				duration: 200
			});
			$$( '.mainMenu' )[0].removeClass( 'noJs' );
			item.addEvent( 'mouseover', function() {
				fx.cancel();
				fx.start( 'top', -40, -20 );
			});
			item.addEvent( 'mouseleave', function() {
				fx.cancel();
				fx.start( 'top', -20, -40 );
			});
			item.addEvent( 'click', function() {
				fx.cancel();
				item.setStyle( 'color', '#5EC5FF' );
				child.setStyle( 'top', -20 );
			});
		});
	}
	
	// fix a IE7 css bug in input text element that doesn't change on focus
	if( $( 'contactForm' ) || $$( '#recommendForm .formSubmit' ).length > 0 ) {
		$$( 'input[type=text], textarea' ).each( function( item, index ) {
			item.addEvent( 'focus', function() {
				item.getParent( 'p' ).addClass( 'focus' )
			});
			item.addEvent( 'blur', function() {
				item.getParent( 'p' ).removeClass( 'focus' )
			});
		});
	}
	
	// Apply the slider and scroll effects in footer contents
	var footerSlider = new Fx.Slide( $( 'footerContent' ), {
		'onComplete': function() {
			if( !this.open ) return;
			$( 'footer' ).addClass('open');
			$( 'footerContent' ).addClass('open');
			// The following line fix a IE7 css bug in genericMapBlock element that doesn't disappear 
			// when the slider is closed. This fix is intended to apply before closing element, show 
			// the element genericMapBlock.
			$( 'genericMapBlock' ).removeClass('hide');
			new Fx.Scroll( window, { 'duration': 1500 }).start( 0, $( 'footerContent' ).getCoordinates().top );
		}
	});

	$$( '#footer .more' )[0].addEvent( 'click', function(e) {
		new Event.stop(e);
		// The following line fix a IE7 css bug in genericMapBlock element that doesn't disappear 
		// when the slider is closed. This fix is intended to apply before closing element, hide 
		// the element genericMapBlock.
		if( footerSlider.open ) {
			$( 'footer' ).removeClass('open');
			$( 'footerContent' ).removeClass('open');
			$( 'genericMapBlock' ).addClass('hide');
		}
		footerSlider.toggle();
	});
	footerSlider.hide();	
	
	if( $$( '#recommendForm .formSubmit' ).length > 0 ) {
		var formValidation = new Form.Validator.Inline( 'recommendForm' );
		$$( '#recommendForm .formSubmit' )[0].addEvent( 'click', function( e ) {
			new Event.stop( e );
			if( formValidation.validate() ) new cpscaptcha( 'recommendForm', '#recommendForm' );
		});
	}
	if( $$( '#recommendForm .textWrapper' ).length > 0 ) {
		$( 'footer' ).addClass('open');
		$( 'footerContent' ).addClass('open');
		footerSlider.toggle();
	}
});

