/* Spintop JS */

var numFeatured;
var curPosFeatured = 0;


document.observe("dom:loaded", function() {

  // Featured Game (Home)
  featured = $$("#featured-buttons div");
  if (featured.length) {
    featured.invoke('observe', 'click', featuredButtonClick);
    setFeaturedItem(1);
  }
});


featuredButtonClick = function(e) {
  pos = this.readAttribute('data-pos');
  if (pos == "left") {
    pos = curPosFeatured - 1;
  }
  if (pos == "right") {
    pos = curPosFeatured + 1;
  }
  if (pos == 0) {
    pos = numFeatured;
  }
  if (pos > numFeatured) {
    pos = 1;
  }

  setFeaturedItem(pos);
}

function setFeaturedItem(pos) {
  $$(".featured-home-text").invoke('removeClassName', 'visible');
  $$(".featured-home-image").invoke('removeClassName', 'visible');

  $$("#featured-home-text-" + pos).invoke('addClassName', 'visible');
  $$("#featured-home-image-" + pos).invoke('addClassName', 'visible');

  $$('#featured-buttons div').invoke('removeClassName', 'active');
  $$('#featured-buttons div[data-pos="' + pos + '"]').invoke('addClassName', 'active');

  curPosFeatured = pos;
}

