$(document).ready(function() {

  // Creating custom :external selector
  $.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
      		&& !obj.href.match(/^javascript\:/)
            && (obj.hostname != location.hostname);
  };

  // Add 'external' CSS class to all external links
  $('a:external').addClass('external');
  $('area:external').addClass('external');

  $('.external').click(function() {
    var link = $(this).attr('href');
	/*Original Wording <div>You are leaving the credit union\'s web site. and is headed towards:  <br /><br /> <strong>'+(link)+'</strong><br /><br />You are linking to an alternate web site <em>not operated</em> by the credit union.<br /><br />The credit union is <em>not responsible</em> for the content of the alternate web site.<br /><br />The credit union <em>does not represent</em> either the third party or you if the two enter into a transaction. Privacy and security policies may differ from those practiced by the credit union.<br /><br />Click \'I Agree\' if you agree with this policy.</div>'*/
    $('<div>You are leaving the credit union\'s web site.  You are linking to an alternate web site <em>not operated</em> by the credit union.<br /><br />The credit union is <em>not responsible</em> for the content of the alternate web site.<br /><br />The credit union <em>does not represent</em> either the third party or you if the two enter into a transaction. Privacy and security policies may differ from those practiced by the credit union.<br /><br />Click \'I Agree\' if you agree with this policy.</div>').dialog({
      title: "Community Credit Union Privacy Policy",
      modal : true,
      width : 580,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'I Agree': function() {
          $(this).dialog('close').remove();
          window.open(link);
        },
        'Cancel': function() {
          $(this).dialog('close').remove();
          return false;
        }
      }
    });

    return false;
  });
  //MEGA MENU TIME
  function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#megamenu li .sub").css({'opacity':'0'});
	$("ul#megamenu li").hoverIntent(config);
  
  
  // Fancy rollover breadcrumbs
	$('#sidenav li').mouseover(function(){
		$(this).parents('li').children('a').addClass('activeside');
	});
	$('#sidenav li').mouseout(function(){
		$(this).parents('li').children('a').removeClass('activeside');
	});
	$('#main-sideNav li').mouseover(function(){
		$(this).parents('li').children('a').addClass('activeside');
	});
	$('#main-sideNav li').mouseout(function(){
		$(this).parents('li').children('a').removeClass('activeside');
	});
	$('#navigation li').mouseover(function(){
		$(this).parents('li').children('a').addClass('active');
	});
	$('#navigation li').mouseout(function(){
		$(this).parents('li').children('a').removeClass('active');
	});
});

//Equal Columns-----------------------------------------------------------------//
$(document).ready(function(){
    	$(function(){
    	    $('.column').equalHeight();
   	});
    });

// make sure the $ is pointing to JQuery and not some other library

(function($){
// add a new method to JQuery
$.fn.equalHeight = function() {
// find the tallest height in the collection
// that was passed in (.column)
tallest = 0;
this.each(function(){
thisHeight = $(this).height();
if( thisHeight > tallest)
tallest = thisHeight;
});

// set each items height to use the tallest value found
this.each(function(){
$(this).height(tallest);
});
}
})(jQuery);


//jQuery Innerfade-----------------------------------------------------------//
$(document).ready(
	function(){
		$('#rotate').innerfade({
			animationtype: 'fade',
			speed: 1000,
			timeout: 5000,
			containerheight: '125px'
		});
	});
	
//Clear Text----------------------------------------------------------------//
function clearText(field){

if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;

}

