jQuery(function($){

  if($('#mailerform').length > 0) {
      $('#mailerform').submit(function() {
          $('#submit').val('submitting...');
          $('#submit').attr("disabled","disabled");
      })
  }
  
  $('ul.gallery a').lightBox();

});

jQuery(function($){
  // add outgoing clicks to GA
  $("a[href*='http://']:not([href*='"+location.hostname+"'])").click(function(){
    _gaq.push(['_trackEvent', 'UserAction','External Link',$(this).attr('href')]);
  });
});

(function($) {
  $.fn.toggler = function(options) {
    var opts = $.extend({}, $.fn.toggler.defaults, options);
  
    return this.each(function() {
      this.togglee = $($(this).attr('href')).hide();
      $(this).click(onClick);
    });

    function onClick() {
      this.togglee[opts.animate ? 'slideToggle' : 'toggle']();
      return false;
    }
  }

  $.fn.toggler.defaults = {animate: false}

  $(document).ready(function() {
    $('a.toggler').toggler({animate:true});
  });
})(jQuery);

jQuery(function($){
	$('#video img').click(function(){
		$('#video').html("<object width='512' height='328'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='' /><param name='wmode' value='transparent' /><embed src='/assets/26904/haiti.swf' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='512' height='328' wmode='transparent'></embed></object>");
	});
});

jQuery(function($){
	$('#homevideo img').click(function(){
		$('#homevideo').html("<object width='448' height='292'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='' /><param name='wmode' value='transparent' /><embed src='/assets/26904/haiti.swf' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='448' height='292' wmode='transparent'></embed></object>");
	});
});

// General purpose video replacement
jQuery(function($){
  $('.video').bind('click', function(e){
    e.preventDefault();
    
    var $this = $(this),
        $img = $this.find('img'),
        width = $img.width(),
        height = $img.height(),
        pubcode = $this.find('a')[0].getAttribute('href')
    ;
    $this.html("<object width='"+ width +"' height='"+ height +"'><param name='allowfullscreen' value='true' /><param name='flashvars' value='"+ pubcode +"' /><param name='allowscriptaccess' value='always' /><param name='movie' value='' /><param name='wmode' value='transparent' /><embed src='/assets/56463/video.swf' flashvars='pubcode="+pubcode+"' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='"+ width +"' height='"+ height +"' wmode='transparent'></embed></object>");
    
    $this.unbind('click');
  });
});

// iOS Viewport fix
var viewportmeta = document.querySelector && document.querySelector('meta[name="viewport"]'),
    ua = navigator.userAgent,

    gestureStart = function () {
        viewportmeta.content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
    },

    scaleFix = function () {
      if (viewportmeta && /iPhone|iPad/.test(ua) && !/Opera Mini/.test(ua)) {
        viewportmeta.content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
        document.addEventListener("gesturestart", gestureStart, false);
      }
    };
scaleFix();

