jQuery(document).ready(function() {

	if( jQuery.cookie('fontSizeCookie') != null)
	{
		var newSizeCookie = jQuery.cookie('fontSizeCookie');
		jQuery('html').css('font-size', newSizeCookie + 'px');
	}
	
	jQuery('#aumentaFonte').click(function(e){
		e.preventDefault();
		incrementFontSize = parseInt(jQuery('html').css('fontSize')) + 1;
		jQuery.cookie('fontSizeCookie', incrementFontSize);
		jQuery('html').css('font-size',incrementFontSize + 'px');
	});
	
	jQuery('#diminuiFonte').click(function(e){
		e.preventDefault();
		decrementFontSize = parseInt(jQuery('html').css('fontSize')) - 1;
		jQuery.cookie('fontSizeCookie', decrementFontSize);
		jQuery('html').css('font-size', decrementFontSize + 'px');
	});
	
	jQuery('#normalFonte').click(function(e) {
		e.preventDefault();
		jQuery.cookie('fontSizeCookie', 16);
		jQuery('html').css('font-size', 16 + 'px');
	});
	
	var mudaAltoContraste = function(){
		jQuery('.baixoContraste').each(function () {
				
			jQuery(this).removeClass('baixoContraste');
			jQuery(this).addClass('autoContraste');
			
			if( jQuery(this).attr('src'))
			{
				var imgContraste = jQuery(this).attr('src');
				
				if (imgContraste.search('.gif') != -1 && imgContraste.search('blank.gif') == -1)
					imgContraste = imgContraste.replace('.gif', '_c.gif');
				
				if (imgContraste.search('.jpg') != -1)
					imgContraste = imgContraste.replace('.jpg', '_c.jpg');
				
				if (imgContraste.search('.png') != -1)
					imgContraste = imgContraste.replace('.png', '_c.png');
				
				jQuery(this).attr('src', imgContraste);
			}
			
			if( jQuery(this).css('background-image') != 'none')
			{
				var bgContraste = jQuery(this).css('background-image');
				
				bgContraste = bgContraste.replace("url(","");
				bgContraste = bgContraste.replace(")","");
				
				if(bgContraste.search('.gif') != -1)
					bgContraste = bgContraste.replace('.gif', '_c.gif');
				
				if(bgContraste.search('.jpg') != -1)
					bgContraste = bgContraste.replace('.jpg', '_c.jpg');
				
				if(bgContraste.search('.png') != -1)
					bgContraste = bgContraste.replace('.png', '_c.png');
				
				jQuery(this).css('background-image', 'url(' + bgContraste + ')');
			}

		});
	};
	
	var mudaBaixoContraste = function(){
		jQuery('.autoContraste').each(function () {
			jQuery(this).removeClass('autoContraste');
			jQuery(this).addClass('baixoContraste');																 
			
			if(jQuery(this).attr('src'))
			{
				var imgContraste = String( jQuery(this).attr('src')).replace('_c.', '.');
				jQuery(this).attr('src', imgContraste);
			}
			
			if(jQuery(this).css('background-image') != 'none')
			{
				var bgContraste = String( jQuery(this).css('background-image')).replace('_c.', '.');
				jQuery(this).css('background-image', bgContraste);
			}

		});
	}
	
	var picanha = function(e) {
		if( jQuery.cookie('contraste') == null || jQuery.cookie('contraste') == 'baixo')
		{
			jQuery.cookie('contraste', 'auto');		
			jQuery('body').addClass('contraste');
			
			mudaAltoContraste();
			
			e.preventDefault();
			return false;
		}
		else
		{
			jQuery.cookie('contraste', 'baixo');
			jQuery('body').removeClass('contraste');

			mudaBaixoContraste();

			e.preventDefault();
			return false;		
		}
	};
	
	jQuery('#mudaContraste').click(picanha);

	if( jQuery.cookie('contraste') == 'auto')
	{
			//troca IMG TAG
			jQuery('body').addClass('contraste');
			mudaAltoContraste();
			return false; 
	}
	//FIM - Contraste
	
});

