var tick = 0;
var scrollStop;
var debug = false;

var homeOffset = 0;
var caseStudiesOffset = 0;
var processOffset = 0;
var differencesOffset = 0;
var contactOffset = 0;

var newsVisible = false;

//accordion
var noMoreActiveID = 0;

function log(message) {
  if (typeof console != 'undefined') {
    console.log(message);
  }
}

/**
 *http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
 *
 **/
function recordLink(category, action, opt_label, opt_value) {
  if (typeof _gaq != 'undefined') {
    log('real GA tracking: category = ' + category + ', action = ' + action);
    _gaq.push(['_trackEvent', category, action, opt_label, opt_value]);
  } else {
    log('fake GA tracking: category = ' + category + ', action = ' + action);
  }
}

function checkBrowserWidth() {
  if ($('body').width() < 1228) {
    $('body').addClass('narrow');
  } else {
    $('body').removeClass('narrow');
  }
}

$(function() {

  $('ul li:first-child').addClass('first');
  $('ul li:nth-child(even)').addClass('even');
  $('ul li:last-child').addClass('last');
  $('#news-bar .news .story:nth-child(even)').addClass('even');
  //Make external links and PDF links open in new tab/window
  $('a[href^=http]').not('a[href*=depersico]').addClass('external');
  $('a[href$=pdf]').addClass('pdf');
  $('a.external, a.pdf').attr('target', '_blank');

  //GOOGLE ANALYTICS TRACKING START
  $('#navigation a, #logo, #logo-dp').click(function() {
    recordLink('Navigation', $(this).attr('href'), null, null);
  });
  $('.cs-link').click(function() {
    recordLink('Case-Study', $(this).attr('href'), null, null);
  });
  $('.easy-accordion dt').click(function() {
    recordLink('Process', $(this).text(), null, null);
  });
  $('a.pdf').click(function() {
    recordLink('PDF', $(this).attr('href'), null, null);
  });
  $('a[href$=vcf]').click(function() {
    recordLink('vCard', $(this).attr('href'), null, null);
  });
  $('a.external').click(function() {
    recordLink('External', $(this).attr('href'), null, null);
  });
  $('a.d-find').click(function() {
    recordLink('Find out more', $(this).attr('href'), null, null);
  });
  $('a.d-link').mouseover(function() {
    recordLink('Differences Hover', $(this).attr('href'), null, null);
  });
  $('#p-accordion dt').click(function() {
    recordLink('Process Section', $(this).attr('id'), null, null);
  });
  $('a.see-before').click(function() {
    recordLink('Case Study - See Before', $(this).attr('href'), null, null);
  });
  //GOOGLE ANALYTICS TRACKING end

  //CASE STUDY BEFORE IMAGE START
  /*$('.see-before').hover(function() {
    $('.before-wrapper').animate({
      height: '228px'
      ,width: '353px'
    }, {queue: false});
    $('.before-image').animate({
      height: '221px'
      ,width: '346px'
    }, {queue: false});
    $('.see-before').hide();
  }, function() {
    
  });*/
  /*$('.before-wrapper').mouseout(function() {
    $(this).animate({
      height: '26px'
      ,width: '132px'
    }, {queue: false});
    $('.see-before').show();
  });*/
  $('.photo').append('<a href="#" id="close-before">Close</a>');
  $('.see-before').attr('href', window.location.pathname);
  $('.see-before').click(function() {
    $('.see-before').hide();
    $('.before-image').show();
    $('.before-wrapper').animate({
      height: '228px'
      ,width: '353px'
    }, 300, function() {
      $('#close-before').show();
    });
    $('.before-image').animate({
      height: '221px'
      ,width: '346px'
    }, 200);
    
    return false;
  });
  
  $('#close-before').click(function() {
    $('#close-before').hide();
    if (debug) log('close');
    $('.before-wrapper, .before-image').animate({
      height: '26px'
      ,width: '101px'
      ,bottom: '10px'
    }, 300, function() {
      $('.see-before').show();
      $('.before-image').hide();
    });
    return false;
  })
  //CASE STUDY BEFORE IMAGE END



});
