Event.observe(window, 'load', init_carousel);

function init_carousel() {

  if (!$('groups')) return;  // skip execution if the main move container is missing

  controls              = $$('.white .controls')[0];     // get the controls container for all of the buttons 
  control_elements      = $$('.white .controls li a');   // get an array of all the buttons

  // pull in the other pages
  new Ajax.Updater('groups', 'pressroom.aspx', 
  {
    method: 'get',
    parameters: {a:'getmagazines'},
    insertion: Insertion.Bottom
  });

  // observe the entire controls container for any events
  controls.observe('click', function(event) { 
      var element = Event.element(event);   // get the element for which the event occured
      var pages = [$('pressFeatured'), $('pressFitness'), $('pressSpa'), $('pressBusiness')];
      
      if (element.nodeName == 'A') {
        control_elements.invoke('removeClassName','active');
        pages.each(function(item){ item.hide(); });
        switch (element.innerHTML) {
          case 'Featured':
            pages[0].show();
            break;
          case 'Fitness':
            pages[1].show(); 
            break;
          case 'The Spa':
            pages[2].show(); 
            break;
          case 'Business/Real Estate':
            pages[3].show(); 
        }
        element.addClassName('active'); 
      }
  });
}

