var SITE = $('meta[name=root]').attr("content");

function get_url() {
    return SITE;
}

function $$(id) 
{ 
    try {       
        var elementId = document.getElementById(id);
        
    } catch(e) { 
        alert("Error: " + e);       
    } 
    return  elementId;
}

function addFlash (file, width, height, id, wmode, version) 
{
    var flashvars = {};
    var params = {'wmode':wmode};
    var attributes = {'id':id}; 
    swfobject.embedSWF(file, id, width, height, version,"js/expressInstall.swf", flashvars, params, attributes)
}

function changeValue (event, obj) {        
    eventValue = event.type;    
    if(!$$(obj).save){$$(obj).save = $$(obj).value;}    
    if(eventValue == "blur"){if($$(obj).value==""){$$(obj).value = $$(obj).save;}}
    else if(eventValue == "focus"){
        if($$(obj).value == ""){$$(obj).value = $$(obj).save;}
        else if($$(obj).value == $$(obj).save){$$(obj).value = "";}}
}

 
    
    $(document).ready(function(){
        
        $('#my-gallery').horizontalmove({ease:'easeInOutExpo'});
        $('#my-gallery2').horizontalmove({ease:'easeInOutExpo'});
        $('#my-gallery3').horizontalmove({
            ease:'easeInOutExpo',
            mask:'.horizontalmove-mask2:first',
            item:'.horizontalmove-item2',
            left:'.horizontalmove-left2',
            right:'.horizontalmove-right2'
        });
        $('#my-gallery4').horizontalmove({
            ease:'easeInOutExpo',
            mask:'.horizontalmove-mask3:first',
            item:'.horizontalmove-item3',
            left:'.horizontalmove-left3',
            right:'.horizontalmove-right3'
        });
        
        $('#my-gallery5').horizontalmove({
            ease:'easeInOutExpo',
            mask:'.horizontalmove-mask4:first',
            item:'.horizontalmove-item4',
            left:'.horizontalmove-left3',
            right:'.horizontalmove-right3'
        });
        
        var menu = function(id){
            $(id + " a").hover(
                function()
                {
                    $(this).stop().animate({ top: -50 }, 300);
                },      
                function()
                {
                    $(this).stop().animate({ top: 0 }, 400);
                }
            );
        }
        
        contato();
        
        
        
        $(".horizontalmove-item4 a").click(
           function()
           {
               var foto = $(this).attr('href');
               $("#prod-imagem div").attr('style', "background: url('" + foto + "') no-repeat; width:450px; height:215px; position: relative;");
               return false;
           }
        );
        
        gmaps();
    
});
    
    function gmaps()
    {
        var latlng = new google.maps.LatLng(-30.011329,-51.205551);

        var mapDiv = document.getElementById('gmaps');
        
        var map = new google.maps.Map(mapDiv, {
            center: latlng,
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            disableDefaultUI: true,
            navigationControl: true,
            navigationControlOptions: {
                position: google.maps.ControlPosition.LEFT,
                style: google.maps.NavigationControlStyle.SMALL
            }
        });

        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            icon:SITE + "/site/images/logo_mapa.png",
            title: "Cotemac"

        });
        
        var infoWindow = new google.maps.InfoWindow({
            position: latlng,
            size: new google.maps.Size(20,30),
            content: '<div style=" width:300px; height:40px; color:#999; line-height:13px; "><img src="' + SITE + '/site/images/logo_mapa.png" align="left"  style="border-right:5px #FFFFFF solid;" />Avenida São Paulo, 985 - CEP: 90230-160 - Bairro São Geraldo - Porto Alegre/RS</div>'
        });
        
        google.maps.event.addListener(marker, 'click', function(e) {
            infoWindow.open(map, marker);
        });        
    }
       
    
    function contato(){
        
        var options = 
        {   
            beforeSubmit:  showRequest,  
            success:       showResponse 
        }; 
        
        function showRequest(formData, jqForm, options) 
        { 
            $("#error").show();
            
            $("#error").html("<li><em>Enviando mensagem</em></li>");
        } 
         
        function showResponse(data)  
        {       
            $("#error").show();
            
            if($.trim(data) == "true")
            {   
                $("#error").html("<li><span>Mensagem enviada com sucesso</span></li>");
                $('#form-contato').clearForm();
            }else{
                $("#error").html("<li><span>Erro ao enviar contato</span></li>");
            }
        }   
        
        $("#form-contato").validate(
        {
            submitHandler: function(form) {
                $('#form-contato').ajaxSubmit(options);
            },
            rules: {
                'nome': { required:true },
                'email': { required:true, email:true },
                'telefone': { required:true },
                'assunto': { required:true },
                'mensagem': { required:true }    
            },
            messages: {
                nome:{required:"<li><span>Campo Nome Obrigatório.</span></li>"},
                email:{required:"<li><span>Campo E-mail Obrigatório.</span></li>",email:"<li><span>E-mail inválido</span></li>"},
                telefone:{required:"<li><span>Campo Telefone Obrigatório.</span></li>"},
                assunto:{required:"<li><span>Campo Assunto Obrigatório.</span></li>"},
                mensagem: { required:"<li><span>Campo Mensagem Obrigatório.</span></li>" }
            },
            
            invalidHandler:function(error, element) {
            },
            
            errorLabelContainer: $("#error")
        });       
    }
    
