var d = new Date();
var curr_year = d.getFullYear();

document.write(''+
  '<div id="footer" class="clearfix">\n'+
  '<ul>\n'+
  '<li><a href="https://www.survey.arrow.com/se.ashx?s=218043747221A91F" rel="windowCenter" class="popupwindow">Feedback</a></li>\n' +
  '<li><a href="http://' + env + '.arrownac.com/terms/">Terms of Use</a></li>\n'+
  '<li><a href="http://' + env + '.arrownac.com/privacy/">Privacy Policy</a></li>\n'+
  '<li><a href="http://' + env + '.arrownac.com/sitemap/">Sitemap</a></li>\n'+
  '</ul>\n'+
  '<p id="copy">&copy; ' + curr_year + ' <a href="http://www.arrow.com/" rel="windowCenter" class="popupwindow">Arrow Electronics</a>, Inc. All rights reserved.</p>\n'+
  '</div>\n'+

  //webtrends setup
  '<!-- START OF SmartSource Data Collector TAG -->\n'+
  '<!-- Copyright (c) 1996-2011 WebTrends Inc.  All rights reserved. -->\n'+
  '<!-- Version: 9.3.0 -->\n'+
  '<!-- Tag Builder Version: 3.1  -->\n'+
  '<!-- Created: 2/25/2011 12:04:43 PM -->\n'+
  '<!-- ----------------------------------------------------------------------------------- -->\n'+
  '<!-- Warning: The two script blocks below must remain inline. Moving them to an external -->\n'+
  '<!-- JavaScript include file can cause serious problems with cross-domain tracking.      -->\n'+
  '<!-- ----------------------------------------------------------------------------------- -->\n'+
  '<script type="text/javascript">\n'+
  '//<![CDATA[\n'+
  'var _tag=new WebTrends();\n'+
  '_tag.dcsGetId();\n'+
  '//]]>\n'+
  '</script>\n'+
  '<script type="text/javascript">\n'+
  '//<![CDATA[\n'+
  '_tag.dcsCustom=function(){\n'+
  '// Add custom parameters here.\n'+
  '//_tag.DCSext.param_name=param_value;\n'+
  '}\n'+
  '_tag.dcsCollect();\n'+
  '//]]>\n'+
  '</script>\n'+
  '<!-- END OF SmartSource Data Collector TAG -->\n'  
  );

/* GOOGLE ANALYTICS */ 
var _gaq = _gaq || [];
if(document.domain == 'www.arrownac.com'){ 
  _gaq.push(['_setAccount', 'UA-21048962-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackPageLoadTime']);
} else if (document.domain == 'components.arrow.com'){
  _gaq.push(['_setAccount', 'UA-21048962-2']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackPageLoadTime']);
};

(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);
})();

$(document).ready(function(){
  filetypes = /\.zip$|\.exe$|\.pdf$|\.doc$|\.mp3$|\.wmv$|\.mov$/i;
  $('a').each(function (){
    if($(this).attr('href') !== undefined ) {
      if($(this).is('a#submit_search')) {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'Part Search', document.URL])
        });
      }
      else if($(this).is('a#login_submit')) {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'My Arrow', document.URL])
        });
      }
      else if($(this).is('a#cart')) {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'Shopping Cart', document.URL])
        });
      }
      else if($(this).is('a#forgot_password')) {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'Forgot Password', document.URL])
        });
      }
      else if($(this).attr('href') == 'http://components.arrow.com/forecastresponse/my_forecasts.jsp') {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'My Forecasts', document.URL])
        });
      }
      else if($(this).attr('href') == 'http://components.arrow.com/ordermanagement/order_listings.jsp') {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'Order Listings', document.URL])
        });
      }
      else if($(this).attr('href') == 'http://components.arrow.com/userservice/Registration/NewUser') {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'E-Commerce', 'Registration', document.URL])
        });
      }
      else if($(this).is('a[href^="mailto"]')) {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'Email', $(this).attr('href'), document.URL])
        });
      }
      else if($(this).is('div.adbx a[href^="http://247.arrownac.com"]')) {
        $(this).click(function(){
          _gaq.push(['_trackEvent', 'Banners', 'Sidebar Banners', + $(this).attr('href')])
        });
      }
      else if($(this).attr('href').match(filetypes)) {
        $(this).click(function(){
          _gaq.push(['_trackPageview', '/download/' + $(this).attr('href')])
        });
      }
      else if(this.hostname !== location.hostname) {
        $(this).click(function(){
          _gaq.push(['_trackPageview', '/outgoing/' + $(this).attr('href')])
        });
      }
    }
  });
  var yaTrigger = '#ya_fcatslink';
  var yaContainer = '#ya_fcats';
  $(yaTrigger).click(function(){
    $(yaContainer).toggle(0, function(){
      if($(this).is(':visible')){
        $(yaTrigger).html('Featured Categories [-]');
      } else if(!$(this).is(':visible')){
        $(yaTrigger).html('Featured Categories [+]');
      }
    });
  });
});
