var projects = [{
		name: "easyjerk",
		type: "website",
		link: "http://easyjerk.com/",
		status: "active",
		progress: "live",
		venue: "self/originate",
		description: "a new interface for watching porn",
		image: "/img/duck.500.png"
	}, 
	{
		name: "starglue",
		type: "website",
		link: "http://starglue.com/",
		progress: "live",
		status: "inactive",
		venue: "self",
		description: "a place for all types of artists to follow eachothers work",
		collaborators: ["billy"],
		image: "/img/logo.500.png"
	},
	{
		name: "Word Merge",
		type: "website/app",
		link: ["http://www.werdmerge.com/", "http://www.wordmergeapp.com/"],
		progress: "live",
		status: "intermittant",
		venue: "self",
		collaborators: ["harold", "toby"],
		description: "a portmanteau generator using phonemes",
		image: "/img/werdmerge.icon.noback.png"
	},
	{
		name: "MadPattern",
		type: "website/plugin/art",
		link: ["http://www.madpattern.com/", "http://www.society6.com/madpattern", "http://www.flickr.com/photos/matthandler/sets/72157617282135023/"],
		progress: "live",
		status: "intermittant",
		venue: "self",
		description: "a free tool for rapidly prototyping patterns",
		image: "http://www.madpattern.com/microdefender.of.salt.share.png"
	},
	{
		name: "six degrees",
		type: "website",
		link: "http://sixdegrees.herokuapp.com/",
		progress: "alpha",
		status: "active",
		venue: "self",
		description: "a graph navigation game using movies and actors"
	},
	{
		name: "jsonX",
		type: "js library",
		link: "https://github.com/matthandlersux/jsonX",
		progress: "alpha",
		status: "active",
		venue: "self",
		description: "a port of xpath applied to json"
	},
	{
		name: "framethrower",
		type: "website/application",
		link: "https://github.com/matthandlersux/framethrower",
		progress: "beta",
		status: "dead",
		venue: "earl industries",
		description: "a tool for annotating stories in movies",
		collaborators: ["harold", "toby", "ted"]
	},
	{
		name: "The WeaponSmith",
		type: "website",
		link: "http://weaponsmith.tumblr.com/",
		progress: "live",
		status: "active",
		venue: "self",
		description: "a weaponshop tumblr where ian draws new weapons daily",
		collaborators: ["ian"],
		image: "/img/weaponsmith.jpg"
	},
	{
		name: "WikiMaze",
		type: "website/app",
		link: "http://wikimaze.me/",
		progress: "live",
		status: "active",
		venue: "self",
		description: "trivia game with dynamically generated questions from wikipedia",
		collaborators: ["ben"],
		image: "/img/mzm.noodtxda.png"
	},
	{
		name: "What Movie Should We See???",
		type: "website",
		link: "http://whatmovieshouldwesee.com/",
		progress: "live",
		status: "intermittant",
		venue: "self",
		description: "a site that helps you figure out exactly which movie you want to see in theaters",
		image: "/img/fb.share.png"
	},
	{
		name: "Restaurantology",
		type: "website",
		link: "http://rtology.com/",
		progress: "live",
		status: "intermittant",
		venue: "self",
		description: "look up restaurants similar to ones you love",
		collaborators: ["ron"],
		image: "http://rtology.com/logo.512.png"
	},
	{
		name: "PicCast",
		type: "app",
		link: "http://piccastapp.com/",
		status: "inactive",
		progress: "beta",
		venue: "self",
		description: "rss feeds for rss feeds, absorbing information without reading",
		collaborators: ["brian"],
		image: "/img/PicCast.512.noback.png"
	},
	{
		name: "epornreview",
		type: "website",
		link: "http://www.epornreview.com/",
		status: "abandoned",
		progress: "live",
		venue: "self",
		description: "a porn review website that specializes in indexing the models and sites they appear on",
	},
	{
		name: "hilight.us",
		link: "http://hilight.us/",
		image: "http://hilight.us/hilight.us.logo.trans.512.png",
		type: "website/bookmarklet",
		status: "intermittant",
		progress: "alpha",
		collaborators: ["harold"],
		description: "a syntax highlighter for english",
		venue: "self"		
	},
	{
		name: "Figure Drawings",
		type: "art",
		link: [
			"http://www.flickr.com/photos/matthandler/sets/72157610674134542/",
			"http://www.flickr.com/photos/matthandler/sets/72157623457965106/"
		],
		status: "inactive",
		progress: "",
		description: "pencil/charcoal drawings, mostly from my time living in boston",
		venue: "self",
		image: "/img/figure.drawing.jpg"
	},
	{
		name: "Paintings",
		type: "art",
		link: [
			"http://www.flickr.com/photos/matthandler/collections/72157623498160476/"
		],
		status: "inactive",
		progress: "student",
		venue: "self",
		image: "/img/paintings.jpg",
		description: "mostly oil paintings. many of the portraits are from highschool."
	},
	{
		name: "Vector Illustrations",
		type: "art/digital art",
		link: [
			"http://www.flickr.com/photos/matthandler/sets/72157610674152652/", 
			"http://www.society6.com/madpattern",
			"http://www.flickr.com/photos/matthandler/sets/72157614140204223/"
		],
		status: "active",
		progress: "",
		description: "various characters/illustrations. heavily inspired by david lanham.",
		venue: "self",
		image: "/img/vector.illustration.jpg"
	}
	
	/*
	{
		name: "Sketches",
		type: "art",
		link: [
			"http://www.flickr.com/photos/matthandler/collections/72157624944298933/"
		],
	},
	{
		name: "Projection",
		type: "art",
		link: "http://www.flickr.com/photos/matthandler/sets/72157624193428230/",
	},
	{
		name: "HeetMap"
	},
	{
		name: "candy coding"
	},
	{
		
	}
	*/
	],
	collaborators = {
		brian: {
			name: "brian newbold",
			link: "http://web.mit.edu/bnewbold/www/",
			blurb: "friend from mit, lives in ny, programmer/crazy, works at octopart"
		},
		ron: {
			name: "ron feldman",
			link: "http://ronsfeldman.com/",
			twitter: "ronfeldman",
			blurb: "friend from ny, entrepreneur"
		},
		ted: {
			name: "ted goranson",
			link: "http://www.filmsfolded.com",
			blurb: "project visionary from framethrower, lives in va, abstractionist/story enthusiast"
		},
		harold: {
			name: "harold cooper",
			twitter: "hrldcpr",
			link: "http://syzygy.st/",
			blurb: "friend from mit, lives in ny, programmer/musician, works at hunch"
		},
		toby: {
			name: "toby schachman",
			twitter: "mandy3284",
			link: "http://www.sundialtone.com/",
			blurb: "friend from mit, lives in ny, programmer/artist, student at itp"
		},
		ian: {
			name: "ian densford",
			twitter: "weaponsmithy",
			link: "http://www.iandensford.com/",
			blurb: "friend from highschool, lives in ny, artist"
		},
		ben: {
			name: "ben gleitzman",
			twitter: "gleitz",
			link: "http://gleitzman.com/",
			blurb: "friend from ny, lives in sf, programmer, works at hunch"
		},
		billy: {
			name: "billy arzt",
			twitter: "billyarzt",
			link: "http://www.linkedin.com/pub/william-arzt/7/4b2/14b",
			blurb: "friend from highschool, lives in ny, cofounder on starglue"
		}
	},
	tags = {},
	progress = ["live", "", "finished", "beta", "student", "alpha", "idea"],
	status = ["active", "intermittant", "inactive", "abandoned", "dead"],
	jClass = function (name) { return $("<div></div>").addClass(name); },
	jId = function (name) { return $("<div></div>").attr("id", name); },
	drawLink = function (link, name) {
		name = name || link;
		return jClass("link").append("&#8250;").append( $("<a href='"+link+"' target='_new'>"+name+"</a>") );
	},
	drawDescription = function (d) {
		return jClass("description").text(d);
	},
	drawTag = function (data, div) {
		var ts = [],
			tagClick = function (name) {
				return function () {
					var tag = $(this);
					tag.siblings().removeClass("selected");
					
					$.each(projects, function (i,e) {
						e.div.show();
					});

					if (tag.hasClass("selected")) {
						tag.removeClass("selected");
					}
					else {
						tag.addClass("selected");
						$.each(projects, function (i,e) {
							e.div.hide();
						});
						$.each(tags[name], function (i,e) {
							e.show();
						});
					}
				}
			};
			
		ts.push(data.status);
		ts.push(data.progress);
		$.each(data.type.split("/"), function (i,e) {
			ts.push(e);
		});
		
		$.each(ts, function (i,e) {
			if (tags[e]) tags[e].push(div) 
			else {
				tags[e] = [div];
				$("#tags").append( jClass("tag").text(e).click(tagClick(e)) );
			}
		});		
	},
	drawProject = function (p) {
		var shadow = jClass("shadow"),
			div = jClass("project").appendTo(shadow),
			top = jClass("top").appendTo(div),
			image = $("<img/>").attr("src", p.image || "").hide().appendTo(div),
			name = jClass("name title").html("<span>&#8285;</span>"+p.name).appendTo(top),
			status = jClass("status").attr("title", p.status).addClass(p.status).appendTo(top),
			type = jClass("type").text(p.type).appendTo(top),
			info = jClass("info").appendTo(div);
		
		if (p.image) image.show().addClass("visible");
		
		// info.append("<label>info</label>");
		typeof p.link == "string" ? info.append( drawLink(p.link) ) : $.each(p.link, function (i,e) {
			info.append( drawLink(e) );
		});
		
		if (p.description) info.append( drawDescription(p.description) );
		if (p.collaborators) info.append( drawCollaborators(p.collaborators) );
		
		div.append(jClass("clear"));
		
		drawTag(p, shadow);
		
		p.div = shadow;
		return shadow;
	},
	drawCollaborators = function (c) {
		var cs = jClass("collaborators"),
			label = $("<label/>").text("collaborators").appendTo(cs),
			drawCollaborator = function (c) {
				var div = jClass("collaborator"),
					name = jClass("name").append(drawLink(c.link, c.name)).appendTo(div);
					
				if (c.twitter) 
					jClass("twitter")
						.append("<a href='http://twitter.com/"+c.twitter+"' target='_new'>@"+c.twitter+"</a>")
						.appendTo(div);
						
				if (c.blurb) jClass("blurb").text(c.blurb).appendTo(div);
				
				return div;
			};

		$.each(c, function (i,e) { cs.append(drawCollaborator(collaborators[e])); });
		return cs;
	};

$(function () {
	var main = $("#main");
	
	projects.sort(function (a, b) {
		as = status.indexOf(a.status);
		bs = status.indexOf(b.status);
		if (as != bs) return as < bs ? -1 : 1;
		else {
			var ap = progress.indexOf(a.progress),
				bp = progress.indexOf(b.progress);
			return ap < bp ? -1 : 1;
		}
	});
	
	for (var i = 0; i < projects.length; i++) {
		main.append( drawProject(projects[i]) );
	}
	
	var timer;
	$("header h1").hover(function () {
		$("#more").animate({top: 38});
	}, function () {
		timer = setTimeout(function () {
			$("#more").stop().animate({top: -25});
		}, 1000);
	});
	
	$("#more").hover(function () {
		clearTimeout(timer);
		$("#more").stop().animate({top: 38});
	}, function () {
		$("#more").stop().animate({top: -25});
	})
});
