//==========================================================================================
// JavaScript Global Functions




//==========================================================================================
// jQuery Global Functions
jQuery(document).ready(function($) {
						   
	// --------------------------------------------------------------------------------------
	// BEGIN: j_on - if javascript is enabled add this class to body:
	$("body").addClass("j_on");
	// END: j_on
	
	
	// --------------------------------------------------------------------------------------
	// BEGIN: j_clear_input - Clear's input field's DEFAULT text. Matches attribute - "title"
	$(".j_clear_input").each(function() {
		if ($(this).val() == $(this).attr("title")) {
			$(this).addClass("off");
		}
	});
	$(".j_clear_input").focus(function() {
		if ($(this).val() == $(this).attr("title")) {
			$(this).val("");
			$(this).removeClass("off");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("title"));
			$(this).addClass("off");
		}
	});
	// END: j_clear_input
	
	
	// --------------------------------------------------------------------------------------
	// BEGIN: j_menu - show/hide dropdown menu
	$(".j_menu_arrow").click(function() {
		$(this).parents(".j_menu:first").addClass("j_menuIsOver");
	});
	
	$(".j_menu").hover(function() {
		
	},function() {
		$(this).removeClass("j_menuIsOver");
	});
	// END: j_menu
	
	
	// ---------------------------------------------------------------------------------------
	// BEGIN: homepage mycarousel
	$('#mySlider').cycle({
		fx:     'fade',
		speed:  'slow', 
		timeout: 7000, 
		next:   '#mySlider_next',
		pause: 1,
		pager:  '#mySlider_nav',
		startingSlide: 0,
		pagerAnchorBuilder:function(idx, slide) {
			return '<a href="javascript:;" class=""></a>';
		}
	});
	// END: mycarousel
	
	// --------------------------------------------------------------------------------------
	// BEGIN: j_tab_wrapper - show/hide tabs and content
	$(".bank_fraud_forum_callout .j_tab a").click(function(){
		// clear
		$(".bank_fraud_forum_callout .active").removeClass("active");
		
		// activate
		$(this).parents(".j_tab_container").addClass("active");
		
	});
	// END: j_tab_wrapper
	
	// ---------------------------------------------------------------------------------------
	// BEGIN: j_accordion
	$(".j_accordion h3 a").click(function() {
		if ( !$(this).parents(".accordion_tab:first").hasClass("active") ) {
			$(".j_accordion .active .accordion_body").slideUp();
			$(".j_accordion .active").removeClass("active");
			$(this).parents(".accordion_tab:first").find(".accordion_body").slideDown();
			$(this).parents(".accordion_tab:first").addClass("active");
		}
	});
	
	$(".j_accordion .accordion_tab").hover(function() {
		$(this).addClass("over");
	}, function() {
		$(this).removeClass("over");
	});
	// END: j_accordion
	
	// ---------------------------------------------------------------------------------------
	// BEGIN: Ellipsis - after max character | slice points
	/* Keep HTML tags */
	function useEllipsis (maxChars, className) {
		var slicePoint = maxChars;
		$(className).each(function() {
			var allText = $(this).html();
			
			if (allText.length > slicePoint) {
				// This cuts off after 130 characters but up to the word
				var startText = allText.slice(0,slicePoint).replace(/\w+$/,''); 
				
				// Add ellipsis
				startText = startText + "...";
				$(this).html(startText);
			}
		});
	}
	
	/* Strips HTML tags */
	function useEllipsisNoHTML (maxChars, className) {
		var slicePoint = maxChars;
		$(className).each(function() {
			var allText = $(this).html();
			var editText;
			
			// This removes all HTML Tags
			editText = allText.replace(/<\/?[^>]+>/gi, ''); 
			
			if (editText.length > slicePoint) {
				// This cuts off after 65 characters but up to the word
				var startText = editText.slice(0,slicePoint).replace(/\w+$/,''); 
				
				// Add ellipsis
				startText = startText + "...";
				$(this).html(startText);
			}
		});
	}
	
	//Initialize Ellipsis
	//useEllipsis (125, ".ellipsis_title");
	useEllipsisNoHTML (160, ".title_area h1");
	useEllipsisNoHTML (450, ".home .slide_txt_only .text");
	// END: Ellipsis
	
	
	// ------------------------------------------------------------------------------
	// BEGIN: PNG IE6 Fix
	// IE6 bug - fixes png transparency images, replaces with spacer.gif and updates CSS
	if ($.browser.msie && $.browser.version<"7") {
		// Connect With Us Icons
		$('.social_list img, .footer_icons img').each(function(){
			imgsrc = $(this).attr('src');
			matches = imgsrc.match(/.png/);
			// don't do the rollover if state is already ON
			if (matches) {
				$(this).width(24);
				$(this).height(24);
				$(this).attr('src', '/Images/CommonImages/spacer.gif');
				newFilter = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgsrc + "', sizingMethod='crop');";
				$(this).attr('style', newFilter);
			}
		});
	}
	// END: PNG IE6 Fix
	
	
});
