$(document).ready(function () {
  var img = 0;
  var count = $("div.home p").length;
  var prev = count - 1;

  function changes() {
    prev = img - 1;

    if (img >= count) {
      img = 0;
    }
    $('div.home p a').eq(img).addClass("new");
    $('div.home p a').eq(img).fadeIn();
    $('div.home p a').removeClass("new");
    $('div.home p a').eq(prev).fadeOut();
    $('div.home p a').removeClass("active");
    $('div.home p a').eq(img).addClass("active");

    img = img + 1;

    setTimeout(changes, 4000);
  }

  if (count > 1) {
    changes();
  }
  else {
    $('div.home p a').eq(img).fadeIn();
  }

  $("div.slider").codaSlider(
    {
      dynamicArrows: false,
      dynamicTabs: false
    });

  $('div.carousel span.left').click(function () {
    $('.stripNavL a').trigger('click');
  });

  $('div.carousel span.right').click(function () {
    $('.stripNavR a').trigger('click');
  });

  $('a[rel="external"]').click(function () {
    window.open($(this).attr('href'));
    return false;
  });

  /* Products on HP - set Y position */
  var products = $("div.products");
  if (products) {
    products.css({ "top": ($("div.foot").position().top - products.height()) + "px" });
  }

  $("div.flash").flash({
    swf: "/swf/head.swf",
    width: 734,
    height: 127
  });
});
