
var home = {

	init: function() {
	
		//$j('home-menu-strip').setStyle('width: 0;')
		$j('home-menu-strip').css('width', '0');
		$j('home-menu-links').hide();

		$j('products-link').bind( 'click', function(e) {
		
			e.stop();

			home.show_sub_bar();
			home.show_menu('products');
		
		});
	
		$j('services-link').bind( 'click', function(e) {
		
			e.stop();

			home.show_sub_bar();
			home.show_menu('services');
		
		});
			
	},
	
	animate: function() {
	
		//menu
		new Effect.Morph( 'home-menu-strip', { style: 'width: 777px;', duration: 0.4 } );
		if( !Prototype.Browser.IE ) {
//			$j('home-menu-links').setStyle('opacity: 0').show();
						$j('home-menu-links').css('opacity', '0').show();
			new Effect.Morph( 'home-menu-links', { style: 'opacity: 1', duration: 0.4, delay: 0.3 } );
		} else {
			Element.show.delay( 0.3, 'home-menu-links' );		
		}
	
		//taglines
		( function() {
		
			home.current_tagline = 0;
			home.show_tagline();
		
		} ).delay( 1 );

	
	},
	
	show_tagline: function() {

		//animate tagline
		var elm = $j('#home-taglines img')[ home.current_tagline ];
		
		elm.show();
		$j('home-taglines').css( 'opacity: 0; right: 10px;' );
		new Effect.Morph( 'home-taglines', { style: 'opacity: 1; right: 25px;', duration: 1 } );
		
		//recurse
		( function() {

			var elm = $$('#home-taglines img')[ home.current_tagline ];
			new Effect.Morph( 'home-taglines', { style: 'opacity: 0; right: 50px;', duration: 0.5, afterFinish: function() { elm.hide() } } );
		
			//hide current tagline
			( function() {
			
				home.current_tagline = home.current_tagline == 2 ? 0 : home.current_tagline + 1;
				home.show_tagline();

			} ).delay( 1 );	
		
		} ).delay( 5 );
	
	},
	
	show_menu: function( type ) {
	
		$j('products-submenu').hide();
		$j('services-submenu').hide();
		$j('products-link').removeClassName('selected');
		$j('services-link').removeClassName('selected');
	
		var submenu = type + '-submenu';
		var link = type + '-link';

		$j(link).addClassName('selected');
		
		( function() { $j(submenu).show().setStyle( 'opacity: 1; left: 12px;' ) } ).delay( home.delay );
		
		new Effect.Morph( submenu, { style: 'opacity: 1; left: 22px;', duration: 0.4, delay: home.delay } );
		
		var i = 0;
		$$( '#' + submenu + ' a').each( function( elm ) {
		
			( function() {
				elm.setStyle( 'color: #00002b;' );
				new Effect.Morph( elm, { style: 'color: #fff;', duration: 0.4, delay: i, afterFinish: function() { elm.style.color = null } } );
				i += 0.05;
			} ).delay( home.delay - 0.2 );
		
		});
		
		home.delay = 0;
		
	},
	
	show_sub_bar: function() {
	
		if( $j('home-menu-substrip').getStyle('display') == 'none' ) {
		
			$j('home-menu-substrip').show().setStyle( 'height: 1px; opacity: 0;' );
			new Effect.Morph( 'home-menu-substrip', { style: 'height: 25px; opacity: 1;', duration: 0.4 } );

			home.delay = 0.4;
		
		}

	}

}
document.observe( 'dom:loaded', home.init );
Event.observe( window, 'load', home.animate );
