/*
 * Amateur spammer prevention.
 */
$(function () {
  $('.mailtoLink').each(function() {
    var contactEmail = new Array('info', '@', 'dactyl', 'publishing', '.com').join('');
    $(this).attr('href', 'mailto:'+contactEmail);
  })
  $('.yearbookMailtoLink').each(function() {
    var contactEmail = new Array('yearbooks', '@', 'dactyl', 'publishing', '.com').join('');
    $(this).attr('href', 'mailto:'+contactEmail);
  })
  $('.plannersMailtoLink').each(function() {
var contactEmail = new Array('planners', '@', 'dactyl', 'publishing', '.com').join('');
$(this).attr('href', 'mailto:'+contactEmail);
})

})

/*
 * The Contact Us lightbox effect.
 */
$(function(){
  $('.showContactInfo').click(function(e){
    $('input:visible, select:visible').hide();
    $('#contactUsWhiteout').show();
    e.preventDefault();
  })
  $('#contactUsClose').click(function(e){
    $('#contactUsWhiteout').hide();
    $('input:hidden, select:hidden').show();
    e.preventDefault();
  })
})

/*
 * Twitter integration.
 */
function showTweets (data) {
  $('#feed').empty();
  for (var tweet in data) {
    $('#feed').append('<p>'+data[tweet].text+'</p>');
  }
  $('#feed').linkify();
}


/*
 * Setup a tabset and pre-select the first tab
 * @var tablistSelector = any UL selector eg "#tabsetUL"
 * @var divClass = any tab content *class*  eg 'TabContentClass' not that the class is not qualified with a dot.
 */
function makeTabs(tablistSelector, divClass) {

  $('div.'+divClass).each(function(i){
    $(this).addClass(divClass+i);
  });

  $(tablistSelector+' li a').each(function(i){
    $(this).click(function(e){
      
      $('div.'+divClass).hide(0, function(){
        $('div.'+divClass+i).show();
      });

      $(tablistSelector+' li.selected').removeClass('selected');
      $(this).parent('li').addClass('selected');
      e.preventDefault();
      
    })
  }).eq(0).click();

  //If the URL contains a hash address (anchor link) try to select that tab from the tablist
  var hashTag = document.location.hash;
  if (hashTag != '') {
    $(tablistSelector+' a[href="'+hashTag+'"]').click();
  }

}


/*
 * Startup Analytics tracking
 * This is the new Asynchronous tracking code for Analytics
 */
//* - double slash this line to activate analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1283018-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script');ga.type = 'text/javascript';ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga, s);
  })();
/**/
