/*
Accordion controller code for daily horoscope pages
Must be included after the other accordion includes

*/

//  load accordions onload
Event.observe(window, 'load', loadAccordions, false);

//	Set up accordion
var divSpotAccordion; // need a reference to this obj outside the function
var accordionInterval; //timer
var accordionCount; // number of div spots
var spotlightInterval = 10000; //delay for animation timer 10 seconds
  
// this is called by the play button with false passed
// to by pass the delay
// so when you hit play it starts playing immediately rather than waiting 10 secs  
// alse called on page load , with the timer needed
function play_spotlights(pause_first)
{
  // clear it out
  window.clearInterval(accordionInterval);
  // turn play button  on
  $('divSpotPlayBtn').removeClassName('divSpotNavBtn');
  $('divSpotPlayBtn').addClassName('divSpotNavBtnOn');
  // turn pause button off
  $('divSpotPauseBtn').removeClassName('divSpotNavBtnOn');
  $('divSpotPauseBtn').addClassName('divSpotNavBtn');
  // start playing immediately for some cases (like hitting the play button)
  if (!pause_first) {
    nextAccordion();
  } 
  // start timer
  accordionInterval = setInterval("nextAccordion()",spotlightInterval);
}
  
function stop_spotlights()
{
  // turn play button  off
  $('divSpotPlayBtn').removeClassName('divSpotNavBtnOn');
  $('divSpotPlayBtn').addClassName('divSpotNavBtn');
  // turn pause button on
  $('divSpotPauseBtn').removeClassName('divSpotNavBtn');
  $('divSpotPauseBtn').addClassName('divSpotNavBtnOn');
  
  window.clearInterval(accordionInterval);
}   
  
// called on page load  
function loadAccordions() {
	
	divSpotAccordion = new accordion('divSpotAccordionWrap', {
    classNames: {
      toggle: 'accordion_header',
      toggleActive: 'accordion_header_active',
      content: 'accordion_content'
    },
    defaultSize : {
      height: 220
    }
  });
  // set buttons up
  Event.observe('divSpotPlayBtn', 'click', function() {play_spotlights(false);});
  Event.observe('divSpotPauseBtn', 'click', stop_spotlights);
  // used for the animation
  accordionCount = divSpotAccordion.accordionCount;
  
  // display container now that content is loaded
  $('divSpotAccordionWrap').style.display = "block";
  // do the first div
  divSpotAccordion.activate($$('#divSpotAccordionWrap .accordion_header')[0]);
  //start the animation
  play_spotlights(true);

} // end of function loadAccordions

function nextAccordion()
{   
  var openMe = divSpotAccordion.activeDivSpotId.next();
  if (!openMe){
  // this will be null if we're at the last div, so start over with div 1
    openMe = $('acc_hdr_btn_1');
  }
  divSpotAccordion.activate(openMe);
}

 
  
