var data = [{
		'key': 'html5-net',
		'link': 'http://affiliate.manning.com/idevaffiliate.php?id=1207_281',
		'image': '/img/projects/html5-net.png',
		'title': 'HTML5 for .NET Developers',
		'tagline': '',
		'year': '2012',
		'roles': ['development', 'writing'],
		'mediums': ['book', 'javascript'],
		'description': 'An introduction to all the hot new goodness in the JavaScript world.',
		'featured': true
	}, {
		'key': 'vogue',
		'link': 'http://www.vogue.com/archive',
		'image': '/img/projects/vogue.png',
		'title': 'Vogue Archive',
		'tagline': '',
		'year': '2011',
		'roles': ['development'],
		'mediums': ['web', 'javascript', 'ipad'],
		'description': 'Desktop and iPad-optimized magazine web app, with over a century of fashion history.',
		'featured': true
	}, {
		'key': 'fathom',
		'link': 'http://www.letsfathom.com/',
		'image': '/img/projects/fathom.png',
		'title': 'Fathom',
		'tagline': '',
		'year': '2011',
		'roles': ['concept', 'design', 'development'],
		'mediums': ['web', 'javascript'],
		'description': 'A playful, immersive web app for exploring and discovering new music.',
		'featured': true
	}, {
		'key': 'rolling-stone',
		'link': 'http://www.rollingstone.com/allaccess',
		'image': '/img/projects/rolling-stone.png',
		'title': 'Rolling Stone All Access',
		'tagline': '',
		'year': '2011',
		'roles': ['development'],
		'mediums': ['web', 'javascript', 'ipad'],
		'description': 'Desktop and iPad-optimized magazine web app, with every issue since 1967.',
		'featured': true
	}, {
		'key': 'iplayboy',
		'link': 'http://i.playboy.com/',
		'image': '/img/projects/playboy.png',
		'title': 'iPlayboy',
		'tagline': '',
		'year': '2011',
		'roles': ['development'],
		'mediums': ['web', 'javascript', 'ipad'],
		'description': 'Desktop and iPad-optimized magazine web app, with every issue since 1953.',
		'featured': true
	}, {
		'key': 'interchange',
		'link': '/interchange/',
		'image': '/img/projects/interchange.png',
		'title': 'Interchange',
		'tagline': '',
		'year': '2011',
		'roles': ['concept', 'design', 'development'],
		'mediums': ['web', 'javascript'],
		'description': 'Music and book site navigation tool.',
		'featured': true
	}, {
		'key': 'panorama',
		'link': 'http://www.azarask.in/blog/post/designing-tab-candy/',
		'image': '/img/projects/firefox2.png',
		'title': 'Firefox Panorama',
		'tagline': '',
		'year': '2010',
		'roles': ['development', 'design', 'leadership'],
		'mediums': ['web', 'javascript', 'mac', 'windows', 'linux'],
		'description': 'Next-generation web navigation.',
		'featured': true
	}, {
		'key': 'chris-jordan',
		'link': 'http://chrisjordan.com/',
		'image': '/img/projects/chrisjordan.png',
		'title': 'Chris Jordan',
		'tagline': '',
		'year': '2010',
		'roles': ['development'],
		'mediums': ['web', 'javascript', 'silverlight'],
		'description': 'Portfolio site for for the artist Chris Jordan, with zooming galleries.',
		'featured': true
	}, {
		'key': 'snapdragon',
		'link': '/projects/snapdragon/',
		'image': '/img/projects/snapdragon.png',
		'title': 'Snapdragon',
		'tagline': 'immersive photo explorer',
		'year': '2009',
		'roles': ['concept', 'design', 'development'],
		'mediums': ['web', 'javascript'],
		'description': 'An organic, immersive way to explore Flickr photos.  Dive from photo to tag to photo seamlessly.',
		'featured': false
	}, {
		'key': 'infinite-canvas',		
		'link': 'http://infinitecanvas.jgate.de',
		'image': '/img/projects/infinitecanvas.png',
		'title': 'Infinite Canvas',
		'tagline': 'elegant comic viewer',
		'year': '2009',
		'roles': ['concept', 'design', 'development'],
		'mediums': ['web', 'javascript'],
		'description': 'An elegant environment for creating and viewing comics unconstrained by page boundaries, inspired by Scott McCloud\'s vision of an infinite canvas.',
		'featured': true
	}, {
		'key': 'gimme-shiny',
		'link': 'http://gimmeshiny.com',
		'image': '/img/projects/shiny.png',
		'title': 'Gimme Shiny',
		'tagline': 'hip pix slideshow',
		'year': '2008',
		'roles': ['concept', 'design', 'development'],
		'mediums': ['web', 'javascript'],
		'description': 'A JavaScript slideshow of today\'s popular images from Flickr and deviantART, as well as the most recent images on FFFFOUND.',
		'featured': true
	}, {
		'key': 'clockwork-goldfish',
		'link': 'http://clockworkgoldfish.com',
		'image': '/img/projects/fish.png',
		'title': 'Clockwork Goldfish',
		'tagline': 'puzzle game community',
		'year': '2008',
		'roles': ['design', 'development'],
		'mediums': ['web', 'javascript'],
		'description': 'A community for creating and playing original puzzles.  So far just one puzzle type (Figure Ground) can be made, with more to come.',
		'featured': true
	}, {
		'key': 'photosynth',
		'link': 'http://photosynth.net/',
		'image': '/img/projects/photosynth.png',
		'title': 'Photosynth',
		'tagline': '3D photo viewer',
		'year': '2006',
		'roles': ['design', 'development'],
		'mediums': ['web', 'silverlight', 'windows'],
		'description': 'A novel, 3-dimensional way to explore photography.'
	}, {
		'key': 'thoughtsam',
		'link': 'http://thoughtsam.iangilman.com/',
		'image': '/img/projects/thoughtsam.png',
		'title': 'Thoughtsam',
		'tagline': '',
		'year': '2006',
		'roles': ['writing'],
		'mediums': ['web'],
		'description': 'Random thoughts and story snippets.',
		'featured': true
	}, {
/*
		'key': 'micropatronage',	
		'link': 'http://micropatronage.org/',
		'image': '/img/projects/micropatronage.png',
		'title': 'Micopatronage.org',
		'tagline': '',
		'year': '2005',
		'roles': ['writing'],
		'mediums': ['web'],
		'description': 'A wiki meant to facilitate greater awareness and usage of micropatronage as a viable economic medium. ',
		'featured': false
	}, {
*/
		'key': 'seadragon',
		'link': 'http://seadragon.com/',
		'image': '/img/projects/seadragon.png',
		'title': 'Seadragon',
		'tagline': 'data navigation system',
		'year': '2005',
		'roles': ['leadership', 'design', 'development', 'community'],
		'mediums': ['web', 'javascript', 'silverlight', 'windows', 'iphone'],
		'description': 'Buttery smooth zooming on extremely large images.',
		'featured': false
	}, {
		'key': 'enabler',
		'link': 'http://www.pypeline.com/',
		'image': '/img/projects/enabler.png',
		'title': 'Enabler',
		'tagline': 'rich media player',
		'year': '2004',
		'roles': ['leadership', 'development'],
		'mediums': ['mac', 'windows'],
		'description': 'A rich media player, now in private beta.'
	}, {
		'key': 'wiitl',
		'link': 'http://www.youtube.com/watch?v=A3tjAGHWPGA',
		'image': '/img/projects/wiitl.png',
		'title': 'What if in This Life',
		'tagline': '',
		'year': '2004',
		'roles': ['production', 'editing'],
		'mediums': ['video'],
		'description': 'Short film, directed by Otis Mannick.', 
		'featured': true
	}, {
		'key': 'split-second',
		'link': 'http://www.youtube.com/watch?v=XvJIZqGvnQ4',
		'image': '/img/projects/splitsecond.png',
		'title': 'Split Second',
		'tagline': '',
		'year': '2002',
		'roles': ['photography', 'editing'],
		'mediums': ['video'],
		'description': 'Short film, directed by Ricardo Madrazo.'
	}, {
		'key': 'highway',
		'link': 'http://www.youtube.com/watch?v=xCktrQ90-8Q',
		'image': '/img/projects/highway.png',
		'title': 'Highway',
		'tagline': '',
		'year': '2001',
		'roles': ['direction', 'photography', 'editing'],
		'mediums': ['video'],
		'description': 'Music video for West by God.'
	}, {
		'key': 'what-what',
		'link': 'http://www.youtube.com/watch?v=e5ELf9jg8gs',
		'image': '/img/projects/whatwhat.png',
		'title': 'What What',
		'tagline': '',
		'year': '2001',
		'roles': ['direction', 'photography', 'editing'],
		'mediums': ['video'],
		'description': 'Music video for The Rangers.'
	}, {
		'key': 'live365',
		'link': 'http://live365.com/',
		'image': '/img/projects/live365.png',
		'title': 'Live365',
		'tagline': 'internet radio community',
		'year': '2001',
		'roles': ['leadership', 'design', 'community'],
		'mediums': ['web'],
		'description': 'A pioneering community of streaming internet radio stations.'
	}, {
		'key': 'brycetalk',
		'link': '/software/brycetalk.html',
		'image': '/img/projects/brycetalk.png',
		'title': 'BryceTalk',
		'tagline': 'virtual artist community',
		'year': '1999',
		'roles': ['leadership', 'development', 'community'],
		'mediums': ['mac', 'windows'],
		'description': 'A beautiful chat client just for Bryce artists.'
	}, {
		'key': 'supergoo',
		'link': '/software/supergoo.html',
		'image': '/img/projects/supergoo.png',
		'title': 'SuperGoo',
		'tagline': 'image manipulation software',
		'year': '1998',
		'roles': ['development'],
		'mediums': ['mac'],
		'description': 'A fun image manipulation tool.'
	}, {
		'key': 'metasquares',
		'link': '/software/metasquares.html',
		'image': '/img/projects/msq.png',
		'title': 'MetaSquares',
		'tagline': 'online computer game',
		'year': '1997',
		'roles': ['leadership', 'development', 'design', 'community'],
		'mediums': ['mac', 'windows'],
		'description': 'Original online 2-player board game, designed by Scott Kim.'
	}, {
		'key': 'seize-the-day',
		'link': '/software/seizetheday.php',
		'image': '/img/projects/seizetheday.png',
		'title': 'Seize The Day',
		'tagline': 'living world calendar',
		'year': '1994',
		'roles': ['leadership', 'development'],
		'mediums': ['mac', 'windows'],
		'description': 'Calendar program with animated worlds that match the time and season.'
	}, {
		'key': 'heaven-earth',
		'link': '/software/heavenearth.php',
		'image': '/img/projects/he.png',
		'title': 'Heaven & Earth',
		'tagline': 'computer puzzle game',
		'year': '1991',
		'roles': ['leadership', 'development', 'design'],
		'mediums': ['mac', 'windows'],
		'description': 'A collection of original puzzles and games.'
	}, {
		'key': 'ishido',
		'link': '/software/ishido.php',
		'image': '/img/projects/ishido.png',
		'title': 'Ishido',
		'tagline': 'computer puzzle game',
		'year': '1989',
		'roles': ['development'],
		'mediums': ['mac', 'windows'],
		'description': 'An original solitaire tile game.'
	}
];

//-------------------------------------------------------------
function loadProjects() {
	var count; 
	var a; 
	var bCount;
	var b;
	var cCount;
	var c;
	var tags;
	var tag;
	var roleList = [];
	var mediumList = [];
	var html;
			
	count = data.length;
	for(a = 0; a < count; a++) {
		// ___ See if there are any new mediums to add to the list
		var mediums = data[a].mediums;
		if(mediums) {
			jQuery.each(mediums, function(key, value) {
				if(jQuery.inArray(value, mediumList) == -1)
					mediumList.push(value);
			});
		}
		
		// ___ See if there are any new roles to add to the list
		var roles = data[a].roles;
		if(roles) {
			jQuery.each(roles, function(key, value) {
				if(jQuery.inArray(value, roleList) == -1)
					roleList.push(value);
			});
		}
	}

	// ___ Spit out medium list	
	mediumList.sort();
	count = mediumList.length; 
	for(a = 0; a < count; a++) {
		medium = mediumList[a];
		html = '<div><a href="#" onclick="limitProjects(\'mediums\', \''
			+ medium
			+ '\'); return false">'
			+ medium
			+ '</a></div>';
			
		$(html).appendTo('#mediums');
	}

	// ___ Spit out role list
	roleList.sort();	
	count = roleList.length; 
	for(a = 0; a < count; a++) {
		role = roleList[a];
		html = '<div><a href="#" onclick="limitProjects(\'roles\', \''
			+ role
			+ '\'); return false">'
			+ role
			+ '</a></div>';
			
		$(html).appendTo('#roles');
	}
	
	// ___ load up the main list
	var handled = false;
	var hash = getHash();
	if(hash) {
		var parts = hash.split('=');
		if(parts.length == 2) {
			var type = parts[0];
			if(type == 'mediums' || type == 'roles') {
				if(limitProjects(type, parts[1]))
					handled = true;
			}
		} else {
			if(limitProjects('mediums', hash) || limitProjects('roles', hash))
				handled = true;
		}
	}
	
	if(!handled)
		showAllProjects();			 
}

//-------------------------------------------------------------
function getHash() {
	return document.location.hash.replace('#', '');
}

//-------------------------------------------------------------
function limitProjects(type, target) {
	var count; 
	var a; 
			
	$('#left-column').empty();

	var found = false;
	count = data.length;
	for(a = 0; a < count; a++) {
		var items = data[a][type];
		if(items) {
			if(jQuery.inArray(target, items) != -1) {		
				addProjectTo(a, '#left-column');
				found = true;
			}
		}
	}
	
	if(found)
		document.location.hash = target;
		
	return found;
}

//-------------------------------------------------------------
function showAllProjects() {
	var count; 
	var a; 
			
	$('#left-column').empty();

	count = data.length;
	for(a = 0; a < count; a++) 
		addProjectTo(a, '#left-column');

	if(getHash())
		document.location.hash = 'all';
}

//-------------------------------------------------------------
function addProjectTo(index, selector) {
	var item = data[index];
	var mediumCount = item.mediums.length;
	var mediumLabel = (mediumCount == 1 ? 'medium' : 'mediums');

	var roleCount = item.roles.length;
	var roleLabel = (roleCount == 1 ? 'my role' : 'my roles');
	
	var html = '<div class="project"><a href="'
		+ item.link
		+ '"><img src="' 
		+ item.image 
		+ '"></a><h1 style="display:inline"><a href="'
		+ item.link
		+'">'
		+ item.title 
		+ '</a></h1>, '
		+ item.year
		+ '<div class="project-description">'
		+ (item.description || item.tagline)
		+ '</div><div class="project-roles">'
		+ mediumLabel
		+ ': '
		+ item.mediums.join(', ')
		+ '</div><div class="project-roles">'
		+ roleLabel
		+ ': '
		+ item.roles.join(', ')
		+ '</div><div style="clear:both"></div></div>';
		
	$(html).appendTo(selector);
}
	
//-------------------------------------------------------------
function getRandomFeaturedProject() {
	var subset = [];
	var count = data.length;
	var a;
	for(a = 0; a < count; a++) {
		var item = data[a];
		if(item.featured)
			subset.push(a);
	}
	
	var index = Math.floor(Math.random() * subset.length);
	return subset[index];
}

//-------------------------------------------------------------
function getHTMLForProjectLinks(keys) {
	var html = "<ul>";
	$.each(keys, function(index, key) {
		$.each(data, function(index2, project) {
			if (project.key == key) {
				html += "<li><a href='"
					+ project.link
					+ "'>"
					+ project.title
					+ "</a></li>";
			}
		});
	});
	
	html += "</ul>";
	return html;
}
