(function($) {

$.fn.equalHeight = function() {
  // In this scope, 'this' refers to the jQuery object, not the
  // DOM elements it's targeting.
  var h = 0;
  this.each(
    function() {
      var x = $(this).height();
      if(x > h) {
        h = x;
      }
    }
  );
  return this.height(h);
}

// $.fn.caption = function() {
//   alert('here');
//   // this = jQuery object
//   return this.each(
//     function(i) {
//       // this = DOM object; $(this) = jQuery object
//       var align = $(this).attr('align') ? $(this).attr('align') : $(this).css('float');
// 
//       if(align != 'none') {
//         var s = this.alt.indexOf('[');
//         var e = this.alt.lastIndexOf(']');
//         if(s > -1 && e > -1 && e > s) {
//           var after = '<span class="caption-text">' + this.alt.substring(++s, e) + '</span>';
//         }
//         $(this)
//         .wrap('<div class="caption caption-' + align + '" style="width:' + this.width + 'px;"></div>')
//         .after(after)
//         .removeAttr('align')
//         .css('float', 'none');
//       }
//     }
//   );
// }

$(document).ready(

  // function() {
  //   try {
      // Caption-ize imgs within the .content div.
      // $('.content img').caption();
  //  }
  //  catch(e) { /* Do nothing */ }
  // }

  function() {
    try {
      // Add rounded corners
      $('#block-search-form .form-text').corner('3px tl bl');
      $('#nice-menu-1 > li > a').corner('7px tl tr');
      $('#nice-menu-1 ul > li.first > a').corner('12px tr');
      $('#nice-menu-1 ul > li.last > a').corner('12px bl br');
      $('.block-menu-block .menu li a, .block-menu-block .menu li.expanded').corner('5px');
      $('#lunchbox-signup-form input').corner('4px');
      $('.block-blue .block-title').corner('5px');
      $('a.tinyButton, .tinyButton a').corner('5px');
      $('#edit-submit-methodologies').corner('4px');
      $('#main-wrapper').corner('10px');
      $('.methodology-download').corner('7px');
      $('.h-block h2.block-title').corner('10px tl tr');
    }
    catch(e) { /* Do nothing */ }
    
    try {
      // Set initial form field values
      $('#block-search-form .form-text').attr('placeholder', 'Search').placeholder();
    }
    catch(e) { /* Do nothing */ }

    try {
      // SelectBox?
    }
    catch(e) { /* Do nothing */ }
    
    $('#nice-menu-1 > li:not(.active-trail)').hover(
      function() {
        $(this).children(':first-child').animate({ marginTop: 0, paddingBottom: 10 }, 200);
      },
      function() {
        $(this).children(':first-child').animate({ marginTop: 10, paddingBottom: 0 }, 200);
      }
    );
    
    // Initialize the title-toggling stuff on the FAQ views.
    $('.view-faqs .views-row .views-field-entity-id').hide();
    $('.view-faqs .views-row .views-field-title a').click(
      function() {
        $(this).parents('.views-row').toggleClass('expanded').children(':last').slideToggle();
        return false;
      }
    );
    
    $('#develop-project .h-block .block-title, #how-it-works .h-block .block-title').equalHeight();
    $('#develop-project .h-block .content, #how-it-works .h-block .content').equalHeight();
    $('.page-news-events #block-views-nodequeue-3-block, .page-news-events #block-views-news-lp-block-4').equalHeight();
    
    /* Setting up equal width tables at body.page-node-198 (assumes 4-column tables) */
    $('.page-node-198 td:nth-child(1)').css('width', '20%');
    $('.page-node-198 td:nth-child(2)').css('width', '45%');
    $('.page-node-198 td:nth-child(3)').css('width', '20%');
    $('.page-node-198 td:nth-child(4)').css('width', '15%');

		
		//Email List signup for Mailchimp
		$('#mc_embed_signup .input-group').hide();
	
		$("#mc_embed_signup #mce-EMAIL").focus(function(){
			$("#mc_embed_signup .input-group").slideDown('fast');
		});
			
		/*
		 * I left this in case it is needed in the future - ham
		 * 
		 $("#mc_embed_signup #mce-EMAIL").focusout(function(){
			$("#mc_embed_signup .input-group").slideUp('fast');
		});	
		*/
		
		$("a.colorbox-inline").each(function() {
			var _href = $(this).attr("href"); 
			$(this).attr("href", 'http://player.vimeo.com/video/' + _href + '?width=800&height=500&iframe=true');
		});
		
  });//END JS

})(jQuery);;
/**
 * jQuery Maxlength plugin
 * @version		$Id: jquery.maxlength.js 18 2009-05-16 15:37:08Z emil@anon-design.se $
 * @package		jQuery maxlength 1.0.5
 * @copyright	Copyright (C) 2009 Emil Stjerneman / http://www.anon-design.se
 * @license		GNU/GPL, see LICENSE.txt
 */

(function($) 
{
	
	$.fn.maxlength = function(options)
	{
		var settings = jQuery.extend(
		{
			events:				      [], // Array of events to be triggerd
			maxCharacters:		  10, // Characters limit
			status:				      true, // True to show status indicator bewlow the element
			statusClass:		    "status", // The class on the status div
			statusText:			    "character left", // The status text
			notificationClass:	"notification",	// Will be added to the emement when maxlength is reached
			showAlert: 			    false, // True to show a regular alert message
			alertText:			    "You have typed too many characters.", // Text in the alert message
			slider:				      false // Use counter slider
		}, options );
		
		// Add the default event
		$.merge(settings.events, ['keyup']);

		return this.each(function() 
		{
			var item = $(this);
			var charactersLength = $(this).val().length;
			
      // Update the status text
			function updateStatus()
			{
				var charactersLeft = settings.maxCharacters - charactersLength;
				
				if(charactersLeft < 0) 
				{
					charactersLeft = 0;
				}

				item.prev("div").html(charactersLeft + " " + settings.statusText);
			}

			function checkChars() 
			{
				var valid = true;
				
				// Too many chars?
				if(charactersLength >= settings.maxCharacters) 
				{
					// Too may chars, set the valid boolean to false
					valid = false;
					// Add the notifycation class when we have too many chars
					item.addClass(settings.notificationClass);
					// Cut down the string
					item.val(item.val().substr(0,settings.maxCharacters));
					// Show the alert dialog box, if its set to true
					showAlert();
				} 
				else 
				{
					// Remove the notification class
					if(item.hasClass(settings.notificationClass)) 
					{
						item.removeClass(settings.notificationClass);
					}
				}

				if(settings.status)
				{
					updateStatus();
				}
			}
						
			// Shows an alert msg
			function showAlert() 
			{
				if(settings.showAlert)
				{
					//alert(settings.alertText);
					$("h2.characterWarning").slideDown('fast');
						
				}
			}

			// Check if the element is valid.
			function validateElement() 
			{
				var ret = false;
				
				if(item.is('textarea')) {
					ret = true;
				} else if(item.filter("input[type=text]")) {
					ret = true;
				} else if(item.filter("input[type=password]")) {
					ret = true;
				}

				return ret;
			}

			// Validate
			if(!validateElement()) 
			{
				return false;
			}
			
			// Loop through the events and bind them to the element
			$.each(settings.events, function (i, n) {
				item.bind(n, function(e) {
					charactersLength = item.val().length;
					checkChars();
				});
			});

			// Insert the status div
			if(settings.status) 
			{
				item.before($("<div/>").addClass(settings.statusClass).html('-'));
				updateStatus();
			}

			// Remove the status div
			if(!settings.status) 
			{
				var removeThisDiv = item.next("div."+settings.statusClass);
				
				if(removeThisDiv) {
					removeThisDiv.remove();
				}

			}

			// Slide counter
			if(settings.slider) {
				item.next().hide();
				
				item.focus(function(){
					item.next().slideDown('fast');
				});

				item.blur(function(){
					item.next().slideUp('fast');
				}); 
			}

		});
	};
	
})(jQuery);;
(function($){
  
	$(document).ready(function(){    
		
	  $('#edit-comment-body-und-0-value').maxlength({   
	    events: [], // Array of events to be triggerd    
	    maxCharacters: 500, // Characters limit   
	    status: true, // True to show status indicator bewlow the element    
	    statusClass: "status", // The class on the status div  
	    statusText: "characters left", // The status text  
	    notificationClass: "notification",	// Will be added when maxlength is reached  
	    showAlert: true, // True to show a regular alert message    
	    alertText: "We only allow 500-character text comments. If your comment requires more space, please choose 'Upload document' above.", // Text in alert message   
	    slider: false // True Use counter slider    
	  }); 
		
		$(".form-textarea-wrapper").append("<h2 class='characterWarning'>We only allow 500-character text comments. If your comment requires more space, please choose 'Upload document' above.<br><a href='javascript:void(0);' title='I understand'>I understand</a></h2>");
		
		$("h2.characterWarning").hide();
		
		$("h2.characterWarning a").click(function(){
			$(this).parent().slideUp();
		});
		
	});

})(jQuery);;

