jQuery.fn.limitMaxlength = function(options){

	var settings = jQuery.extend({
		attribute: "maxlength",
		onLimit: function(){},
		onEdit: function(){}
	}, options);

	// Event handler to limit the textarea
	var onEdit = function(){
		var textarea = jQuery(this);
		var maxlength = parseInt(textarea.attr(settings.attribute));

		if(textarea.val().length > maxlength){
			textarea.val(textarea.val().substr(0, maxlength));

			// Call the onlimit handler within the scope of the textarea
			jQuery.proxy(settings.onLimit, this)();
		}

		// Call the onEdit handler within the scope of the textarea
		jQuery.proxy(settings.onEdit, this)(maxlength - textarea.val().length);
	}

	this.each(onEdit);

	return this.keyup(onEdit)
				.keydown(onEdit)
				.focus(onEdit);
}

positionElement = function(element){
	width = $(element).width()
	height = $(element).height()
	$(element).css({
		'margin-left':'-'+width/2+'px',
		'margin-top':'-'+height/2+'px'
	})
}

$(document).ready(function(){
	$('#id_cep').setMask('cep');
	$('#id_telefone').setMask('phone');
	$('#id_fax').setMask('phone');
	$('#id_cpf').setMask('cpf');
	$('#id_data_nascimento').setMask('date');
	
	$('.apoio').cycle({
		fx: 'fade',
		height: '79px',
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
			positionElement(currSlideElement)
			positionElement(nextSlideElement)
		}
	});

});
