/*
 * site.js
 *
 * Includes jQuery onReady call, plus pre-defined functions for re-use
 */

$(document).ready(function(){
  // wire up the title links to reveal The Answer!
  $('.faq h3 a').live('click', function(){
    var $question = $(this);
    
    if ($question.is('.showing'))
      $question.removeClass('showing');
    else
      $question.addClass('showing');
    
    $question.parent().next('.answer').toggle('fast');
    return false;
  });
  
  //set the top issue links to also reveal the answer for the jump to the anchor
  $('#topfive ol li a').live('click', function() {
    // alert('tis i the dirty scoundrel');
    var $link = $(this);
    // what's in the href (e.g. #such_and_such) is the question title we are jumping to
    var $question = $( $link.attr('href') );
    var $answer = $question.parent().next('.answer');
    
    if ($answer.is(':hidden')) {
      $question.addClass('showing');
      $answer.show();
    }
  });
  
  // if we're on the Faq page and the Location has a hash, make sure that answer isn't hidden
  var path_parts = document.location.pathname.split('/');
  var current_document = (path_parts[path_parts.length-1]); // e.g. faq.html
  var extension_index = current_document.search(/.html/i);
  var slug = "";
  if (extension_index == -1) {
    slug = current_document;
  } else {
    slug = current_document.substring(0, current_document.search(/\.html/i));
  }
  
  // if we're on an faq page and there's a hash/id in the url, make sure that answer is shown
  if (slug == 'faq' && document.location.hash) {
    $(document.location.hash).parent().next('.answer').show();
  }
  
  $('#palm-screens').cycle({ 
    fx:     'fade', 
    speed:   300, 
    timeout: 5000, 
    next:   '#screens', 
    pause:   1 
  });
  
  // randomize the sidebar snippets
  $('.quotes').cycle({
    fx: 'fade',
    speed: 500,
    timeout: 6000, 
    random: 1// ,
    //     fit: 1,
    //     containerResize: 1,
    //     zeteticSidebarFloat: true
  });
  
  // lightbox the tour images
  // $('.screenshot a.lightbox').lightBox();

});
