/*	
    Nova Rio
    cbc.org.br
    
    por: M2BRNET (http://www.m2brnet.com)
\* ......................................................................................................................................... */

/*
	Namespace
\* ......................................................................................................................................... */

var M2 = function() {

	function Tabs(el) {
		var tabContainers = $('.tab-content .tabs',el),
			tabNav        = $('.tab-nav a',el);
		$(tabNav).click(function () {
			tabContainers.hide().filter(this.hash).show();
			$(tabNav).removeClass('active');
			$(this).addClass('active');
			return false;
		}).filter(':first').click();
	}

	return {
		External: function() {
			$('a[rel*="external"]').attr('target','_blank');
		},
		SetTabs: function(el) {
			var el = $("#"+el);
			if (el.length > 0) {
				Tabs(el);
			}
		},
		Init: function(){

			M2.External();
			M2.SetTabs('tabs-container');

			swfobject.embedSWF("../_swf/mosaico/mosaico.swf", "clientes", "600", "300", "9.0.0");
			swfobject.embedSWF("../_swf/certificados/banner_site.swf", "certificados", "600", "300", "9.0.0");

			$('#fc-cpf').mask("999.999.999-99");
			$('#fc-cep').mask("99999-999");
			$('#fc-telres,#fc-telcel,#fc-telrec,#fp-tel').mask("(99) 9999-9999");
			$('#fc-data,#fc-inicio1,#fc-inicio2,#fc-inicio3,#fc-fim1,#fc-fim2,#fc-fim3').mask("99/99/9999");
			$('#fc-previsao').mask("99/9999");
			

			$('.cnt-toggler').hide();
			$('#duvidas .lnk-toggler, #convenios .lnk-toggler').click(function(){
				$(this).next('.cnt-toggler').toggle();
				return false; 
			});

			$('#banner.aviaslider').aviaSlider({
				blockSize: { 
					width: 'full', 
					height: 40
				},
				display: 'topleft',
				transition: 'fade',
				slides: '.slide',
				autorotationSpeed: 3,
				betweenBlockDelay: 50,
				animationSpeed: 1000,
				switchMovement: true,
				slideControlls: false,
				showText: false,
				backgroundOpacity: 0.5
			});	
		}
	};

}();

/*
	DOM Loaded
\* ......................................................................................................................................... */

$(function(){ M2.Init(); });

var limitCaracteres = function(textid, limit, infodiv) {
	var text = $('#'+textid).val(),
		textlength = text.length;

	if (limit === 0) {
		$('#' + infodiv).html(''+ textlength +' caracteres digitados.');
		return true;
	} else {
		if(textlength > limit) {
			$('#' + infodiv).html('Atingido o limite máximo de '+limit+' caracteres!');
			$('#'+textid).val(text.substr(0,limit));
			return false;
		} else {
			$('#' + infodiv).html('Você possui '+ (limit - textlength) +' caracteres restantes.');
			return true;
		}		
	}
};

