var currentThemeSelector = $('person-austin');
var switcher;
var counter = null;
var toggleSwitch = {};
var themes;
var fragment = document.location.hash.substr(2).split('/');
pages = $H({
   lost: {
		title: "Are you lost?",
	} 
});
projects = $H({
	prisma: {
		shortname: "pris.ma", 
		name: 			'Pris.ma, simple file-sharing for everyone',
		description: 	'<p>It doesn\'t matter if you\'re on-campus or off. If you\'re trying to send a tiny file or a larger one &mdash; If you\'re trying to send anything to anyone, you can do it here. <a class="person-site" target="_blank" href="http://pris.ma">pris.ma</a></p>',
		image:          'images/projects/prisma.png',
		href: "http://pris.ma", 
	},
	snackbot: {
		shortname: "Snackbot", 
		name: "Snackbot, a mobile robot system", 
		description: "<p>Snackbot is a mobile robot, about the size of a very small human, that rolls around on wheels, and will be delivering snacks to students, faculty, and office workers at <a href='http://cmu.edu' alt='Carnegie Mellon'>Carnegie Mellon University</a>. Participants include: <a href='/#/people/josh' class='internal'>Josh</a> and <a href='/#/people/austin' class='internal'>Austin</a>.</p>.",
		image: "images/projects/snackbot.png",
		href: "http://snackbot.org", 
		
	}
});

people = $H({
	austin: {
		name: 'Austin Robert Bales', 
		bio: 		'<p>Originally from Washington, D.C., Austin specializes in creating websites and interactions in the digital realm. The founder of 417east, Austin has been designing since he was 12-years old and also practices industrial design, photography, and graphic design.<a class="person-site" target="_blank" href="http://austinbales.com">austinbales.com</a></p>',
		headshot:	'images/headshots/austin.jpg',	
		href: 'http://austinbales.com',
		sample: 'images/microfolio/austin.jpg',
		sampleText: '<p>This material and form driven "Rewired Radio" keeps the technology in the background for a more peaceful life</p>'
		},
	jason: {
		name: 'Jason May',
		bio: '<p>Hailing from Mt. Lebanon outside Pittsburgh, Jason created precisely crafted objects of many materials - and his talent with wood is remarkable. Right now he\'s working at the <a href="http://www.letterthirteen.com/">Letter Thirteen</a> design agency, creating models, illustrations, and mockups for products and environments.<a class="person-site" target="_blank" href="http://jason-may.com">jason-may.com</a></p>',
		headshot:	'images/headshots/jason.jpg',	
		href: 'http://jason-may.com',
		sample: 'images/microfolio/jason.jpg',
		sampleText: '<p>A selection of Jason\'s recent drawings shows his talent with space and image. These were sketches done as precursors to animations.</p>'
		},
	josh:  {
		name: 'Josh Finkle',
		headshot: 'images/headshots/joshua.jpg',
		sample: 'images/microfolio/josh_duplex.jpg',
		sampleText: '<p>In this collabrative chess set, Josh designed a static bishop, a kinetic bishop, a static pawn, and a kinetic pawn. 2009.</p>',
		bio: '<p>Joshua, from Albany, is a jack-of-all trades. He\'s created robots for <a href="http://microsoft.com">Microsoft</a>, red wagons for <a href="http://radioflyer.com">Radioflyer</a> and has some amazing work in Industrial Design and drawing.<a class="person-site" target="_blank" href="http://jfinkle.com">jfinkle.com</a></p> ', 
		href: 'http://jfinkle.com',
	},
	vanessa: 	{
		name: 'Vanessa Koch',
		bio: 		'<p>Vanessa is a talented communication designer from Sandusky, Ohio. At <a href="http://www.troika.tv/">Troika</a> she helped make TNT\'s new look and MTVNHD\'s logo. Now at <a href="http://www.bluestatedigital.com/">Blue State Digital</a> she\'s making the world a better place through design.<a class="person-site" target="_blank" href="http://vanessakoch.com">vanessakoch.com</a></p>',
		headshot: 'images/headshots/vanessa.jpg',
		href: 'http://vanessakoch.com',
		sample: 'images/microfolio/vanessa.jpg',
		sampleText: '<p>Branding a city: Develop a strong and lasting identity for the city of Florence, Italy. Vanessa chose to portray Florence as a city “in full bloom,” welcoming modern innovation to grow from its classic roots.</p>'
	},
	youna: {
		name: 'Averie Youna Yang',
		headshot: 'images/headshots/youna.jpg',
		bio: '<p>Averie Youna is a wiz at process and execution. She\'s experienced the world: from Korea to Eindhoven; and her talents in Industrial Design focus on creating meaning and helping people of all walks of life. Right now she\'s helping <a href="http://intel.com">Intel</a> create robots, but who knows what she\'ll do next.</p>',
		href: '#',
		sample: 'images/microfolio/youna.jpg',
		sampleText: '<p>Youna and group members completed a bag for the Dockers brand\'s "San Francisco lifestyle" audience.'
	},
	jeremy: {
		name: 'Jeremy Wolf',
		bio:  '<p>Jeremy has a passion for interaction with simple, pure, and pleasant forms. At <a href="http://www.ihomeaudio.com/">iHome Audio</a>, he designed products for the iHOME brand. Now he\'s creating products to help and entertain people in the present and in the future.<a class="person-site" target="_blank" href="http://jeremy-wolf.com">jeremy-wolf.com</a></p>',
		headshot: 'images/headshots/jeremy.jpg', 
		href: 'http://jeremy-wolf.com',
		sample: 'images/microfolio/jeremy.jpg',
		sampleText: '<p>Jeremy designed a trashcan that <em>isn\'t</em> a pain to take out. A project for <a href="http://bayermaterialscience.com">Bayer Material Science</a>, 2009.'
	},
	alanna: {
		name: 'Alanna Schwartz',
		bio: '<p>Alanna is a talented thinker and chemist. Although she\'d likely deny it, she has talents across the spectrum &mdash; if you need advice on chemistry, biology, or even graphic design you can turn to her. Right now she\'s doing cancer research, but what will she think of next!?</p>',
		headshot: 'images/headshots/alanna.jpg',
		href: '#',
		sample: 'images/microfolio/alanna.jpg',
		sampleText: '<p>An illustration of a Polymerase Chain Reaction, from <a href="http://en.wikipedia.org">Wikipedia</a>, the free encyclopedia.</p>'
	},
	molly: {
		name: 'Molly Samuels',
		bio: '<p>Molly is a designer and information systematist. She\'s created books, databases, websites, and even makes awesome scarves and mittens in her spare time (so once or twice a year). Right now she\'s igniting code at <a href="http://curiositymedia.com">Curiosity Media</a>, and enjoying Boston. <a class="person-site" target="_blank" href="http://burntorangetea.com">burntorangetea.com</a></p>',
		headshot: 'images/headshots/molly.jpg',
		href: 'http://burntorangetea.com',
		sample: 'images/microfolio/molly.png',
		sampleText: '<p>Molly designed a developed a website for <a href="http://www.transitionsartgallery.com/">Transitions Art Gallery</a>. PHP/SQL/HTML/CSS.</p>'
	},
	joyce : {
		name: 'Joyce Kim',
		bio: '<p>Joyce\'s work lies in communication design and photography, and everything she does she does with flair. Right now she\'s working at <a href="http://www.lairdandpartners.com">Laird+Partners</a> in the big city, but if you\'re lucky she\'ll work for you someday.<a class="person-site" target="_blank" href="http://heavyfloats.com">heavyfloats.com</a>',
		headshot: 'images/headshots/joyce.jpg',
		href: 'http://heavyfloats.com',
		sample: 'images/microfolio/joyce.jpg',
		sampleText: '<p>The rise of Hipsterdom and the fall of the planet are inextricably linked. In this work, Joyce compares, contrasts, and visually links the two with skill and aesthetic grace.</p>'
	}
	
});


htmlCSS = "";

function scanForInternalLinks(){
	$$('.internal').each(function(s){
		s.observe('click', function(){
			initUIFromHash(this.href);
		});
	});
}

function updateFragment(fragment){
	document.location.hash = "/" + fragment;
	setTimeout(function() {
		scanForInternalLinks();
	}, 100); //NASTY!
	
}


function revealList(target){
		$$('#navigation li ul').each(function(s){
			if (s.id != 'list-'+target){
				Effect.BlindUp(s.id, { duration: .2 });
			}
				
		});
		
		if ($('list-'+target).style.display == 'none'){
			Effect.BlindDown('list-'+target, { 
				duration: .2,
			});
		}
		
		$('navigation').fire('list:loaded');
		
	
}

function hideAllInList(){
	$$('#navigation li ul').each(function(s){
			Effect.BlindUp(s.id, { duration: .2 });
	});
}

function revealNextElement(currentElement){
	e = currentElement.next();
	if (e.style.display == 'none')
		Effect.BlindDown(e, {duration: .2});
	
}



function initUIFromHash(_newFragment){	
	if (_newFragment != undefined){
		fragment = _newFragment.substr(21).split('/');
	}
	
	if (defaultLoad != undefined && defaultLoad != '' && fragment == ''){
		loadPage(defaultLoad);
	}
	else if (fragment[0] == 'people') {
		loadPerson(fragment[1]);
	} else if (fragment[0] == 'projects'){
		loadProject(fragment[1]);
	}	
}



function createModalWindow(options){
	if (options.text == undefined){
		throw('Modal windows cannot be initialized without content.');
	} else {
		windowContent = "<p id='mw_content'>" + options.text + "</p><p id='mw_buttons'>";
		if (options.buttonText != undefined && options.buttonCallback != undefined){
			windowContent += '<span id="mw_button_one" onclick="'+options.buttonCallback+'()">' + options.buttonText + '</span>';
		} else {
			windowContent += '<span id="mw_button_one" onclick="dismissModalWindow();">Close</span>';
		}
		
		if (options.button2Text == 'cancel'){ 
			windowContent += '<span id="mw_button_one">Nevermind</span>';
		} else if (options.button2Text != undefined){
			windowContent += '<span id="mw_button_one">' + options.button2Text + '</span>';
		} else {
		}
		windowContent += "</p>";
	}
	$('messaging').update(windowContent).show();
}

function dismissModalWindow(){
	$('messaging').update().hide();
}

function isValidPerson(name){
	if (people.get(name) != undefined){
		return true;
	} else {
		return false;
	}
}

function isValidProject(name){
	if (projects.get(name) != undefined){
		return true;
	} else {
		return false;
	}}

function loadPage(name){
	new Ajax.Updater('block-dynamic', 'block-'+name+'.html', {
		method: 'get',
		asynchronous:false,
	});
	
	document.title = "417east / " + pages.get(name)['title'];
	
	$('block-dynamic').removeClassName('_project').removeClassName('_person').addClassName('_page');	
}

function loadPerson(name){
	if (!isValidPerson(name)){
		return false;
	}
	
	if (!$('block-dynamic').hasClassName('_person')){
		new Ajax.Updater('block-dynamic', 'block-person.html', {
			method: 'get',
			asynchronous:false,
			onComplete: function(){
				doLoadPerson(name);
			}
		});
		$('block-dynamic').removeClassName('_project').removeClassName('_page').addClassName('_person');
	} else {
		doLoadPerson(name);
	}
}

function loadProject(name){
	if (!isValidProject(name)){
		return false;
	}
	if (!$('block-dynamic').hasClassName('_project')){
		new Ajax.Updater('block-dynamic', 'block-project.html', {
			method: 'get',
			asynchronous:false,
			onComplete: function(){
				doLoadProject(name);
			}
		});
		$('block-dynamic').removeClassName('_person').removeClassName('_page').addClassName('_project');
	} else {
		doLoadProject(name);
	}	
}

function doLoadPerson(name){
	new Effect.Parallel([
	  new Effect.Fade('person-name', { sync: true }), 
	  new Effect.Fade('person-bio', { sync: true, }),
	  //new Effect.BlindUp('person-headshot'),
	], { 
	  duration: 0.2,
	  beforeStart: function(){
		$('person-work-image').src = 'images/spinner.gif';
		},
	  afterFinish: function(){
			_person = people.get(name);
		   	document.title = "417east / " + _person['name'];
		
		
		new Effect.Parallel([
		  new Effect.Appear('person-name', { sync: true }), 
		  new Effect.Appear('person-bio', { sync: true }),
		  //new Effect.BlindDown('person-headshot'),
		 
		], { 
		  duration: 0.2,
		  beforeStart: function(){
				$('person-name').update(_person['name']);
				$('person-bio').update(_person['bio']);
				$('person-headshot').src = _person['headshot'];
				$('person-work-image').src = _person['sample'];
				$('person-work-text').update(_person['sampleText']);
	 	 },
		 afterFinish: updateFragment('people/'+name)
		
		});
		
	}
	});
}

function doLoadProject(name){
	new Effect.Parallel([
	  new Effect.Fade('project-name', { sync: true, mode: 'relative' }), 
	  new Effect.Fade('project-description', { sync: true, }) 
	], { 
	  duration: 0.2,
	  beforeStart: function(){
		$('project-image').src = 'images/spinner.gif';
		},
	  afterFinish: function(){
		
		
		new Effect.Parallel([
		  new Effect.Appear('project-name', { sync: true, mode: 'relative' }), 
		  new Effect.Appear('project-description', { sync: true, }) 
		], { 
		  duration: 0.2,
		  beforeStart: function(){
				_project = projects.get(name);
				document.title = "417east / Project • " + _project['name'];
			   	
				$('project-name').update(_project['name']);
				$('project-description').update(_project['description']);
				$('project-image').src = _project['image'] ;
		},
		 afterFinish: updateFragment('projects/'+name)
		
		});
		
	}
	});
}
