$(document).ready(function(){


  //signatures carousel 
  if ( $("#signatures ul").length ) {
    $("#signatures ul").cycle({
      fx:'scrollHorz',
      timeout:8000,
      speed:500,
      prev:"#signatures .prev",
      next:"#signatures .next"
    });
  } 
  

  //feature slideshow stuff
  $("ul#pager li").prepend('<div class="indicator"></div>');
  
  $("ul#pager a").each(function() {
    themargin = parseInt(( $(this).parent("li").height() - $(this).height() ) / 2 );
    $(this).css("margin-top", themargin);
  });

  if ( $("ul#slides").length) {
  
    $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
      $(pager).find('li').removeClass('activeSlide').filter('li:eq('+currSlideIndex+')').addClass('activeSlide'); 
    };  
  
    $("ul#slides").cycle({
      speed:'slow',
      timeout:5000,
      pager: '#pager',
      pause: 1,
      pagerAnchorBuilder:function(index,slide) {
        return "#pager li:eq("+index+") a";
        }
    });
  }
  
    $("#pager a").click(function(){
    $("ul#slides").cycle('toggle');
  }); 
  
  //navbar
  $(".primary-nav").superfish();
  $(".primary-nav ul li:last-child").addClass("last"); 

  
  //polling
  if ( $(".momentquiz").length) {
    
    //when clicked, show response and set answer status
    $(".momentquiz .submit").click( function() {
       //set the height of the response to match the height of the poll box so page doesn't shift.
      $(".momentquiz .result").height( $(".momentquiz .question").height() );   
    
      //check the answer and retool if necessary (default is incorrect)
      if ( $("input[name=pollradio]:checked").val() == $("#rightans").val() ) {
        $("p#response").html("Correct!").removeClass("incorrect").addClass("correct");
      }
      
      //swap the layers
      $(".momentquiz .question").fadeOut("fast", function() {
        $(".momentquiz .result").fadeIn("fast");
      });
      
      return false;
    });
  
  } //end code for poll
  
  
  //tabs on homepage
  if ( $("div#tabbed").length) {
    $("#tabbed li a").click(function() {
      //deactivate tabs and content
      $("#tabbed li a, .tabcontent").removeClass("active");
      //activate this tab and its content
      $(this).addClass("active");
      whichtab = $(this).attr("id").split("-");
      $("#"+whichtab[0]+"-content").addClass("active");
    });
  } //end home tabs

  
  //misc behaviors
  $("input.box, input.email, input[name=cons_zip_code]").resettable();
  $("#bigger").fontscale(".col_wrap p","+",{unit:"percent",increment:20});
  $("#smaller").fontscale(".col_wrap p","-",{unit:"percent",increment:20});       
  
  //tabbed interior boxes
  $(".tab-box:first-child").addClass("first");
  $(".tab-box:last-child").addClass("last");  
  $(".tab-box h2").append('<span class="right" />').after('<span class="corner" />');  
  $(".tab-box h2.red").parent('.tab-box').addClass('red'); 
  $(".tab-box div").append('<div class="clear" />'); 
});
