$(function() {
  $('a[rel="external"]').each(function() {
    $(this).attr('target', '_blank')
  });
});
// fade out instructions and error messages
$(function() {
  $('#instructions').fadeOut(8000)
  if (document.getElementById('errors') && $('#errors').hasClass('fade')) {
    $('#errors').fadeOut(8000)
  }
});
// hide form labels on focus
$(function() {
  $('input[type=text], textarea').focus(function() {
    if ($(this).hasClass('inline-label')) {
      if (typeof $(this).attr('rel') == 'undefined') {
        $(this).attr('rel', $(this).attr('value'))
      }
      if ($(this).attr('value') == $(this).attr('rel')) {
        $(this).attr('value', '')
      }
    }
  })
  $('input[type=text], textarea').blur(function() {
    if ($(this).hasClass('inline-label')) {
      if ($(this).attr('value') == '') {
        $(this).attr('value', $(this).attr('rel'))
      }
    }
  })
});
// Google Analytics - track downloads and external links
$(function() {
  $('a').click(function() {
    if ($(this).get(0).protocol == 'mailto:') {
      pageTracker._trackPageview('/mailto/' + $(this).attr('href').substring(7))
    } else if ($(this).get(0).hostname == location.host) {
      var path = $(this).get(0).pathname + $(this).get(0).search
      var isDoc = path.match(/\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/)
      if (isDoc) {
        trackPageView($(this).get(0), 'downloads')
      }
    } else {
      trackPageView($(this).get(0), 'external')
    }
  });
});
trackPageView = function(link, tag) {
  var page = (link.pathname.charAt(0) == "/") ? link.pathname : "/" + link.pathname
  if (link.search && link.pathname.indexOf(link.search) == -1) page += link.search
  if (link.hostname != location.host) page = '/' + tag + '/' + link.hostname + page
  pageTracker._trackPageview(page)
}
// Cufon config
Cufon.replace([
    'p#strap',
    'div#footer h1'
  ], {
    hover: true
  }
)
