jQuery(document).ready( function() {
//--------------------------------------------------
// FIXED MENU
//--------------------------------------------------
	if ( !( $.browser.msie && $.browser.version < '7.0' ) ) {
		var menuHeight = $('div#bottom_content_left').height() + 13;
		var menuContent = $('div#bottom_content_left').html();
		var menuTop = $('div#bottom_content_left').offset().top;
		
		$('div#bottom_content_left').remove();
		
		$('div#bottom_content').prepend('<div id="bottom_content_left_holder"></div>');
		$('div#bottom_content_left_holder').height(menuHeight);
		
		$('div#page').append('<div id="bottom_content_left_fixed"></div>');
		$('div#bottom_content_left_fixed').html(menuContent).css('top', menuTop);
		
		$(window).scroll( function () {
			var windowTop = $(window).scrollTop() + 150;
			
			var windowBottom = $('div#top_of_page').offset().top - 20;
			var menuBottom = windowTop + $('div#bottom_content_left_fixed').height() + 13;
			var menuStop = windowBottom - $('div#bottom_content_left_fixed').height() - 13;
			
			if ( windowTop > menuTop ) {
				if ( menuBottom < windowBottom ) {
					$('div#bottom_content_left_fixed').css({'position' : 'fixed', 'top' : '150px' });
				}
				
				else {
					$('div#bottom_content_left_fixed').css({'position' : 'absolute', 'top' : menuStop });
				}
			}
			
			if ( windowTop < menuTop ) {
				$('div#bottom_content_left_fixed').css({'position' : 'absolute', 'top' : menuTop });
			}
		});
	}
	
//--------------------------------------------------
// ARCHOR LINKS
//--------------------------------------------------
	var urlAnchor = document.location.hash;
	
	if ( !urlAnchor == '' ) {
		var anchorExplode = urlAnchor.split("/");
		
		if ( !anchorExplode[1] == '' ) {
			var urlSection = anchorExplode[1];
			
			if ( $('div.projects_bottom div#' + urlSection).length > 0 ) {
				$('ul.project_catgeories').children('li.active').removeClass('active');
				$('div.projects_bottom').children('div.active').removeClass('active').hide();
				
				$('ul.project_catgeories').children('li').children('a.' + urlSection).parent('li').addClass('active');
				$('div.projects_bottom').children('div#' + urlSection).addClass('active').show();
				
				if ( !anchorExplode[3] == '' ) {
					var pageNumber = anchorExplode[3];
					
					if ( $('div.projects_bottom').children('div#' + urlSection).children('div.sub_section_' + pageNumber).length  > 0 ) {
						$('div.projects_bottom').children('div#' + urlSection).children('div.portfolio_nav').children('a.active').removeClass('active');
						
						$('div.projects_bottom').children('div#' + urlSection).children('div.portfolio_nav').children('a#sub_section_' + pageNumber).addClass('active');
						
						$('div.projects_bottom').children('div#' + urlSection).children('div.sub_section_1').hide();
						
						$('div.projects_bottom').children('div#' + urlSection).children('div.sub_section_' + pageNumber).show();
					}
				}
			}
		}
	}
	
//--------------------------------------------------
// SECTION
//--------------------------------------------------
	$('ul.project_catgeories').children('li').children('a').click( function() {
		$(this).blur();
		
		if( !$(this).parent('li').hasClass('active') ) {
			if ( !$('div.projects_bottom').hasClass('active') ) {
				$('div.projects_bottom').addClass('active');
				
				var section = $(this).attr('class');
				
				$('ul.project_catgeories').children('li.active').removeClass('active');
				$(this).parent('li').addClass('active');
				
				$('div.projects_bottom').children('div.active').removeClass('active').fadeOut( 800, function() {
					$('div.projects_bottom').children('div#' + section).addClass('active').fadeIn( 800, function() {
						$('div.projects_bottom').removeClass('active');
					});
				});
			}
		}
	});
	
//--------------------------------------------------
// SUB SECTION
//--------------------------------------------------
	$('div.portfolio_nav a').click( function() {
		$(this).blur();
		
		if ( !$(this).hasClass('active') ) {
			if ( !$('div.projects_bottom').hasClass('active') ) {
				var oldSubSection = $(this).siblings('a.active').attr('id');
				var newSubSection = $(this).attr('id');
				
				$('div.projects_bottom').addClass('active');
				
				$(this).siblings('a.active').removeClass('active');
				$(this).addClass('active');
				
				$(this).parent('div.portfolio_nav').parent('div.portfolio_section').children('div.' + oldSubSection).fadeOut( 800, function() {
					$(this).siblings('div.' + newSubSection).fadeIn( 800, function() {
						$('div.projects_bottom').removeClass('active');
					});
				});
			}
		}
	});
	
//--------------------------------------------------
// CURRENT LINK
//--------------------------------------------------
	$('div.project').children('h4').children('a.active').click( function() {
		$(this).blur();
	});
	
});
