window.addEvent( 'domready', function(e) {
	// get the previous value
	var previous = $( 'division-name' ).innerHTML;
	// add the events
	$$( 'div.divisions div.square' ).addEvents({
		// when the mouse enters then show the applicable division
		'mouseenter': function(e) {
			$( 'division-name' ).set( 'text', this.lang + ' Services' );
		},
		// when it leaves restore the previous value (could be empty)
		'mouseleave': function(e) {
			$( 'division-name' ).set( 'text', previous );
		},
		// when they click on one then load that division
		'click': function(e) {
			window.location = '/' + this.lang.toLowerCase();
		}
	// make the cursor go to pointer for the boxes
	}).setStyle( 'cursor', 'pointer' );
	
	// make sure we are on the homepage
	if( $('divisions') ) {
		// go through each link
		$$( 'a.fisheye' ).each( function( link ) {
			// add the height property
			link.getElement( 'img' ).setStyle( 'height', '55' );
			// add the events
			link.addEvents({
				'mouseenter': function(e) {
					// add the effect
					var effect = new Fx.Morph( link.getElement( 'img' ), {
						duration: 'short',
						transition: Fx.Transitions.Sine.easeOut
					});
					effect.start({
						//'src': src.replace( "small", "large" ),
						'height': [ 55, 73 ],
						'width': [ 95, 125 ],
						'margin-top': [ 0, -18 ],
						'margin-left': [ 0, -18 ]
					});
				},
				'mouseleave': function(e) {
					var effect = new Fx.Morph( link.getElement( 'img' ), {
						duration: 'short',
						transition: Fx.Transitions.Sine.easeOut
					});
					effect.start({
						//'src': src.replace( "large", "small" ),
						'height': [ 73, 55 ],
						'width': [ 125, 95 ],
						'margin-top': [ -18, 0 ],
						'margin-left': [ -18, 0 ]
					});
				}
			});
		});

	}
	
	// case study animation
	if( $( 'case-info') && $( 'case-studies' ) ) {
		
		// add the pointer to the div
		$( 'case-studies' ).setStyle( 'cursor', 'pointer' );
		
		// add the mouse enter/leave events to the case study
		$( 'case-studies' ).addEvents({
			'mouseenter': function(e) {
				// add the effect
				var effect = new Fx.Morph( $( 'case-info' ), {
					duration: 'long',
					transition: Fx.Transitions.Sine.easeOut
				});
				effect.start({
					'height': [ 41, 90 ],
					'width': [ 162, 246 ],
					'margin-top': [ 278, 229 ],
					'margin-left': [ 238, 154 ],
					'background-image': [ 
						"url( '/images/casestudy/case-study-learn-more-small.png')", 
						"url('/images/casestudy/case-study-learn-more-large.png')"
					]
				});
			},
			'mouseleave': function(e) {
				// add the effect
				var effect = new Fx.Morph( $( 'case-info' ), {
					duration: 'long',
					transition: Fx.Transitions.Sine.easeOut
				});
				effect.start({
					'height': [ 90, 41 ],
					'width': [ 246, 162 ],
					'margin-top': [ 229, 278 ],
					'margin-left': [ 154, 238 ],
					'background-image': [ 
						"url('/images/casestudy/case-study-learn-more-large.png')",
						"url('/images/casestudy/case-study-learn-more-small.png')"
					]
				});
			}
		});
		
	}
	
	// get the url
	var url = window.location.href.split( ".com" );
	// strip the slash from the end
	url[1] = url[1].replace( "/", "" );
	
	// set the page based on what is left
	if( url[1] == "" || url[1] == "home" ) var page = "home";
	else var page = "other";
	
	// see if there is a services dropdown image
	if( $( 'division_dropdown' ) ) {
		// add the cursor to the image
		$( 'division_dropdown' ).setStyle( 'cursor', 'pointer' );
		// add the events
		$( 'division_dropdown' ).addEvent( 'click', function(e) {
			// stop the default
			new Event(e).stop();
			// get the posision of the image
			var coords = this.getCoordinates();
			// show and position the box
			$( 'divisionbox' ).setStyles({
				'background-color': ( page == 'home' ? '#c7261e' : '#454648' ),
				'display': ( $( 'divisionbox' ).getStyle( 'display' ) == 'none' ? '' : 'none' ),
				'position': 'absolute',
				'left': coords['left'],
				'top': coords['top']+5
			}).addEvent( 'mouseleave', function(e) {
				this.setStyle( 'display', 'none' );
			});
		});
		
		// add the mouseenter and mouseleave to the li elements
		$$( 'ul#divisionbox li' ).addEvents({
			'mouseenter': function(e) {
				this.setStyles({
					'background-color': ( page == 'home' ? '#6d0b10' : '#747577' )
				});
			},
			'mouseleave': function(e) {
				this.setStyles({
					'background-color': ( page == 'home' ? '#c7261e' : '#454648' )
				});
			}
		});
	}
	
});