// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function() {
  $('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;
  });

  $('a#petition_popup').fancybox({frameWidth: 790, frameHeight : 467, hideOnContentClick:false}).trigger('click');
  //drop shadow on welcome text, experimental
  $("#welcome p.welcome_huge").dropShadow({left: 0,top: 0,blur: 2, opacity: 0.6, color: "black", swap: false});
  $("#welcome p.welcome_small").dropShadow({left: 0,top: 0,blur: 2, opacity: 0.6, color: "black", swap: false});
  $("#welcome p.welcome_medium").dropShadow({left: 0,top: 0,blur: 2, opacity: 0.6, color: "black", swap: false});

  start_current_event_scroll();
});

// scroller stuff. not classed due to loss of scope in setTimeout
var scroll_data = {
  scroll_top: 0,
  scroll_num: 3,
  scroll_space: 16
};
function scroll_current_events(top) {
  scroll_data.scroll_top += scroll_data.scroll_space;

  if (scroll_data.scroll_top >= (scroll_data.scroll_space*scroll_data.scroll_num)) {
    scroll_data.scroll_top = 0;
    $('#current_events_mask').scrollTo(scroll_data.scroll_top+'px');
  } else {
    $('#current_events_mask').scrollTo(scroll_data.scroll_top+'px', {duration: 1000});
  }
  window.setTimeout(scroll_current_events, 3000)
}

function start_current_event_scroll() {
  // first figure out the nums
  scroll_data.scroll_num = $('#current_events_list .latest_event').size();
  window.setTimeout(scroll_current_events, 3000)
}

