$(document).ready(function(){
	
	$(window).bind('resize', function(){
		Resize();
	});
	
	$(window).load(function(){
		Resize();
	});
		
	function Resize(){
	
		/* var $resume_height = $('#Resume .TitleImage').width();
		var $portfolio_height = $('#Portfolio .TitleImage').height();
		var $contact_height = $('#Contact .TitleImage').height();
		console.log($resume_height, $portfolio_height, $contact_height);*/
		
		$('#GlobalNav > div').each(function(){
			
			var $this = $(this);
			
			var $purple = $(this).find('.Purple');
			
			var $title_image = $(this).find('.TitleImage');
			var $subnav = $(this).find('.SubNav');
			var $subnav_width = $subnav.width();
						
			var $ratio = $title_image.attr('height');
			
			var $container_width = $(this).width();

			$title_image.css({'top': $ratio * .15, 'left': $ratio * .15 });
			$subnav.css({'top': $ratio * .3, 'left': $ratio * .3, 'padding-top': $ratio * 1.2, 'padding-bottom': $ratio * .4, 'padding-left': $ratio * .7, 'padding-right': $ratio * .7, 'width': $container_width - $ratio * 2.5});
			$purple.css({'opacity': 0,'width': $container_width - $ratio * 1.2});
			
			var $this_height = $ratio;
			var $this_final_height = $subnav.height() + $ratio * 2.5;						
			$this.css({'height' : $this_height});
			
			$this.hover(expandNav, shrinkNav);
			
			function expandNav() {
				$this.css({'cursor' : 'hand', 'cursor':'pointer'});
				$this.stop().animate({'height': $this_final_height}, 300);
				$purple.animate({'opacity': 0.5}, 300);
			};
			
			function shrinkNav() {
				// this.css({'height': $this_height});
				$this.stop().animate({'height': $this_height}, 300);
				$purple.css({'opacity': 0});
			};
			
			ResizeElementsOnLoad();
			
			function ResizeElementsOnLoad() {
				
				setTimeout(function(){
					$purple.css({'height': $subnav.height() + $ratio * 1.2 });	
					// $this_element.css({'height': $subnav.height() + $ratio * 1.4 });	
					
				}, 2500);
				
			};
			
			// console.log($ratio, $subnav.outerHeight(), $purple.height());
			
		}); // ends each function
	}; // ends Resize
	
});
