$(document).ready(function() {  
	  
         $('#rotator-img').cycle({
             fx: 'scrollVert',
             cleartype: !$.support.opacity,
             delay:  -1000,
             timeout: 6000,
             speed: 3000,
             pause: true
          });

        $('input, textarea, select').bind({
            click: function() {
             validar($('#formContato'));
            },
            focus: function() {
              validar($('#formContato'));
            },
            keypress: function() {
              validar($('#formContato'));
            }
        });
        
        $('#proje').cycle({
            fx:    'scrollDown',
            easing: 'easeInOutBack', 
             cleartype: !$.support.opacity,
             delay:  -1000,
             timeout: 6000,
             speed: 3000,
             pause: true
          });
});

//Imagem load
function imgLoaddefault (x){
    var a = '<img src="images/load'+x+'.gif"/>';
    return a;
}

/*Mascara*/
function mascara(Field, m, e) {
    var Value = Field.value.replace( /\W/gi, "" ),i;

    for (i = 0; i < Value.length; i ++) {
        if (!/[#A9%]/.test(m.charAt(i))) {
            Value = Value.splice(i, 1, m.charAt(i) + Value.charAt(i));
        }
    }

    var ValueFormated = '';
    for (i = 0; i < Value.length; i ++) {
        if (
            (m.charAt(i) == "A" && /[a-z]/i.test(Value.charAt(i))) ||
            (m.charAt(i) == "9" && /[0-9]/.test(Value.charAt(i))) ||
            (m.charAt(i) == "%" && /[0-9a-fA-F]/.test(Value.charAt(i))) ||
            (m.charAt(i) == "#" && /\w/.test(Value.charAt(i)))
            ) {

            ValueFormated += Value.charAt(i);

        }else if (m.charAt(i) == Value.charAt(i)){
            ValueFormated += Value.charAt(i);
        }
    }

    if (ValueFormated.replace( /\W/gi, "" ) == ''){
        ValueFormated = '';
    }

    Field.value = ValueFormated;
}

String.prototype.splice = function (i, offset, str) {
    if (i < 0)
        i = this.length + i;

    return this.substr(0, i) + (str || "") + this.substr(i + offset, this.length)
}

/*///////// COMENTARIO ////////////*/
function validar(form) {
        var cont=0;
        $('#contato-retorno').fadeOut();
       $(form).find('input[type="text"], textarea, select').each(function(){
           if($(this).attr('id')=='email'){
                var vEmail = $(this).val();
                var eEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
                    if($(this).val()  == ""){
                      $(this).next().html(' Obrigatório').fadeIn('slow');
                        cont = cont + 1;
                    }else if ( !(eEmail.test(vEmail))) {
                        $(this).next().html(' E-mail inválido').fadeIn('slow');
                        cont = cont + 1;
                    }else $(this).next().empty().fadeOut('slow');
           }else if($(this).attr('id')=='fone'){
               if( $(this).val() == '' ) {
                    $(this).next().html(' Obrigatório').fadeIn('slow');
                    cont = cont + 1;
                }else if ( $(this).val().length < 14) {
                    $(this).next().html(' Telefone inválido').fadeIn('slow');
                    cont = cont + 1;
                }else $(this).next().empty().fadeOut();
           }else{
               if( $(this).val() == '') {
                    $(this).next().html('Obrigatório').fadeIn('slow');
                    cont = cont + 1;
                }else{
                    $(this).next().empty().fadeOut('slow');
                }
           }
       });

       return cont;
}

function enviarEmail(form)
{
    var cont = validar(form);
    if(cont <= 0) {
        document.getElementById('formContato').submit();
    }else return false;
}

