if (window.console === undefined) { window.console = { log: function() {} }; }	
	
	
	// First, define our "Snapper" object -> 
	// this holds variables and functions relevant to the projects description snapping
	var Snapper = 
	{
		// Vars
		projects: [], // all projects
		offsetRight: 0, // project wrapper offset
		limitTop: 100, // fixed nav offset
		
		// Init Snapper
		init: function() 
		{
			// Image load events - fix for webkits weird DOM rendering
			$("article.project img").load(Snapper.load);
			// Bind window interactions / events
			$(window).bind("scroll", Snapper.check).bind("resize", Snapper.respond).trigger("resize");
		},
		
		// Debounce the loading, reduces "build" calls
		load: function()
		{
			// Set timer for "build" call
			$.doTimeout("SnapperLoad", 100, Snapper.build);
		},
		
		// Build the project listing
		build: function() 
		{
			// Reset the project array
			Snapper.projects = [];
			// Loop through and cahce all relevent data
			$("article.project").each(function() {
				var target = $(this); // project el
				var description = target.find(".description"); // description el
				var offset = target.offset(); // project offset
				var id = target.attr("id"); // project id
				var top = offset.top - Snapper.limitTop; // actual top, takes into account the fixed nav bar
				var height = target.outerHeight(); // project height
				var descriptionHeight = description.outerHeight(true); //description height
				var limit = top + height - descriptionHeight; // limit for when to snapp to bottom
				
				// push project to array
				Snapper.projects.push({
					_article: target, //im using "_" to prefix actuall jquery elements
					_description: description,
					id: id, //the rest of these are just numeric/string/bool values
					top: top,
					height: height,
					descriptionHeight: descriptionHeight,
					limit: limit,
					isActive: false //not active yet
				});
			});
			$(window).trigger("scroll");
		},
		
		// Check each project on scroll
		check: function()
		{
			var scrolltop = $(window).scrollTop(); // scroll position
			for(var i in Snapper.projects)
			{
				//console.log(scrolltop, Snapper.projects[i].top, Snapper.projects[i].limit);
				// Project in view?
				// if the top of the project is above the browser window
				// and the bottom of the project is below the project's limit
				if(scrolltop > Snapper.projects[i].top && scrolltop < Snapper.projects[i].limit)
				{
					Snapper.projects[i].isActive = true;
					Snapper.projects[i].isPassed = false;
					Snapper.projects[i]._article.removeClass("bottom").addClass("active");
					Snapper.projects[i]._description.css({ right: Snapper.offsetRight });
				}
				// Project passed view?
				// if the scroll position has passed the project's limit
				else if(scrolltop > Snapper.projects[i].limit)
				{
					Snapper.projects[i].isActive = false;
					Snapper.projects[i].isPassed = true;
					Snapper.projects[i]._article.removeClass("active").addClass("bottom");
					Snapper.projects[i]._description.attr("style", "");
				}
				else
				{
					// Only remove classes if we need to - reduces calls to the DOM
					if(Snapper.projects[i].isActive || Snapper.projects[i].isPassed)
					{
						Snapper.projects[i].isActive = false;
						Snapper.projects[i].isPassed = false;
						Snapper.projects[i]._article.removeClass("active bottom");
						Snapper.projects[i]._description.attr("style", "");
					}
				}
			}
		},
		
		// Respond to window resize event
		respond: function()
		{
			// calculate new description offset
			var offset = $("#work-container").offset();
			Snapper.offsetRight = $(window).width() - ($("#work-container").width() + offset.left);
			// If an active project is found, reset it's offset
			$("article.project.active .description").css({ right: Snapper.offsetRight });
		}
		
	}
	
	// Moved web font loading into js -> special events on font load
	// WEB FONTS
	var WebFontConfig = { 
		typekit: {
			id: "rcv2luc"
		},
		loading: function() {
			//console.log("WF: LOADING");
		},
		fontloading: function(fontFamily, fontDescription) {
			//console.log("WF: FONT LOADING: " + fontFamily);
		},
		fontactive: function(fontFamily, fontDescription) {
			//console.log("WF: FONT ACTIVE: " + fontFamily);
		},
		fontinactive: function(fontFamily, fontDescription) {
			//console.log("WF: FONT INACTIVE: " + fontFamily);
		},
		active: function() {
			//console.log("WF: ACTIVE");
		},
		inactive: function() {
			//console.log("WF: INACTIVE");
		}
	};
	
	
	// Init after declaring everything, otherwise we get weird errros
	$(document).ready(function() {
		Snapper.init();

        // Scroll the whole document
        $('#nav-container').localScroll({
    			offset: { top: -100}   
				 });
		
		    $('#footer-nav').localScroll({});
	});
	
	

// Do timeout is awesome, can't recomment it enough. So many uses for the different timing functions.
/*
 * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
 * http://benalman.com/projects/jquery-dotimeout-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);
	
