

( function( $ ) {
	
	var phoneRight = -115;
	var contactRight = -115;
	var gisRight = -115;
	
	var body    = $( 'body' ),
	    _window = $( window );

	$(document).click(function(event) {
		var $target = $(event.target);
		if (!$target.is("#phoneButton")) { 
			if($("#phoneButton").css('right') == '0px') $("#phoneButton").css('right',phoneRight);
		}
		if (!$target.is("#emailButton")) { 
			if($("#emailButton").css('right') == '0px') $("#emailButton").css('right',contactRight);
		}
		if (!$target.is("#gisButton")) { 
			if($("#gisButton").css('right') == '0px') $("#gisButton").css('right',gisRight);
		}
	});
	/**
	 * Enables menu toggle for small screens.
	 */
	( function() {
		var nav = $( '#site-navigation' ), button, menu;
		if ( ! nav )
			return;

		button = nav.find( '.menu-toggle' );
		if ( ! button )
			return;

		// Hide button if menu is missing or empty.
		menu = nav.find( '.nav-menu' );
		if ( ! menu || ! menu.children().length ) {
			button.hide();
			return;
		}

		$( '.menu-toggle' ).on( 'click.wafd', function() {
			nav.toggleClass( 'toggled-on' );
		} );
	} )();
	
	$('#navButton').on('click',function() {
		if($("#navWrapper .nav").is(':visible')) $("#navWrapper .nav").hide("slide",{direction: 'up'},300);
		else {
			$("#navWrapper .nav").show("slide",{direction: 'up'},300);
			//$("#header .inner-header .main-nav-v2").addClass('mobileLoaded');
		}
		//hide submenus that were open
		//$("#navWrapper .nav ul li ul").hide();	
	});
	
	$('#navWrapper .nav ul li').on('click',function() {
		if($('#navButton').css('display') == 'block') {
			// for showing and hiding sub menus
		/*if($(this).find('ul').is(':visible')) $(this).find('ul').hide("slide",{direction: 'up'},300);
		else {
			$("#navWrapper .inner-header .main-nav-v2 ul li ul").hide();
			$(this).find('ul').show("slide",{direction: 'up'},300);	
		}*/
		}
	});
	
	$(window).resize(function() {
		$("#navWrapper .nav").attr('style','');
		$("#navWrapper .nav ul li ul").attr('style','');
		//$("#header .inner-header .main-nav-v2").removeClass('mobileLoaded');
	});
	
	$('.gridItem').tooltip({
	  position: { my: "center top+100", at: "center top"},
  	  tooltipClass:"ui-tooltip"

	});
	
	$('.postWrapper .postItem').on('click',function() {
		window.location = $(this).attr('theLink');
	});
	$('.postWrapper .postItem').matchHeight(
		{
			byRow: true,
			property: 'height',
			target: null,
			remove: false
		}
	);
	
} )( jQuery );