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

	// forms
	if( $( 'newsletterForm' ) ) {
		new FormCheck( 'newsletterForm', {
			submit: false,
			display: {
				addClassErrorToField: 1
			},
			onValidateSuccess: function() {
				new cpscaptcha( 'newsletterForm', '#newsletterForm' );
			}
		});
	}
	if( $( 'talkWithUsForm' ) ) {
		new FormCheck( 'talkWithUsForm', {
			submit: false,
			display: {
				addClassErrorToField: 1
			},
			onValidateSuccess: function() {
				new cpscaptcha( 'talkWithUsForm', '#talkWithUsForm' );
			}
		});
	}

	// menu hover effect
	var menuDefs = new Array();
	if( document.body.hasClass( 'pt' ) ) {
		menuDefs[0] = new Array( '0 -53px', '0 -70px' );
		menuDefs[1] = new Array( '-68px -53px', '-68px -73px' );
		menuDefs[2] = new Array( '-167px -53px', '-167px -73px' );
		menuDefs[3] = new Array( '-254px -53px', '-254px -73px' );
		menuDefs[4] = new Array( '-346px -53px', '-346px -73px' );
		menuDefs[5] = new Array( '-435px -53px', '-435px -73px' );
		menuDefs[6] = new Array( '-621px -53px', '-621px -73px' );
	} else {
		menuDefs[0] = new Array( '0 -41px', '0 -60px' );
		menuDefs[1] = new Array( '-68px -41px', '-68px -60px' );
		menuDefs[2] = new Array( '-167px -41px', '-167px -60px' );
		menuDefs[3] = new Array( '-254px -41px', '-254px -60px' );
		menuDefs[4] = new Array( '-346px -41px', '-346px -60px' );
		menuDefs[5] = new Array( '-455px -41px', '-455px -60px' );
		menuDefs[6] = new Array( '-621px -41px', '-621px -60px' );
	}
	$$( '#header .mainMenu ul li a' ).each( function( item, index ) {
		if( Browser.Engine.trident4 == true ) return;
		if( item.hasClass( 'active' ) ) return;
		var menuFx = new Fx.Tween( item, { duration: 200 });
		item.addEvent( 'mouseover', function() {
			menuFx.cancel();
			menuFx.start( 'background-position', menuDefs[index][0], menuDefs[index][1] );
		});
		item.addEvent( 'mouseleave', function() {
			menuFx.cancel();
			menuFx.start( 'background-position', menuDefs[index][1], menuDefs[index][0] );
		});
	});

	// recentProjects
	if( $$( '.recentProjects ul .item' ).length > 0 ) {
		$$( '.recentProjects ul .item' ).each( function( item, index ) {

			if( Browser.Engine.trident4 == true ) return;
			var hover = false;
			var fx = new Array();
			fx[0] = new Fx.Morph( item.getChildren( 'div' )[0], { duration: 200 });
			fx[1] = new Fx.Tween( item.getChildren( '.image' )[0], { duration: 200 });

			item.addEvent( 'mouseover', function() {
				if( hover ) return;
				hover = true;
				fx[0].cancel();
				fx[0].start({ 'background-color': '#00ADE2' });
				fx[1].cancel();
				fx[1].start( 'background-position', '0 0', '-40px 0' );
			});
			item.addEvent( 'mouseleave', function() {
				hover = false;
				fx[0].cancel();
				fx[0].start({ 'background-color': '#9BD7F3' });
				fx[1].cancel();
				fx[1].start( 'background-position', '-40px 0', '0 0' );
			});

		});

	}

	// pagination effect
	var paginationItems = $$( '.paginationList li .next, .paginationList li .prev' );
	if( paginationItems.length > 0 ) {
		paginationItems.each( function( item, index ) {
			var fx = new Array();
			var pos = new Array();
			pos['prev'] = new Array( -220, 0 );
			pos['next'] = new Array( 0, -220 );
			fx = new Fx.Tween( item.getChildren( '.holder' )[0], { duration: 300 });
			item.addEvent( 'mouseenter', function() {
				fx.cancel();
				if( item.hasClass( 'next' ) ) position = pos['next'][0];
				else position = pos['prev'][0];
				fx.start( 'margin-left', position );
			});
			item.addEvent( 'mouseleave', function() {
				fx.cancel();
				if( item.hasClass( 'next' ) ) position = pos['next'][1];
				else position = pos['prev'][1];
				fx.start( 'margin-left', position );
			});
		});
	}
});
