//<![CDATA[
jQuery(document).ready(function(){
	// #animacao
	jQuery(document).pngFix();
	
    jQuery("#animacao").slideshow({
		playhoverr:true,
        playframe:false,
        play:true,
        titleshow:true,
		width:788,
		height:240,
		panel:false,
		loadframe:false,
        imgajax:true,  // by default
        imglink:true   // by default
    });
	
	// #menu
	if(!jQuery.browser.msie) {
		jQuery("ul.sub-menu").fadeTo("fast",0.9);
	}
	jQuery("ul.menu li a.sub").hover(function() {
		jQuery(this).parent().find("ul.sub-menu").slideDown('fast').show();
		jQuery(this).parent().addClass("ativo");
		jQuery(this).parent().hover(function() {
				//
		}, function() {
			jQuery(this).parent().find("ul.sub-menu").slideUp('fast',function() {
				jQuery(this).parent().removeClass("ativo");
			});
		});
	});
});


//]]>


function VEmail( strEmail ) {
     var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     return (filter.test(strEmail));
}

function Contato() {
	document.forms['formulario'].method = "post";
	document.forms['formulario'].action = "mail.php";
}

/* 
	Mascara para Campos.
	"#" - Numeros
	"A" - Letras UpperCase
	"a" - Letras LowerCase
	"Z" - Letras
	"*" - Qualquer Caracter
	"/", ".", "-", " ", ":" - Caracteres Fixos
*/
function Mascara(objeto, evt, mask) {
		
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras 	= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var Numeros = '0123456789';
	var Fixos 	= '().-:/ '; 
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";
	
	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		tecla = Charset.substr(ntecla - 32, 1);
		if (ntecla < 32) return true;

		var tamanho = value.length;
		if (tamanho >= mask.length) return false;

		var pos = mask.substr(tamanho,1); 
		while (Fixos.indexOf(pos) != -1) {
			value += pos;
			tamanho = value.length;
			if (tamanho >= mask.length) return false;
			pos = mask.substr(tamanho,1);
		}

		switch (pos) {
				case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
				case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
				case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
				case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
				case '*' : objeto.value = value; return true; break;
				default : return false; break;
		}
	}
	objeto.value = value; 
	return true;
}

function contarCaracteres(oCampo){
	var cTotal;
	var hohoho;
	cTotal = document.form1.mensagem.value.length;
	if (event.keyCode == 8)
		hohoho = cTotal - 1;
	else
		hohoho = cTotal + 1;
	if(cTotal > 249 && event.keyCode != 8 && event.keyCode != 46){
		return false;
	}	
	document.getElementById('cTotal').innerHTML = 250 - hohoho;
	return true;
}


// Deixa a string apenas com os numeros, eliminando o restante.
function trimToDigits(string) {
	s = "";
	var Numeros = /\d/;
	for (i = 0; i <= string.length; i++) 
		if (Numeros.test(string.substr(i,1))) s += string.substr(i,1);
	return s;	
}

function MaskTelefone(objeto, evt) { 
	return Mascara(objeto, evt, '(##) ####-####');
}
function MaskData(objeto, evt) { 
	return Mascara(objeto, evt, '##/##/####');
}
function MaskCPF(objeto, evt) { 
	return Mascara(objeto, evt, '###.###.###-##');
}

function ajaxInit() {
	var req;
	
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ex) {
			try {
				req = new XMLHttpRequest();
			} catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
	}
	return req;
}

function DecHex(dec2) {  
    var hex_chars = "0123456789ABCDEF";  

    var n1 = hex_chars.charAt(Math.floor(dec2 / 16));  
    var n2 = hex_chars.charAt(dec2 % 16);  

    return n1 + n2;  
}  

function formSender(f) {  
    var acao = f.action;  
    var metodo = f.method.toLowerCase();  
    
	if (!document.forms['formulario'].nome.value) { alert("What's your name?\nQual é o seu nome?"); document.forms['formulario'].nome.focus(); return false; };
	if (!VEmail( document.forms['formulario'].email.value)) { alert("What's your e-mail?\nQual é o seu e-mail?"); document.forms['formulario'].email.focus(); return false; };
	if (!document.forms['formulario'].mensagem.value) { alert("What's your message?\nQual é a sua mensagem?"); document.forms['formulario'].mensagem.focus(); return false; };

	if(!acao) {  
        alert("erro: O valor action do formulário não foi definido.");  
    }  
      
    var send = new Array();  
    var elementos = f.elements;  
      
    for(var i = 0; i < elementos.length; i++) {  
        var e = elementos[i];  
        if(!e.name)  
            continue;  
          
        var nVal = "";  
          
        for(var x = 0; x < e.value.length; x++) {  
            codeA = e.value.charCodeAt(x);  
            codeA = DecHex(codeA);  
            nVal += "%" + codeA;  
        }  
          
        var tipo = e.type.toLowerCase();  
          
        if(tipo != "checkbox" && tipo != "radio") {  
            send[send.length] = e.name + "=" + nVal;  
        } else {  
            if(e.checked) {  
                send[send.length] = e.name + "=" + nVal;  
            }  
        }  
    }  
      
    send = send.join("&");  
    var ajax = ajaxInit();  
      
    if(ajax) {  
        if(metodo == "post") {  
            ajax.open("POST", acao, true);  
            ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
        } else {  
            ajax.open("GET", acao + "?" + send, true);  
        }  
          
        ajax.onreadystatechange = function() {  
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					document.getElementById('formularioEmail').innerHTML = ajax.responseText;
				};
			}
		}  
          
        if(metodo == "post") {  
            ajax.send(send);  
        } else {  
            ajax.send(null);  
        }  
    }  
}
function ExibeFlash(w,h,wmode,movie) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="'+wmode+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}


/* Alert p/ validação do Form, Mensagem e Campo */
function alertMessage(str,obj) {
	alert(str);
	obj.focus();
	return false;
}


/* Verifica se o campo está vazio */
function isInputEmpty(obj) {
	return obj.value.length == 0;
}


function vFormulario(obj) {
	
	for(var i = 0; i < obj.length; i++) {
		var campo = document.getElementById(obj[i]);
		if(isInputEmpty(campo)) {
			alertMessage("Campo obrigatório não informado.",campo);
			return false;
		}
	}
	return true;
}