problem in carousel

problem in carousel

      Hi

I have a dynamic carousel. in which item varies from 2 to 14.

Now if i have 2 items, then i want to show as soon as i load the carousel the right arrow disabled. How wud i show it on loading the carousel itself.

Below is the code to handle the carousel arrows.

  1. function filterArrowButtonWasClicked(event) {
  2. var content = $('carousel_content');
  3. var offset = parseInt(content.readAttribute('data-offset'), 10);
  4. var no_of_products = parseInt(ACProductBrowser.products.products.length, 10);
  5. var remainingProducts = Math.floor(no_of_products % 6);
  6. var totalWidth = 138.5 * remainingProducts;
  7. var slideTo = totalWidth + 830;

  8. var initialWidth = 830;
  9. if (no_of_products <= 6 || no_of_products < 12 ) {
  10. initialWidth = totalWidth;
  11. slideTo = totalWidth;
  12. } else {
  13. initialWidth = 830;
  14. }

  15. if (event.target.id == 'right_arrow') {
  16. $('left_arrow').removeClassName('disabled');
  17. offset = Math.max(offset - initialWidth, -slideTo);
  18. if (offset == -slideTo) {
  19. $('right_arrow').addClassName('disabled');
  20. }
  21. } else {
  22. $('right_arrow').removeClassName('disabled');
  23. offset = Math.min(offset + initialWidth, 0);
  24. if (offset == 0) {
  25. $('left_arrow').addClassName('disabled');
  26. }
  27. }

  28. content.writeAttribute('data-offset', offset);
  29. content.style.webkitTransform = 'translateX(' + offset + 'px)';
  30. content.style.MozTransform = 'translateX(' + offset + 'px)';
  31. content.style.OTransform = 'translateX(' + offset + 'px)';
  32. content.style.msTransform = 'translateX(' + offset + 'px)';
  33. content.style.left = offset + 'px';
  34. }

But this function will be called only when i click any arrow. in case of two items, the arrows shud be disabled right away. how to do this?