jQuery.fn.extend({

	fontSize: function(o) {
	/*
	*  Funcao que altera o tamanho dos textos e grava em cookie
	* 	
	*  ** FEATURES:
	*  *  - 	
	*  **
	*  	
	*  ** PARAMETROS:
	*  *  elements: elementos a mudar o tamanho de texto
	*  **	
	* 
	*  ** TODO: 
	*  *  - 
	*  **	
	*/	

		o = $.extend({
			elements: 'body' // elementos onde vai alterar o tamanho do texto
		}, jQuery.fn.fontSize.defaults, o);

		var obj = jQuery(this);

		jQuery(".font-min", this).click(function(){btFontSize(80);return false})
		jQuery(".a2", this).click(function(){btFontSize(100);return false})
		jQuery(".a3", this).click(function(){btFontSize(140);return false})
		
		btFontSize = function(size){
			saveCookie('fontSize',size);
			dFontSize(size);
		}
		
		dFontSize = function(size){
			var cont, butao;
			
			butao = jQuery("li", obj)
			for (var j=0; j<butao.length; j++){
				if(butao[j].className==size){
					jQuery(butao[j]).addClass('off');
				} else if(butao[j].className.indexOf('off')) {
					jQuery(butao[j]).removeClass('off');
				}
			}
	
			if(size) {
				jQuery(o.elements).each(function(i, item) {
					jQuery(item).css("font-size", size + "%");
					if (size > 120) {
						jQuery(item).css("fontWeight", "bold")
					} else {
						jQuery(item).css("fontWeight", "normal")
					}
				})
			}
      //return;
		}

		var sizeCook = loadCookie('fontSize');
		if(typeof(sizeCook) != 'undefined'){
		  dFontSize(sizeCook)
    }
	
	}
});

saveCookie = function(nam,val){
	var expire = new Date ();
	expire.setTime (expire.getTime() + (6000 * 24 * 3600000));
	expire = expire.toGMTString();
	document.cookie=nam+"="+val+"; path=/; expires="+expire;
}

loadCookie = function(nam){
	var nameEQ = nam + "=";
	var coks = document.cookie.split(';');
	for(var i=0;i < coks.length;i++) {
		var c = coks[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nam) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
