$(document).ready(function ()
{
  // Highlight current section in top nav.
  var pathname = window.location.pathname;

  if (pathname.lastIndexOf("/") == 0) { $("#home a").addClass("current"); }
  else if (pathname.indexOf("services/") > 0) { $("#services a").addClass("current"); }
  else if (pathname.indexOf("green/") > 0) { $("#green a").addClass("current"); }
  else if (pathname.indexOf("quote/") > 0) { $("#quote a").addClass("current"); }
  else if (pathname.indexOf("customer-resources/") > 0) { $("#customerResources a").addClass("current"); }
  else if (pathname.indexOf("employment/") > 0) { $("#employment a").addClass("current"); }
  else if (pathname.indexOf("contact/") > 0) { $("#contactUs a").addClass("current"); }

  // Open external website links in a new tab.
  $('a[rel="external"]').click(function ()
  {
    window.open($(this).attr('href'));
    return false;
  });

  var allBoxes = $("#boxes p a");
  var box1 = $("#boxes #one a");
  var box2 = $("#boxes #two a");
  var box3 = $("#boxes #three a");

  $(allBoxes).animate({ opacity: 0 }, 0).animate({ opacity: .7 }, 2000);

  $(box1).hover(

    function ()
    {
      $(box2).stop(true, false).animate({ opacity: .3 }, "normal");
      $(box3).stop(true, false).animate({ opacity: .3 }, "normal");
      $(this).stop(true, false).css({ backgroundPosition: '0px -144px' }).animate({ opacity: 1 }, "normal");
    },
    function ()
    {
      $(this).stop(true, false).css({ backgroundPosition: '0px 0px' })
      $(allBoxes).stop(true, false).animate({ opacity: .7 }, "normal");
    }
  );

  $(box2).hover(

    function ()
    {
      $(box1).stop(true, false).animate({ opacity: .3 }, "normal");
      $(box3).stop(true, false).animate({ opacity: .3 }, "normal");
      $(this).stop(true, false).css({ backgroundPosition: '0px -144px' }).animate({ opacity: 1 }, "normal");
    },
    function ()
    {
      $(this).stop(true, false).css({ backgroundPosition: '0px 0px' })
      $(allBoxes).stop(true, false).animate({ opacity: .7 }, "normal");
    }
  );

  $(box3).hover(

    function ()
    {
      $(box1).stop(true, false).animate({ opacity: .3 }, "normal");
      $(box2).stop(true, false).animate({ opacity: .3 }, "normal");
      $(this).stop(true, false).css({ backgroundPosition: '0px -144px' }).animate({ opacity: 1 }, "normal");
    },
    function ()
    {
      $(this).stop(true, false).css({ backgroundPosition: '0px 0px' })
      $(allBoxes).stop(true, false).animate({ opacity: .7 }, "normal");
    }
  );
})
