$(document).ready(function() {

  $("#calendar_tabs").tabs();
  
    if ( $('.bodycontent .help, .bodycontent a[title], .bodycontent [title]').qtip ) {

        $('.bodycontent .help, .bodycontent a[title], .bodycontent [title]').qtip({
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                }
            },
            style: { 
                name: 'blue',
                tip: 'bottomMiddle'
            }
        });
    }

	/* hide the standard submit button, show the pretty button */
	/* $('form input:submit').hide(); */
	/* $('.submit.button').show(); */
	
	/* submit the form when the pretty button is clicked */
	/* $('.submit.button').click(function(){ $(this).parents('form:first').submit(); }); */

  if ($('input[title]').example) {

      $('input[title]').example(function() {
          return $(this).attr('title')}, 
          {className: 'gray'}
      );
  }

  $('.subcontent').hide();
  $('#f_contact .toggle').toggle(function()
  {
    $(this).next('.subcontent').slideDown(400);
    $(this).html('<img class="icon" src="/icons/silk/bullet_toggle_minus.png" /> Hide additional recipients');
  }, function() {
    $(this).next('.subcontent').slideUp(400);
    $(this).html('<img class="icon" src="/icons/silk/bullet_toggle_plus.png" /> Show additional recipients');
  });

  $('#training .toggle').toggle(function()
  {
    $(this).next('.subcontent').slideDown(400);
    $(this).children('img').attr('src', '/icons/silk/bullet_toggle_minus.png' );
  }, function() {
    $(this).next('.subcontent').slideUp(400);
    $(this).children('img').attr('src', '/icons/silk/bullet_toggle_plus.png' );
  });
  
  var fadeColor = "#ffffff"; 

  $('.thanks').hide();
  $('.design_your_march').hide();

  $('.signup_button').click(function() {
    $('.signup').slideUp();
    $('.thanks').slideDown();
    $('.who_is_signed_up').slideUp();
    $('.design_your_march').slideDown();
  });

  $('.from_fax').click(function() {
    $('h3#fax').html('<img class="icon" src="/icons/silk/tick.png"/> <a href="#">Bank Faxes</a> <strong>You banked 3 free faxes. That makes us smile!</strong> <img class="icon" src="/icons/silk/emoticon_smile.png"/> ');
    $('h3#fax strong').animate({backgroundColor:fadeColor}, 30000);
  });

  $('.no_fax').click(function() {
    $('h3#fax').html('<img class="icon" src="/icons/silk/bullet_go.png"/> <a href="#">Bank Faxes</a> <strong>No problem, you can still fax on the day of the march.</strong>');
    $('h3#fax strong').animate({backgroundColor:fadeColor}, 30000);
  });

  $('.from_call').click(function() {
    $('h3#call').html('<img class="icon" src="/icons/silk/tick.png"/> <a href="#">Make Calls</a> <strong>You signed up to call from 1 &ndash; 3. Thumbs up!</strong> <img class="icon" src="/icons/silk/thumb_up.png"/> ');
    $('h3#call strong').animate({backgroundColor:fadeColor}, 30000);
  });

  $('.no_call').click(function() {
    $('h3#call').html('<img class="icon" src="/icons/silk/bullet_go.png"/> <a href="#">Make Calls</a> <strong>Busy schedule? You can still call on the day of the march.</strong>');
    $('h3#fax strong').animate({backgroundColor:fadeColor}, 30000);
  });

  $('.from_remind').click(function() {
    $('h3#remind').html('<img class="icon" src="/icons/silk/tick.png"/> <a href="#">Get Reminders</a> <strong>We&rsquo;ll remind you on the day of the march.</strong> <img class="icon" src="/icons/silk/heart.png"/>');
    $('h3#remind strong').animate({backgroundColor:fadeColor}, 30000);
  });

  $('.no_remind').click(function() {
    $('h3#remind').html('<img class="icon" src="/icons/silk/bullet_go.png"/> <a href="#">Get Reminders</a> <strong>See you on the day of the march!</strong>');
    $('h3#fax strong').animate({backgroundColor:fadeColor}, 30000);
  });

  $('.to_call').click(function() {
    $('#accordion').accordion('activate', '#call' );
  });

  $('.to_remind').click(function() {
    $('#accordion').accordion('activate', '#remind' );
  });

  $('.to_share').click(function() {
    $('#accordion').accordion('activate', '#share' );
  });

/* Make all pdfs open in a new window */
$("a[href*=.pdf]").click(function(){
	window.open(this.href);
	return false;
});

/* Jquery slideshow */
if ($('.slideshow').cycle) {
    $('.slideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
}

function ResizeImage(image, maxwidth, maxheight)
{
    if (image.className == "Thumbnail")
    {
        w = image.width;
        h = image.height;
                
        if( w == 0 || h == 0 )
        {
            image.width = maxwidth;
            image.height = maxheight;
        }
        else if (w > h)
        {
            if (w > maxwidth) image.width = maxwidth;
        }
        else
        {
            if (h > maxheight) image.height = maxheight;
        }
                
        image.className = "ScaledThumbnail";
    }
}

if ( $("img[src*=.png]").pngfix ) {
    $("img[src*=.png]").pngfix( { repeatMethod: "crop" } );
}

$("table.sortable").tablesorter({widthFixed: true, widgets: ['zebra']});

});