$(document).ready(function() {
  $('div#formsuccess').parents('#ctaForm').removeClass('collapse');
  $('div#formsuccess').parents('#ctaForm').delay(5000).animate({
    height:0
  });
  $('div.errors').parents('#ctaForm').removeClass('collapse');
  $('#contact_product input#submit').mouseover(function() {
    $(this).addClass('hover');
  });
  $('#contact_product input#submit').mouseout(function() {
    $(this).removeClass('hover');
  });
  
  $('label.required').append('*');
  
  $("a.track").click(function() {
    if('cta' + $(this).attr('id') != $('div.open').attr('id')) {
      var link = $(this).attr('rel');
      var page = $(this).parent().attr('rel')
      _gaq.push(['_trackEvent', 'cta', link, page]);
      //alert('tracked: \'_trackEvent\', \'cta\', \'view\', \'' + link + '\', \'' + page + '\'');
    }
  });
  
  $('a.panel').click(function() {
    if('cta' + $(this).attr('id') == $('div.open').attr('id')) {
      $(this).removeClass('current');
      $('div.open').animate({
        height: 0      
      }, 300, function(){
        // Animation complete.
      }).removeClass('open');
    } else {
      $('a.panel').removeClass('current');
      $(this).addClass('current');
      $('div.open').removeClass('open').animate({
        height: 0      
      }, 300);
      var requested = 'div#cta' + $(this).attr('id');
      var openheight = $(requested + ' > .ctaContent').height() + 40;
      $(requested).addClass('open').animate({
        height: openheight
      }, 300);      
    }
  });
  
});
