$(document).ready(function() {  
	  $("ul.menubar li.submenu-trigger").mouseover(function()
        {
            $(this).find('a:first').removeClass().addClass('sub-menu-class-active');
            $(this).find("div.sub-menu").slideDown('fast').show(); //Drop down the subnav on click

            $(this).hover(function() {
            }, function(){
                    $(this).find('a:first').removeClass().addClass('sub-menu-class');
                    $(this).find("div.sub-menu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
            });

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("menuint"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("menuint"); //On hover out, remove class "subhover"
                });

         $('#rotator').cycle({
             fx: 'scrollVert',
             cleartype: !$.support.opacity,
             delay:  -1000,
             timeout: 5000,
             speed: 3000,
             pause: true,
             fastOnEvent: true,
             pagerEvent: 'mouseover',
             pager: "#pager",
             pagerAnchorBuilder: function(idx, slide){
                return '<a href="#"><span class="pager-seta"></span>' + slide.rel+'</a>';
             }
          });

          /*Atletas*/
          $(".atleta-info").hide();
	  $(".atleta-box a").click(function(){
	    $(".atleta-info:visible").slideUp("slow");
	    $(this).parent().parent().parent().find('.atleta-info').slideDown("slow");
            return false;
	  });
          /*$(".atleta-info").hide();
          $(".atleta-box a").click(function(e)
          {
            e.preventDefault();
           $(this).parent().parent().parent().find('.atleta-info').slideUp();
            return false;
          });*/

        $('input, textarea, select').bind({
            click: function() {
             validar($('#formContato'));
            },
            focus: function() {
              validar($('#formContato'));
            },
            keypress: function() {
              validar($('#formContato'));
            }
        });
});

//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) {
        //Envia Email
         var dpto = $('#dpto option:selected').val();
         var nome = $('#nome').val();
         var fone = $('#fone').val();
         var email = $('#email').val();
         var msg = $('#msg').val();

         var imgload = imgLoaddefault('p');
         var url = 'paginas/contato-enviar.php?dpto='+dpto+'&nome='+nome+'&fone='+fone+'&email='+email+'&msg='+msg;
        $.ajax({
                url: url,
                dataType: 'html',
                type: 'GET',
                timeout: 10000,
                beforeSend: function(){
                    $('#contato-retorno').fadeIn().empty().append(imgload);
                },
                complete: function() {
                    $('#contato-retorno').addClass('enviado').html(' Enviado com sucesso!');
                },
                success: function(data, textStatus) {
                     $(form).find('input[type="text"], textarea').each(function(){$(this).val('')});
                },
                error: function(xhr , er) {
                }
        });
        return false;

    }else return false;
}

