function updateCountdownAll() {
    $('.message').each(function () {
        updateCountdown(this);
    });
}

function updateCountdown(e) {

    var currentElement;
    if (e.target) {
        currentElement = e.target;
    } else {
        currentElement = e;
    }

    var maxLengh = $(currentElement).attr('maxlength');
    var remaining = maxLengh - $(currentElement).val().length;
    $(currentElement).nextAll('.countdown:first').text(remaining + ' characters remaining.');
}
function addTag(){
maxtagcount--;
if(maxtagcount == 0){
	$("#tags_1_addTag").hide();
}
updateTagMsg();
}

function removeTag(){
maxtagcount++;
if(maxtagcount > 0){
	$("#tags_1_addTag").show();
}
updateTagMsg();	
}

function updateTagMsg(){
	$("#maxTags").html("Maximum " + maxtagcount + " tags remaining");
}

var maxtagcount = 10;

$(function($) {'use strict',
$(document).ready( function(){
	$(":file").filestyle({icon: false});
		//Slider
		$('.indexSlider').bxSlider({
			  mode:'fade',
			  pager: false,
			  auto:true,
			  
		});
		
		//Large Product View Slider
$('.largeSlider').bxSlider({
    mode:'fade',
    minSlides:1,
    maxSlides:1,
    moveSlides:1,
    slideMargin:0,
	pagerCustom: '#productThumb'
  });


	//Product Thumb Slider
	
			$('.thumSlider').bxSlider({
			mode: 'horizontal',
			minSlides:5,
			maxSlides:5,
			moveSlides:1,
			slideMargin:10,
			infiniteLoop:true,
			
			touchEnabled:true
		});
		
		
		//navigation
		$('nav').meanmenu();
		
		if( $(".tabbingArea").length) {
		$('.tabbingArea').responsiveTabs({
			startCollapsed: 'accordion', //accordion
			collapsible: 'accordion' //accordion

		});
	}	
	

	$('input[type="radio"]').click(function(){
        if($(this).attr("value")=="yes"){
            $(".fundDetail").show();
        }
        else{
        	$(".fundDetail").hide();
        }
    });

		
	$('.filterBar a').click( function(event){
		event.stopPropagation();
		if ($(this).hasClass('active')) {
			$('.sub').fadeOut();
			$('.filterBar a').removeClass('active');
		} else {
			$('.filterBar a').removeClass('active');
			$('.sub').fadeOut();
			$(this).parent().find('.sub').fadeIn();
			$(this).addClass('active');
		}
	});
	
	$(document).click( function(){
		$('.sub').fadeOut();
		$(".filterBar a.active").removeClass('active');
   });	
	$('.sub').click(function(e){
		e.stopPropagation();
	});
	
	
	updateCountdownAll();
    $('.formCol').on('input', '.message', updateCountdown);

	$('#tags_1').tagsInput({
	        width: 'auto',
	        onAddTag:addTag,
	        onRemoveTag:removeTag
	});	
		
});	
});

