$(function(){
	
	var fadeSpeed = 200;
	
	/*=========================
	Main-Menu Hover
	=========================*/
	$('#menu a').hover(function(){
		$('#menu *').not(this).stop().animate({opacity: 0.5}, fadeSpeed);
	}, function(){
		$('#menu *').stop().animate({opacity: 1}, fadeSpeed);
	});
	
	$('#menu a').click(function(){
		$('#main-menu').animate({opacity: 0}, fadeSpeed, function(){
			$(this).hide();
		});
		$('#main').show(0, function(){
			$('#main').animate({opacity: 1}, fadeSpeed);
		});
	});
	
	
	
	
	/*=========================
	Side-Menu Hover
	=========================*/
	$('#side-menu-links a, .home-link, #side-menu-links p').not('.selected').animate({opacity:0.3}, fadeSpeed);
	$('#side-menu').hover(function(){
		$('#side-menu-links a, .home-link').animate({opacity:1}, fadeSpeed);
	}, function(){
		$('#side-menu-links a, .home-link').animate({opacity:0.3}, fadeSpeed);
	});
	
	
	/*=========================
	Logo Hover
	=========================*/
	$('#logo-wrap').hover(function(){
		$('#logo').stop().bgFade('fadeIn');
		$('#name').stop().animate({ color: '#ff4800' }, fadeSpeed);
	}, function() {
		$('#logo').stop().bgFade('fadeOut');
		$('#name').stop().animate({ color: '#1b5771' }, fadeSpeed);
	});
	
	$('.heatmap').live('hover',function(){
		$(this).stop().bgFade('fadeIn');
	}, function() {
		$(this).stop().bgFade('fadeOut');
	});
	
	
	/*=========================
	Photography Slideshow Size
	=========================*/
	$(window).resize(function(){
		var windowHeight = $(window).height();
		$('#photography-wrapper').css({height: windowHeight - 100});
	});
	
	
	/*=========================
	Social button
	=========================*/
	var contactPadding = parseInt( $('#contact').css('padding-top').replace('px','') );
	var contactHeight = $('#contact').height();
	if( $.browser.msie )
	{
		contactPadding = contactPadding + 3;
	}
	$('.social').toggle(function(){
		$('#contact').stop().animate({height: (contactHeight+contactPadding)*2}, fadeSpeed);
	}, function(){
		$('#contact').stop().animate({height: contactHeight }, fadeSpeed);
	});
	
	/*=========================
	Hashchange Functionality
	=========================*/
	var titleSuffix = " | Jake Lauer's Web Portfolio";
	var loadedYet = false;
	$(window).bind('hashchange', function () {
	
		/*=========================
		IE Photography Size Fix
		=========================*/
		if( $.browser.msie && hash == "photography" )
		{
			var windowHeight = $(window).height();
			$('#photography-wrapper').css({height: windowHeight - 100});
		}
		
		
		var hash = location.hash.replace( /^#/, '' );
		
		
		/*=========================
		Home and User Experience
		get their own rules. The
		other pages follow the
		rules in the first "if"
		=========================*/
		
		
		if( hash != "" && hash != "home" && !hash.match("user-experience") ){
			$('#main-menu').animate({opacity: 0}, fadeSpeed, function(){
				$(this).hide();
			});
			$('#main').show(0, function(){
				$('#main').animate({opacity: 1}, fadeSpeed);
			});
			if( hash != $('#thisFile').text() )
			{
				$('#main').css({background: 'transparent url(images/load.gif) center center no-repeat'});
				$('#content-load-area').animate({opacity:0},fadeSpeed, function(){
					$(this).load(hash+'.html',function(){
						$('#main').css({background: 'transparent'});
						$(this).animate({opacity:1},fadeSpeed);
						document.title = $('#title').text() + titleSuffix;
						if( $.browser.msie )
						{
							$(this).height( $(this).height() );
						}
					});
				});
			}
			loadedYet = false;
			
		
		/*=========================
		Specific to "Home" so that
		the user can get back to
		the main page
		=========================*/
		} else if( hash == "" || hash == "home" ){
			$('#main-menu').show(0, function(){
				$(this).animate({opacity: 1}, fadeSpeed);
			});
			$('#main').animate({opacity: 0}, fadeSpeed, function(){
				$(this).hide();
			});
			loadedYet = false;
			
		
		/*=========================
		Specific to "User Experience"
		because that page has its 
		own separate navigation
		that is also goverened by
		hash changes
		=========================*/
		} else if( hash.match("user-experience") ) {
			$('#uex-list a').not('a[href=#' + hash + ']').css({opacity:0.5});
			$('a[href=#' + hash + ']').css({opacity:1});
			$('#main-menu').animate({opacity: 0}, fadeSpeed, function(){
				$(this).hide();
			});
			$('#main').show(0, function(){
				$('#main').animate({opacity: 1}, fadeSpeed);
			});
			if( loadedYet == false )
			{
				$('#main').css({background: 'transparent url(images/load.gif) center center no-repeat'});
				$('#content-load-area').animate({opacity:0},fadeSpeed, function(){
					$(this).load('user-experience.html',function(){
						document.title = $('#title').text() + titleSuffix;
						$('#main').css({background: 'transparent'});
						$(this).animate({opacity:1},fadeSpeed, function(){
							if( hash != "user-experience" ) {
								$('.uex, .click-one').hide();
								$('#uex-list a').not('a[href=#' + hash + ']').css({opacity:0.5});
								$('a[href=#' + hash + ']').css({opacity:1});
							}
							$('.' + hash).fadeIn(fadeSpeed);
						});
					});
				});
				loadedYet = true;
			} else {
				$('.uex, .click-one').hide();
				if( hash == "user-experience" )
				{
					$('#uex-list a').not('a[href=#' + hash + ']').css({opacity:0.5});
					$('a[href=#' + hash + ']').css({opacity:1});
					$('.click-one').fadeIn(fadeSpeed);
				}
				$('.' + hash).fadeIn(fadeSpeed);
			}
		}
	});
	

	/*=========================
	Trigger hashchange in case
	it does not get triggered
	automatically
	=========================*/
	$(window).trigger( "hashchange" );
	
});
