var map;

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    var result = true;
    $(mail).each(function(){
        if (!er.test($(this).val())){
            $(this).css('border', 'solid 1px #f00');
            $(this).stop()
                .animate({left: "-10px"}, 100).animate({left: "10px"}, 100)
                .animate({left: "-10px"}, 100).animate({left: "10px"}, 100)
                .animate({left: "0px"}, 100);
            result = false;
        }
    });
    return result;
}

function validar(){

    $("input[class=requerido], textarea[class=requerido]").css('border','solid 1px #000');
    var requiredFields = $("input[class=requerido][value=], textarea[class=requerido][value=]");
    if (requiredFields.size() > 0) {
        requiredFields.each(function() {
            $(this).css('border', 'solid 1px #f00');
            $(this).stop()
                .animate({left: "-10px"}, 100).animate({left: "10px"}, 100)
                .animate({left: "-10px"}, 100).animate({left: "10px"}, 100)
                .animate({left: "0px"}, 100);
        });
        return false;
    }else{
        return true;
    }

}

$(function(){
    $('#menu ul li a, .menu-rodape li a').hover(function(){
         Cufon.set('color', '#00ff00');
         Cufon.replace(this,{color: '-linear-gradient(#00ff00, #246703)',
	fontFamily: 'Kabel Md BT',
	textShadow: '1px 1px rgba(0, 0, 0, 0.1)'});
    },function(){
         Cufon.set('color', '#ffffff');
         Cufon.replace(this);
    })

    Cufon.replace('#menu ul li a, .menu-rodape li a');
    Cufon.replace('h2, h3', {
	color: '-linear-gradient(#00ff00, #246703)',
	fontFamily: 'Kabel Md BT',
	textShadow: '1px 1px rgba(0, 0, 0, 0.1)'
        
   });

   $('.lista-home li').hover(function() {
        $(this).find(".pb").stop().fadeTo(300,0);
        $(this).find(".caption").animate({"top": "110px"}, "slow");
        }, function() {
        $(this).find(".pb").fadeTo(300,1);
        $(this).find(".caption").animate({"top": "152px"}, "slow");
    });

    $('.lista-portfolio li ul').hide();

    $('.lista-portfolio li h2').click(function(){
        $(this).next().toggle("slow");
    });

    $('.lista-portfolio li ul li').hover(function(){
        $(this).animate({backgroundPosition: '0 0'},800);
    },function(){
        $(this).animate({backgroundPosition: '0 -205px'},800);
    });

    $('.lista-clientes li').hover(function(){
        $(this).animate({backgroundPosition: '0 0'},800);
    },function(){
        $(this).animate({backgroundPosition: '0 -205px'},800);
    });

    $(".teste").colorbox({width:"940", height:"617", iframe:true});
    $(".picture").colorbox();
    $(".form").submit(function() {
        if (validar() && checkMail("input[title=email]")){
            $.ajax({
                type: "POST",
                url: $('.form').attr('action'),
                data: $('.form').serialize(),
                beforeSend: function(request){
                    $('.form').html('<center><img src="/images/ajax-loader.gif" /></center>');
                },
                success: function(request){
                    $('.form').html('<center><strong>' + request + '</strong></center>');
                }
            });
        }
        return false;
    });

    $(".form_noajax").submit(function() {
        return (validar() && checkMail("input[title=email]"));
    });


    $(".comment-list ul li:odd").css('background','#e7e7e7');
    $(".comment-list ul li:last").css('border-bottom','solid 1px #AAAAAA');
    $(".abrir-regra").colorbox({width:"50%", inline:true, href:".comment-info-hide"});


})

function initialize(lat, longi) {
    if($('#google-maps').length){
        var latlng = new google.maps.LatLng(lat, longi);
        var myOptions = {
            zoom: 15,
            center: latlng,
            navigationControl: false,
            scaleControl: false,
            mapTypeControl: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("google-maps"), myOptions);
        var marker = new google.maps.Marker({
              position: latlng,
              title:"Posição da empresa"
        });
        marker.setMap(map);
    }
}
