
// Automatically calls all functions in ET.init
jQuery(document).ready(function() {
	ET.global();
	$(document).pngFix(); 
});

// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
var ET = (function($) {
	return {
		// Start It
		global: function() {
			for (var i in ET.init) {
				ET.init[i]();
			}
		},



		init: {
			cufon: function() 
			{
				Cufon.replace('p.futura');
			},
			
			
			// Navigation drop downy things
			navigation: function() 
			{
				// First, preload needed images
				ET.preload([
					'/assets/img/nav_contact_bg.png',
					'/assets/img/nav_history_bg.png',
					'/assets/img/nav_home_bg.png',
					'/assets/img/nav_news_bg.png',
					'/assets/img/nav_tech_bg.png'
					
				]);
				
				$('ul.nav a').hover(function(){

				
					// Get links parent id

					var type = $(this).parent().attr('id');
					var cls = $('#' + type).attr('class');

					if (cls !== 'active')
					{
						var image = '<img id="' + type + '" class="background" style="top:-111px" src="/assets/img/nav_' + type + '_bg.png">';
						
						// Check to see if the image already exists before creating a new one.
						if ($('img#'+type).length == 0)
						{
							$(this).parent().prepend(image);
						}
						
						// Animate the image down
						$('li#'+ type +' img.background').animate({
							top: 0
						}, 300);
						
						
						$('li#'+ type +' a').animate({
								color: '#FFFFFF'
						}, 300);
					
					}					
					
				}, function() {
				
					// Get links parent id
					var type = $(this).parent().attr('id');
					var cls = $('#' + type).attr('class');
					
					if (cls !== 'active')
					{
				
						$('li#'+ type +' a').animate({
							color: '#2c8db7'
						}, 300);
							
						$('li#'+ type +' img.background').animate({
						    top: -111
						}, 300);
				
					}				
				
				});
			
			
			
			},
			
			// Level hover states
			levels: function() 
			{
				
				var cls = '';
				
				$('div.levels a').hover(function() {
					// Get id of item.
					var id = $(this).attr('id');
					
					$('div.levels a#'+id+' img:first').hide();
					$('div.levels a#'+id+' img:nth-child(2)').show();
					
					
				}, function() {
					var id = $(this).attr('id');
					
					$('div.levels a#'+id+' img:nth-child(2)').hide();
					$('div.levels a#'+id+' img:first').show();
					
				});
				
			},
			
			
			
			
			// Make the content div match div.right
			level_height: function() 
			{
				// if div.right exists
				if ($('div.right').length > 0)
				{
					// get heights
					var r_height = $('div.right').height();
					var l_height = $('div.left').height();
					
					if (r_height > l_height)
					{
						$('div.left').height(r_height);
					}
				
				}
			
			},
			
			
			
			
			// For all the happy images on the home page
			image_scroller: function() 
			{
				$('#scroller_1').innerfade({
							animationtype: 'fade',
							speed: 3000,
							timeout: 5000,
							/*type: 'random',*/
							containerheight: '284px'
						});
				
			}

			
			
			
			
			
		},



		
		preload: function(array)
		{
    		$(array).each(function(){
    		    $('<img/>')[0].src = this;
    		});
		
		}
	};
// Pass in jQuery ref.
})(jQuery, this);






