// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function(){

  $("#donationForm").validate({
    rules: { 
      amount: "required",// simple rule, converted to {required:true} 
      email: {// compound rule 
        required: true, 
        email: true 
      },
      reason: "required"
    },
    messages: { 
      amount: "Please enter an amount.",
      email: "Please enter a valid email address.",
      reason: "Please enter a reason for this donation."  
    },
    submitHandler: function(form) {
      amount = $("#donationForm #amount").val();
      amount = (amount*100);
      $("#donationForm #amount").attr("value", amount);
      form.submit();
    }
  });
  
  $("#smallDonationForm").validate({
    rules: { 
      amount: "required"// simple rule, converted to {required:true} 
    }, 
    messages: { 
      amount: "Please enter an amount."
    },
    submitHandler: function(form) {
      amount = $("#smallDonationForm #donationAmount").val();
      amount = (amount*100);
      $("#smallDonationForm #donationAmount").attr("value", amount);
      form.submit();
    }
  });

  $(function() {
  	$('.parchment-block.imagegallery ul.image-gallery a').lightBox(); 
  	$('.full-article ul.images a').lightBox()
  });
  
  $("#header .main-nav li").hover(
    function () {
  	  $(this).find("ul").show();
  		$(this).find("a").addClass('hover');
  	},
  	function () {
  	  $(this).find("ul").hide();
  		$(this).find("a").removeClass('hover');
  	}
  );
  

  $('#main-content .top-area .top-right ul.case_studies_list').cycle({ 
    fx:    'fade',
  	timeout:  7000,
  	random:  1,
  	width: 517,
  	height: 360 
  });
  
  $('#main-content .right-col .top-right ul.case_studies_list').cycle({ 
    fx:    'fade',
  	timeout:  7000,
  	random:  1,
  	width: 517,
  	height: 360 
  });
  
  $('.image-placeholder.cycling').cycle({ 
    fx:    'fade',
  	timeout:  3000,
  	random:  1,
  	top: 100
  });
  
  $('#homepage .bottom-area #news .image').cycle({ 
    fx:    'fade',
  	timeout:  3000,
  	random:  1,
  	top: 100
  });
  
  $('.top-right .image-gallery.cycling').cycle({
    fx:    'fade',
  	timeout:  3000,
  	next:   '#next2', 
    prev:   '#prev2'
  });
  
  $('.top-right .parchment-block.imagegallery .play').hide()
  
  $('.top-right .parchment-block.imagegallery').mouseover(function(){
   $('.top-right .parchment-block.imagegallery .gallery-navigation').css('display', 'block')
  })
  $('.top-right .parchment-block.imagegallery').mouseout(function(){
   $('.top-right .parchment-block.imagegallery .gallery-navigation').css('display', 'none')
  })
  
  $('.top-right .parchment-block.imagegallery #pause').click(function() {
    $('.top-right .parchment-block.imagegallery .pause').hide()
    $('.top-right .parchment-block.imagegallery .play').show()
    $('.top-right .image-gallery.cycling').cycle('pause');
    return false
  });
  
  $('.top-right .parchment-block.imagegallery #play').click(function() { 
    $('.top-right .parchment-block.imagegallery .play').hide()
    $('.top-right .parchment-block.imagegallery .pause').show()
    $('.top-right .image-gallery.cycling').cycle('resume');
    return false
  });
  
  $('#homepage #main-content .bottom-area .left ul.box-links li a').click(function() {
    url = $(this).attr("href");
    $("#homepage #main-content .bottom-area .left div").removeClass("active")
    $("#homepage #main-content .bottom-area .left " + url).addClass("active")
    return false
  });
  
  $('#homepage #main-content .bottom-area .right ul.box-links li a').click(function() {
    url = $(this).attr("href");
    $("#homepage #main-content .bottom-area .right div").removeClass("active")
    $("#homepage #main-content .bottom-area .right " + url).addClass("active")
    return false
  });


})