/***
* Home page carousel methods
**/
var descs = {
  chapters: 'Empower affiliates, field organizers, or local branches with Chapter-level access',
  events: 'Salsa event manager makes it an affair to remember... literally',
  reports:'The most powerful custom and built-in reports in the business',
  supporter: 'A complete picture of your supporters, customized for your organization',
  email: 'Your killer app for personal, relevant communication to supporters',
  web: 'Create a variety of pages for publication to your users',
  donations: 'Integrated fundraising with Salsa is a snap',
  advocacy: 'Cause organizations can turn pageviews into public pressure with the Salsa actions tool',
  mySalsa: 'Create and organize your own online community'
};

function startAutoPlay() 
{
  $('#content-wide-carousel .roundabout').focus(function() 
  {
    var useTitle = $(this).find('img').attr('alt');
    var useText = (typeof descs[$(this).attr('id')] != 'undefined') ? descs[$(this).attr('id')] : '';
    $('#description').html('<span class="carousel-title">' + useTitle + ':</span><br/>' + useText).fadeIn(200);
  }).blur(function() 
  {
    $('#description').fadeOut(100);
  });

  //$('#content-wide-carousel').roundabout_setTilt(-0.6); 

  return setInterval(function() 
  {
    $('#content-wide-carousel').roundabout_animateToNextChild();
  }, 3000);
}

/**
 * Home slideshow clicks
 */
var homeSlideStart = 1;
var homeNumSlides = 3;
function homeSlideShowClickDir(dir)
{
  for(var i = 1; i <= homeNumSlides; i++ )
  {
    $('#slide-'+i).hide();
    $('#slide-a-'+i).removeClass('video-on');      
  }
  if( dir > 0 && (dir+homeSlideStart) <= homeNumSlides ) 
    homeSlideStart++;
  else if ( dir < 0 && (dir+homeSlideStart) >= 1 )
    homeSlideStart--;
  else  if( dir > 0 && homeSlideStart == homeNumSlides )
    homeSlideStart = 1;
  else if( dir < 0 && homeSlideStart == 1 )
    homeSlideStart = homeNumSlides;

  $('#slide-'+homeSlideStart).show();
  $('#slide-a-'+homeSlideStart).addClass('video-on');
  
} // homeSlideShowClickDir()

function homeSlideShowClick(index)
{
  for(var i = 1; i <= homeNumSlides; i++ )
  {
    if(index == i)
    {
      $('#slide-'+i).show();
      $('#slide-a-'+i).addClass('video-on');
      homeSlideStart = i;
    }
    else
    {
      $('#slide-'+i).hide();
      $('#slide-a-'+i).removeClass('video-on');      
    }
  }
} // homeSlideShowClick

/***
* Interior navigation
**/
function salsaNav() 
{
  var currentNav = $('#interior-nav-inner li.active-trail');

  $('#interior-nav-inner ul li').hover(
      function() {
        // hide all others
        $(this).parent().children('.nav-toplevel').each( function() {
          if( $(this).hasClass('active-trail') ) {            
            $(this).children('ul').css('visibility','hidden');
          }
          // mark current active element as disabled
          if( $(this).hasClass('active-trail') && $(this).attr('id') == currentNav.attr('id') )
          {
            $(this).addClass('active-grey');
          }

        });
        
        if( $(this).find('ul').length > 0 ) {
          // make current visible
          $(this).find('ul:first').css('visibility','visible');
          $(this).removeClass('active-grey');
        }        
      },
      function() {
        if( $(this).find('ul').length > 0 && !$(this).hasClass('active-trail') ) {
          // hide current
          $(this).find('ul:first').css('visibility','hidden');
        }

        // show the one that's active
        $(this).parent().children('.nav-toplevel').each( function() {
          if( $(this).hasClass('active-trail') ) {
            $(this).removeClass('active-grey');
            $(this).children('ul').css('visibility','visible');
          }            
        });
                
      }
  );
  
}; // SalsaNav
