String.prototype.replaceAll = function(de, para){
    var str = this;
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}

$(function(){
	$('#menu li:not(.act) a').each(function(){
		var alt = $(this).text();
		var img = $("<img />").attr('src', 'img/menu_' + alt.replace('Ç','C').toLowerCase() + '.png').attr('alt', alt);
		
		$(this).html('');
		$(this).append(img);
	}).mouseover(function(){
		var src = $(this).find('img').attr('src');
		$(this).find('img').attr('src', src.replace('.png', '_act.png'));
	}).mouseout(function(){
		var src = $(this).find('img').attr('src');
		$(this).find('img').attr('src', src.replace('_act.png', '.png'));
	});
	
	$('#menu .act').each(function(){
		var alt = $(this).text();
		var img = $("<img />").attr('src', 'img/menu_' + alt.replace('Ç','C').replace(' ','').toLowerCase() + '_act.png').attr('alt', alt);
		
		$(this).html('');
		$(this).append(img);
	});
	
	$('h2').each(function(){
		var alt = $(this).text();
		var img = $("<img />").attr('src', 'img/txt_' + alt.replaceAll('ç','c').replaceAll('ó','o').replaceAll('é','e').replaceAll('á','a').replaceAll('?','').replaceAll(':','').replaceAll('!','').replaceAll(' ','-').toLowerCase() + '.png').attr('alt', alt);
		
		$(this).html('');
		$(this).append(img);
	})
	
	$('.content h1').each(function(){
		var alt = $(this).text();
		var img = $("<img />").attr('src', 'img/tt_' + alt.replace('ç','c').replace('ó','o').replace('é','e').replace(/ /g,'').toLowerCase() + '.png').attr('alt', alt);
		
		$(this).html('');
		$(this).append(img);
	})
	
	$('#pecas h2 img').attr('src', 'img/txt_pecas2.png');
});

