$(function() {
/*$('a[rel=external]').attr('target', '_blank'); */

/**
 * section should be a string with an id, e.g. '#portfolio'
 */
function activateSection(section) {
	$(section).siblings('section').removeClass('active')
	 .end()
	 .addClass('active')
	 .find('a.show_more').removeClass('show_more').addClass('hide_more').text('hide')
	 .end()
	 .find('div.additional').slideDown();
}
/**
 * section should be a string with an id, e.g. '#portfolio'
 */
function deactivateSection(section) {
	$(section)
	 .find('a.hide_more').addClass('show_more').removeClass('hide_more').text('more')
	 .end()
	 .find('div.additional').slideUp('', function() { 
		$(this).parent().removeClass('active'); 
	 });
}
/* hide lots of content, add show more button */
$('section.column')
 .find('div.additional').hide()
 .end()
 .each(function() {
	$('<a href="#'
	 + $(this).attr('id') 
	 + '" class="show_more">more</a>').insertBefore($(this).find('h2'));
 })
 .delegate('a.show_more', 'click', function() { /* this = a.show_more */
	var section = $(this).parent();
	_gaq.push(['_trackEvent', 'show_more', 'clicked', section.attr('id')]);	
	activateSection(section);
	return false;
 })
 .delegate('a.hide_more', 'click', function() { /* this = a.hide_more */
	var section = $(this).attr('href');
	$.scrollTo('#everything', 1000, { onAfter: deactivateSection(section) });
	return false;
 });

/* nav: add tracking, add active class to correct section */
$('#sections').find('a[rel=section]').click(function() {
	_gaq.push(['_trackEvent', 'navigation', 'clicked', $(this).attr('id')]);
	var section = $(this).attr('href');
	if (!$(section).hasClass('active')) {
		activateSection(section);
	}
	$.scrollTo('nav', 1000);
	return false;
});

/* back to top */
$('#back_to_top').click(function() {
	$.scrollTo('#everything', 1000);
	return false;
});

/* tooltips */
$('#nav_contact').add('#hokuten').add('#networks .linkedin a').tinyTips('dark', 'title');

/* portfolio: tracking and thumbnails */
$('#portfolio').find('div.project').find('div').first().find('a.thumb').colorbox({
	onOpen: function() {
		_gaq.push(['_trackEvent', 'portfolio', 'clicked', $(this).attr('id')]);
		//console.log($(this));
	}
});

});

twttr.anywhere(function (T) {
	T("#networks .twitter a").hovercards({ username: function(node) { return node.title; } });
});