// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function() {
  $('.flash').hide().slideDown().animate({opacity: 1.0}, 3000).slideUp();

  $('input.clearme').focus(function(i) {
    if (this.value == this.title) {
      this.value = "";
      $(this).removeClass('clearme');
    }
  });
  $('input.clearme').blur(function(i) {
    if (this.value == "") {
      this.value = this.title;
      $(this).addClass('clearme')
    }
  });
  $('#subscriber_form').submit(function() {
    $.post('/subscribers', $(this).serialize(), function(data) {
      if (data.status == "success") {
        $('#subscriber_form_wrap').html(data.message);
      }
    }, "json");
    return false;
  });
  $('#subscriber_form_default').submit(function() {
    $.post('/subscribers', $(this).serialize(), function(data) {
      if (data.status == "success") {
        $('#subscriber_form_wrap_default').html(data.message);
      }
    }, "json");
    return false;
  });

  var testimonials = jQuery('#testimonials .testimonial');
  var current_testimonial = 0;
  var tweets = jQuery('#twitter_bird .tweet')
  var current_twitter = 0;
  jQuery(tweets[current_twitter]).addClass('active');
  var quote_rotator = setInterval(function() {
    jQuery(testimonials[current_testimonial]).removeClass('active');
    current_testimonial += 1;
    if (testimonials.length == current_testimonial) {
      current_testimonial = 0;
    }
    jQuery(testimonials[current_testimonial]).addClass('active');

    jQuery(tweets[current_twitter]).removeClass('active');
    current_twitter += 1;
    if (tweets.length == current_twitter) {
      current_twitter = 0;
    }
    jQuery(tweets[current_twitter]).addClass('active');
  }, 5000);

  $('a#fancy_popup').fancybox({hideOnContentClick:false, frameHeight: 410, frameWidth: 792}).trigger('click');

});

