$(document).ready(function()
{
	// custom externals selector
	$.expr[':'].external = function(obj)
	{
    if(obj.href == '')
    {
      return false;
    }
        
    return !obj.href.match(/^mailto\:/)
      && (obj.hostname != location.hostname)
      && $(obj).children().length == 0
	};
	
	$("a:external").addClass('external');
    
  $("#news-scroller").scrollable({ next: "#news-next", prev: "#news-prev", speed: 200, onSeek: checkNewsHeight }).navigator();
  $("#tweets-scroller").scrollable({ next: "#tweets-next", prev: "#tweets-prev", speed: 200, onSeek: checkTweetsHeight }).navigator();

  checkNewsHeight(null, 0);    
  checkTweetsHeight(null, 0);
  
  // homepage slideshow
  $('.slideshow').cycle({ fx: 'scrollLeft', timeout: 6000 });
  
  // photostream lightbox
  $("a[rel^='prettyPhoto']").prettyPhoto();
  
  // now hide bandcamp player when lightbox is visible
  $("a[rel^='prettyPhoto']").click(function()
  {
    $('#player').toggle(!$('div.pp_pic_holder').is(':visible'));
  });
  
  // add some tracking to links to external sites
  $("a[href^='http']").click(function()
  {
  	pageTracker._trackEvent("links", "External Links", $(this).attr("href"), 0);
  });    
});

function checkTweetsHeight(e, index)
{
	var container_height =  $('#tweets-scroller').height();
	var content_height   = $('#tweets-scroller li').eq(index).height();
	
	$('#tweets-scroller').animate({ 'height': content_height + 10 }, 100);
}

function checkNewsHeight(e, index)
{
	var container_height =  $('#news-scroller').height();
	var content_height   = $('#news-scroller li').eq(index).height();
	
	$('#news-scroller').animate({ 'height': content_height + 10 }, 100);
}
