/////////////////////////////////////////
//
// Multi-Product Slider
// Brett Slone
// brett_slone@belk.com
// 2011.01.13
// 
// v1.1
//
// TODO: Move into Belk namespace
//
/////////////////////////////////////////

  var activeItem = null;
  var ivMove = null;
  var scrollMargin = 6;
  var trackMargin = 15;

  $(document).ready(function() {

   $("#item ul.products li").each(function() {
    $(this).fadeIn(1000, function() {
     checkBounds($("ul.products").position().left);
    });
   });

   $("a#goRight").mousedown(function() {
    pageRight();
   });

   $("a#goLeft").mousedown(function() {
    pageLeft();
   });

  });

  function pageRight() {
   prods  = $("ul.products");
   prods.stop(false, true);
   x = (prods.position().left - 583);

   x = checkBounds(x);

   prods.animate({left: x}, 1100, "easeInOutQuart") ;
  }

  function pageLeft() {
   prods  = $("ul.products");
   prods.stop(false, true);
   x = (prods.position().left + 583);

   x = checkBounds(x);

   prods.animate({left: x}, 1100, "easeInOutQuart") ;
  }

  function checkBounds(x) {
   min = -($("ul.products").width() - $("#item").width() + scrollMargin);

   if (x <= min ) {
    x = min;
    $("#goRight").stop(false, true).animate({opacity: 0}, 400);
   } else {
    $("#goRight").stop(false, true).animate({opacity: 1}, 400);
   }

   if (x >= 0) {
    x = 0;
    $("#goLeft").stop(false, true).animate({opacity: 0}, 400);
   } else {
    $("#goLeft").stop(false, true).animate({opacity: 1}, 400);
   }

   return x;

  }

 
