var projects;

$(document).ready(function(){
	$('input[type=text]').focus(function(){
		if ($(this).val() == $(this).attr('defaultValue'))
		{
			$(this).val('');
		}
	});
	
	$('input[type=text]').blur(function(){
		if ($(this).val() == '')
		{
			$(this).val($(this).attr('defaultValue'));
		}
	});
	
	$('a.zoom').zoom({imageDir: '/images/zoom/'});
	
	$('.download a').click(trackDownload);
	
	$('#tumblr_controls').load(function(){
	  $(this).fadeIn();
	});
	
	$('#projects .project h3 a').live('mouseenter', showDescription).live('mouseleave', hideDescription);
	$('#project_filter a').click(filterProjects);
	projects = $('#projects .project').clone();
});


function trackDownload(event)
{
	 _gaq.push(['_trackEvent', 'Downloads', $(this).attr('href')]);
	
	return true;
}


function showDescription(event)
{
  $(this).parents('.project').find('div').fadeIn(); //css({left: relativeX, top: relativeY}).fadeIn();
}


function hideDescription(event)
{
  $(this).parents('.project').find('div').hide();
}


function filterProjects()
{
  $('#project_filter a.selected').removeClass('selected');
  $(this).addClass('selected');
  
  var type = $(this).attr('rel');
  
  if (type == 'all')
  {
    $('#projects').quicksand(projects, {attribute: 'id'});
  }
  else
  {
    $('#projects').quicksand(projects.filter('.' + type), {attribute: 'id'});
  }
  
  return false;
}