(function ($) {
	 $().ready(function(){
			
			// Keep the main menu item highlighted when hovering over its dropdown items
			$("#block-system-main-menu .expanded").hover(function () {
			    $(this).children('a').andSelf().addClass("hover");
			}, function () {
			    $(this).children('a').andSelf().removeClass("hover");
			});
		
		if ($('body').hasClass('page-node-24'))	{	
			// Apply collapsible block sets to about-us/people page
			// Adding and removing the visuallyhidden class keeps content accessible
			$("#main .block-views .view-people").addClass('visuallyhidden slidecontainer');
			$("#main .block-views header").addClass("expandable closed");
			$("#main .block-views header").click(function() {
					$(this).toggleClass("opened closed");
					$(this).siblings('.view-people').toggleClass('visuallyhidden');
					return false;
				});
		}
				
		if ($('body').hasClass('page-node-51'))	{
			// Build map helper tools on help/maps page	
		    $('#nationalmaphelp').mousemove(function(e){
		       var x = e.pageX - this.offsetLeft;
			   var y = e.pageY - this.offsetTop;
			   $('.nationalmaphelp-xy').html("X: " + x + " Y: " + y); 
		    });
		    $('#pacificmaphelp').mousemove(function(e){
		       var x = e.pageX - this.offsetLeft;
			   var y = e.pageY - this.offsetTop;
			   $('.pacificmaphelp-xy').html("X: " + x + " Y: " + y); 
		    });
		    $('#rockymountainmaphelp').mousemove(function(e){
		       var x = e.pageX - this.offsetLeft;
			   var y = e.pageY - this.offsetTop;
			   $('.rockymountainmaphelp-xy').html("X: " + x + " Y: " + y); 
		    });
		    $('#midwestmaphelp').mousemove(function(e){
		       var x = e.pageX - this.offsetLeft;
			   var y = e.pageY - this.offsetTop;
			   $('.midwestmaphelp-xy').html("X: " + x + " Y: " + y); 
		    });
		    $('#southernmaphelp').mousemove(function(e){
		       var x = e.pageX - this.offsetLeft;
			   var y = e.pageY - this.offsetTop;
			   $('.southernmaphelp-xy').html("X: " + x + " Y: " + y); 
		    });
		    $('#northeastmaphelp').mousemove(function(e){
		       var x = e.pageX - this.offsetLeft;
			   var y = e.pageY - this.offsetTop;
			   $('.northeastmaphelp-xy').html("X: " + x + " Y: " + y); 
		    });
		 }
		
		if ( $('body').hasClass('front') || $('body').hasClass('regional-map') )	{
		   // Show/hide mapping points
		   $('.borrower').hide();
		   $('.loanpoints a').click(function (e) {
			e.preventDefault(); // cancel default behavior
			});
		   $('.loanpoints li').hover(
		    function () {
		     var loanid = $(this).find("a").attr("href");
		     $(loanid).show();
		     $('.borrower').not(loanid).hide();
		     $('.borrowers').removeClass('auto');
		   }, 
		     function () {
		       var loanid = $(this).find("a").attr("href");
		     }
		   );
		   $('.loanpoints li a').focus(
		    function () {
			 var loanid = $(this).attr("href");
		     $(loanid).show();
		     $('.borrower').not(loanid).hide();
		   });
		
		  // Create a slideshow of borrows until someone hovers over a pointer
		  $('.borrowers').addClass('auto');
		  $('.auto li:first-child').show();
		  if ($('.auto').children().length > 1) {
		    $(function(){
		      $('.auto li:not(:first-child)').hide();
		    setInterval(function(){
		      $('.auto li:first-child').hide()
		         .next('li').fadeIn(2000)
		         .end().appendTo('.auto');}, 
		      8000);
		    });
	       }
	    }
	
		  // Create slideshow of NWC facts
		  $('#block-views-impact-facts-block .view-content').addClass('slidefacts');
		  $('.slidefacts .views-row:first-child').show();
		  if ($('.slidefacts').children().length > 1) {
		    $(function(){
		      $('.slidefacts .views-row:not(:first-child)').hide();
		    setInterval(function(){
		      $('.slidefacts .views-row:first-child').hide()
		         .next('.views-row').fadeIn(1500)
		         .end().appendTo('.slidefacts');}, 
		      5000);
		    });
	       }
			
			// Hide the loan descriptions in the All States view and create clickable element to toggle it
	   		if ( $('body').hasClass('page-impact-lending-activity-states') )	{
				$('#main h3').append(' <span class="clickable read-more element-focusable">Loan&nbsp;Info</span>');
				$(this).find('.loan-description').hide();
				$('#main h3 .clickable').click(function() {
				  $(this).parent('h3').siblings('.loan-description').slideToggle('slow', function() {
				     
				  });
				});
			}
	
			// If width is higher then breaking point set blocks on home page to equal heights
		    if ($('body').hasClass('front') && $(window).width() > 768) {
				var block1 = $('#block-views-news-block');
				var block2 = $('#block-views-loan-products-block-1');
				var block3 = $('#block-views-impact-facts-block');
				var tallest = '';
				var height1 = block1.height();
				var height2 = block2.height();
				var height3 = block3.height();
				if ( height1 > height2 && height1 > height3 ){ tallest = height1; }
				if ( height2 > height1 && height2 > height3 ){ tallest = height2; }
				if ( height3 > height1 && height3 > height2 ){ tallest = height3; }
				block1.css("min-height", tallest);
				block2.css("min-height", tallest);
				block3.css("height", tallest);
		    }
		
			// If width is higher then breaking point add image map to national map
		    if ($('body').hasClass('page-node-70')) {
				if ( $(window).width() > 800 ) {
					var imgmap = [
					'<map name="regions" id="regions">', 
					'<area shape="poly" coords="39,3,9,119,30,216,65,255,81,468,167,439,186,410,258,440,268,426,343,459,360,445,337,418,274,386,178,322,91,260,85,251,101,230,52,153,62,104,95,113,100,78,112,64,103,53,116,14,62,0,36,1" href="/impact/lending-activity/pacific" title="Pacific" alt="Pacific"/>', 
					'<area shape="poly" coords="117,14,238,30,234,152,256,153,251,208,236,204,239,221,271,221,271,253,313,265,340,260,353,301,351,321,305,357,309,380,284,368,252,315,233,332,215,318,207,297,135,285,89,255,108,233,57,152,65,112,98,120,105,83,115,67,112,54,118,16" href="/impact/lending-activity/rocky-mountain" title="Rocky Mountain" alt="Rocky Mountain"/>', 
					'<area shape="poly" coords="244,32,332,30,382,48,443,65,474,108,488,125,492,154,477,177,447,165,416,193,396,218,339,217,342,258,280,246,278,217,255,218,260,147,238,148,244,32,242,31" href="/impact/lending-activity/midwest" title="Midwest" alt="Midwest"/>',
					'<area shape="poly" coords="342,220,386,216,398,229,413,204,459,174,481,180,496,156,508,166,524,155,563,204,509,289,540,351,532,372,515,356,495,332,491,311,471,299,462,309,401,309,414,325,356,320,358,298,352,284,351,260,344,258,339,217" href="/impact/lending-activity/southern" title="Southern" alt="Southern"/>',
					'<area shape="poly" coords="492,121,540,60,584,43,591,14,606,14,619,54,589,79,595,96,611,102,571,132,558,184,530,152,498,153,490,120" href="/impact/lending-activity/northeast" title="Northeast" alt="Northeast"/>',
					'</map>'
					].join("");
					$('#regional-map img').attr('usemap','#regions').after(imgmap);
				}
		    }
		
			// If width is higher then breaking point set blocks on home page to equal heights
		    if ($('html').hasClass('ie7') && $('body').hasClass('front')) {
				var blockA = $('#block-views-news-block');
				var blockB = $('#block-views-loan-products-block-1');
				var blockC = $('#block-views-impact-facts-block');
				$(blockA).addClass('bottom-block');
				$(blockB).addClass('bottom-block');
				$(blockC).addClass('bottom-block');
				$('.bottom-block').wrapAll('<div></div>');
		    }
	
	 });	
})(jQuery);;

