$( function() {
	$('#hero .menu a').click( function() {
		if( !$(this).parent().hasClass('selected') ) {
			$(this).parent().addClass('selected').siblings('.selected').removeClass('selected');
			$('#hero .section.selected').removeClass('selected').show().slideUp();
			$('#hero .section').filter( $(this).attr('href') ).addClass('selected').hide().slideDown();			
		}
		return false;
	});
	
	$('a[href^="#"]').click(function() {
		if (this.hash != '#hero-what' && 
		this.hash != '#hero-how' &&
		this.hash != '#hero-services' && 
		this.hash != '#hero-team' ) {
			$("html, body").animate({
				scrollTop: $($(this).attr("href")).offset().top + "px"
			}, {
				duration: 500,
				easing: "swing"
			});
			return false;
		}
	});
	
	if (document.getElementById('sidebar')){
	var top = $('#sidebar').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/,0));
	$(window).scroll(function (event) {
		// what the y position of the scroll is
		var y = $(this).scrollTop();

    	// whether that's below the form
    	if (y+20 >= top) {
      		// if so, ad the fixed class
      		$('#sidebar').addClass('fixed');
    	} else {
      		// otherwise remove it
      		$('#sidebar').removeClass('fixed');
    	}
	});
	}
});
