// Viewport plugin
(function($){$.belowthefold=function(element,settings){var fold=$(window).height()+$(window).scrollTop();return fold<=$(element).offset().top-settings.threshold;};$.abovethetop=function(element,settings){var top=$(window).scrollTop();return top>=$(element).offset().top+$(element).height()-settings.threshold;};$.rightofscreen=function(element,settings){var fold=$(window).width()+$(window).scrollLeft();return fold<=$(element).offset().left-settings.threshold;};$.leftofscreen=function(element,settings){var left=$(window).scrollLeft();return left>=$(element).offset().left+$(element).width()-settings.threshold;};$.inviewport=function(element,settings){return!$.rightofscreen(element,settings)&&!$.leftofscreen(element,settings)&&!$.belowthefold(element,settings)&&!$.abovethetop(element,settings);};$.extend($.expr[':'],{"below-the-fold":function(a,i,m){return $.belowthefold(a,{threshold:0});},"above-the-top":function(a,i,m){return $.abovethetop(a,{threshold:0});},"left-of-screen":function(a,i,m){return $.leftofscreen(a,{threshold:0});},"right-of-screen":function(a,i,m){return $.rightofscreen(a,{threshold:0});},"in-viewport":function(a,i,m){return $.inviewport(a,{threshold:0});}});})(jQuery);

// Shadowbox
Shadowbox.init({
	skipSetup: true
});
window.onload = function() {
    Shadowbox.setup(".item a", {
        gallery: "Portfolio",
        overlayOpacity: 0.9
    });
};

// Main functions
$(document).ready(function(){
	
	// Animate scrolling
	$('#nav a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $destination = $(this.hash);
			$destination = $destination.length && $destination || $('[name=' + this.hash.slice(1) +']');
			if ($destination.length) {
				var destinationOffset = $destination.offset().top;
				$('html,body').animate({scrollTop: destinationOffset}, 2000);
				return false;
			}
		}
	});
	
	// Floating navigation
	var msie6 = $.browser == 'msie' && $.browser.version < 7;
	if (!msie6) {
		var top = $('#nav').offset().top - parseFloat($('#nav').css('margin-top').replace(/auto/, 0));
		$(window).scroll(function (event) {
			var y = $(this).scrollTop();
			if (y >= top) {
				$('#nav').addClass('floating');
			} else {
				$('#nav').removeClass('floating');
			}
		});
	}
	
	// Navbar active class
	$(window).scroll(function () {
		var inview = '#' + $(".section:in-viewport:first").attr('id');
		var $link = $('#nav ul li a').filter('[hash=' + inview + ']');
		var active = $link.is('.active');
		if ($link.length && !active) {
			$('#nav ul li a').removeClass('active');
			$link.addClass('active');
		}
	});
	
});



