// Drupal comes to the rescue ...
$(document.documentElement).addClass('js');
// 'js enabled' cookie
document.cookie = 'has_js=1; path=/';

$(document).ready(function(){
  $('body.index #appswf')
    .flash({ 
      swf: $('a#launchbtn').attr('rel'), 
      width: 640, 
      height: 480 
    });
  $('body.index a#launchbtn')
    .attr('href', '#appswf')
    .fancybox( { 
      frameWidth: 640, 
      frameHeight: 480, 
      hideOnOverlayClick: false,
      hideOnContentClick: false,
      enableEscapeButton: false
//      showCloseButton: false 
    } );
  $('#privacybtn')
    .fancybox( {
      frameWidth: 640,
      frameHeight: 480
    } );
  $('.progcheck a')
    .fancybox( {
      frameWidth: 580,
      frameHeight: 280
    } );
  $('#email_share')
    .fancybox( {
      frameWidth: 400,
      frameHeight: 280,
      hideOnContentClick: false,
      callbackOnShow: function() {
         $('#fancy_div form.emails_form').ajaxForm({
            target: $('#fancy_div .emails_content .response'),
            beforeSubmit: function( data, obj, opts ) { 
              $('#fancy_div .indicator').css('display','inline');
              $('#fancy_div .submit').attr('disabled', true);
              return true;
            },
            success: function( text ) {
              $('#fancy_div .indicator').css('display','none');
              // $('#fancy_div .submit').attr('disabled', false);
            }
          });
      }
    } );
    
  
  $('#quick_submit').submit(function(e){
    e.preventDefault();
    
    // Clever numeric test!
    var amount = $('#amount').val();
    if( amount != parseFloat( amount ) )
    {
      alert( "Please input a numeric value for the quick donation amount" );
      return false;
    }
    
    if( $('#group_id').val().length == 0 )
    {
      alert( 'Please select a team for which to donate.' );
      return false;
    }
    
    $('#closure').flash( {
      swf: 'flash/QuickSubmit.swf',
      flashvars: {
       'amount':    $('#amount').val(),
       'group_id':  $('#group_id').val()
      },
      height: 1,
      width: 320
    });
    
    return false;
  });
});

var addthis_config = {
  ui_delay: 100
};

var addthis_share =
{
  title: 'Click here to help the Habitat for Humanity: Women Build',
  // should only be used by LinkedIn
  description: 'I just did my part to help Flower City Habitat for Humanity’s Women Build, a wonderful opportunity to support women who want to build a "green" home on their own for a deserving Rochester family in the JOSANA neighborhood.',
  templates: 
  {
    twitter: 'Just did my part to help @ROCHabitat Women Build. Check out the awesome app to help build a "green" home in #ROC! http://www.rochabitat.org'
  },
  email_template: 'rochabitat',
  email_vars: 
  { 
    donator_name: "One of your friends",
    donator_first_name: "Their"
  }
};
var base = window.location.protocol + "//" + window.location.host + window.location.pathname.replace('thankyou', 'index');
if( $.query.get('id') )
{
  addthis_share.url = base + '?ref=' + $.query.get('id');
}
else
{
  addthis_share.url = base + '?ref=0';
}