$(document).ready(function(){
	
	//troca flash por imagem para compensar transparencia
	if($.browser.safari){
		
		$('#flash-logo').hide();
		$('#img-logo').show();
	}
	
	//js do label da pesquisa
	$("#pesquisa-home").click(function () {
			
		if ($("#pesquisa-home").val()==pesquisarproduto) {
			$("#pesquisa-home").val('');
		}
	});

	$("#pesquisa-home").blur(function () {
	
		  if ($("#pesquisa-home").val()=="") {
				$("#pesquisa-home").val(pesquisarproduto);
		}
	});
	
});

function trim (str, charlist) {
    // Strips whitespace from the beginning and end of a string  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/trim    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: mdsjack (http://www.mdsjack.bo.it)
    // +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
    // +      input by: Erkekjetter
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // +      input by: DxGx
    // +   improved by: Steven Levithan (http://blog.stevenlevithan.com)
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // *     example 1: trim('    Kevin van Zonneveld    ');    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: trim('Hello World', 'Hdle');
    // *     returns 2: 'o Wor'
    // *     example 3: trim(16, 1);
    // *     returns 3: 6    var whitespace, l = 0, i = 0;
    str += '';
    
    if (!charlist) {
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');    
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {            str = str.substring(i);
            break;
        }
    }
        l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

function executaForm(url,elemento){
	var valor = jQuery.trim(elemento.elements[0].value);
	valor = valor.replace(/\ /g,'+');
	valor = valor.replace(/\//g,'');
	window.location = url+'/'+valor
}

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}

function seoUrl(input, replace)
{
	replace = '-';
	
    arrayIn = ['Á','À','Â','Ã','ä','Ä,','á','à','â','ã','ª','É','È','Ê','é','è','ê','í','î','Í','ì','Ì','Î',
                        'ï','Ï','Ó','Ò','Ô','Õ','ó','ò','ô','õ','º','Ú','Ù','Û','ú','ù','û','ü','Ü'];
    arrayOut = ['a','a','a','a','a','a','a','a','a','a','a','e','e','e','e','e','e','i','i','i','i','i','i',
                        'i','i','o','o','o','o','o','o','o','o','o','u','u','u','u','u','u','u','u'];


    input = str_replace(arrayIn, arrayOut, input);

    input = str_replace("Ç","c",input);
    input = str_replace("ç","c",input);
    input = str_replace(",","",input);
    input = str_replace(".","",input);
    input = str_replace(":","",input);
    input = str_replace(";","",input);
    input = str_replace("+","",input);

    output = trim(input.toLowerCase().replace(/[^a-zA-Z0-9.\s]/g,'').replace(/[\s]+/g,' '));
    
    return str_replace(' ', replace, output); 
}
