function trata(text) {
  text = text.replace(new RegExp('[ÁÀÂÃ]','gi'), 'A');
  text = text.replace(new RegExp('[ÉÈÊ]','gi'), 'E');
  text = text.replace(new RegExp('[ÍÌÎ]','gi'), 'I');
  text = text.replace(new RegExp('[ÓÒÔÕ]','gi'), 'O');
  text = text.replace(new RegExp('[ÚÙÛ]','gi'), 'U');
  text = text.replace(new RegExp('[Ç]','gi'), 'C');
  text = text.replace(new RegExp('[ ]','gi'), '-');
  text = text.replace(new RegExp('[:]','gi'), '');
  return text;
}
jQuery.noConflict();
function popup(url){
	window.open(url,'','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=1013,height=580');
}


	/* Função do jqModal */
	var showModal = function(hash){
		jQuery(hash.w).fadeIn('2000').show();
	}

	var hideModal = function(hash) {
		jQuery(hash.w).fadeOut('2000',function(){ hash.o.remove(); });
	}

jQuery(document).ready(function(){
	var end = endereco_site;
	jQuery('.s_superficie').change(function(){
		t = jQuery('.s_tipo').val();
		s = jQuery('.s_superficie').val();

		location.href = end+'/produtos_tipo/'+t+'/'+s;

	});

	jQuery('.s_produto').change(function(){
		p = jQuery('.s_produto').val();
		
		p_ = jQuery('.s_produto option:selected').text();

		p_ = trata(p_).toLowerCase();
		
		/*
		if(p_ == 'graffiato')
			popup('http://www.graffiato.com.br/');
		else
		*/
			location.href = end+'/produto/'+p+'/'+p_;
		
	});


	jQuery('.cor').each(function(){
		jQuery(this).click(function(){
			cor = jQuery(this).css('background');
			nome = jQuery(this).html();

			jQuery('#cor_g').fadeOut('fast', function(){
				jQuery('#cor_g').css('background', cor);
			});

			jQuery('#cor_g').fadeIn('slow', function(){
				jQuery('#cor_n').html(nome);
			});
		});
	});

	/* jQuery Modal */

	jQuery('#envAmigo').jqm({
		trigger: 'a.envAmigo',
		onShow:  showModal,
		onHide:  hideModal
	});
	jQuery('#urlAtual').val(window.location);

	jQuery('#ajaxWindow').jqm({
		trigger: 'a.veja_mais2',
		ajax: '@href',
		onShow: showModal,
		onHide: hideModal
	});

	/* Formulário por Ajax */
	jQuery('#enviarAmigo').ajaxForm({
		beforeSubmit: function(){
			jQuery('#envAmigoMsg').fadeOut('slow');
			jQuery('.btn').attr('disabled','disabled');
			jQuery('.btn').val('Enviando...');
		},
		target: '#envAmigoMsg',
		success: function(){
			jQuery('#envAmigoMsg').fadeIn('slow');
			jQuery('.btn').val('Enviar');
			jQuery('.btn').attr('disabled','');
		},
		clearForm: true
	});

	/* Menu Fade */
	/*
$("p").toggle(function(){
  $(this).addClass("selected");
},function(){
  $(this).removeClass("selected");
});
*/


	jQuery('ul.menu-auxiliar li.submenu').toggle(function(){
		jQuery('li.submenu ul').fadeIn();
		jQuery(this).css({ background: "url(imagens/bck-arrow-left.gif) no-repeat 120px center"});
	},function(){
		jQuery('li.submenu ul').fadeOut();
		jQuery(this).css({ background: "url(imagens/bck-arrow-right.gif) no-repeat 120px center"});
	});

	jQuery('ul.menu-auxiliar a').click(function(){
		local = jQuery(this).attr('href');
		window.location = end+local;
	});
});
