$(document).ready(function () {
    menuTopo();
    focusBlur();

    $(".modalAcompanheObra ").height($(document).height());
    $(".modalAcompanheObra .boxSelectObra select").sSelect({ ddMaxHeight: '200px' });

    $(".topo .menuTopo .btAcompanheSuaObra, .rodape .menu .btAcompanheSuaObra").click(function () {
        if ($.browser.msie) {
            $(".modalAcompanheObra").show();
        } else {
            $(".modalAcompanheObra").fadeIn("fast");
        }
    });

    $(".modalAcompanheObra .conteudoModal .btFechar").click(function () {
        if ($.browser.msie) {
            $(this).parent().parent().hide();
        } else {
            $(this).parent().parent().fadeOut("fast");
        }
    });

    $(".modalAcompanheObra .conteudoModal .btFechar").hover(function () {
        animaFechar($(this), 8, 0);
        $(this).find(".bg").animate({
            marginLeft: 0,
            marginTop: 0
        }, 200);
        $(this).find(".bg img").animate({
            height: 26,
            width: 26
        }, 200);
    }, function () {
        animaFechar($(this), 8, 1);
        $(this).find(".bg").animate({
            marginLeft: 2,
            marginTop: 2
        }, 200);
        $(this).find(".bg img").animate({
            height: 22,
            width: 22
        }, 200);
    });

});

function menuTopo() {
    var tempoAnimacao = 300;
    $(".topo .centro .menu .btMenu").hover(function() {
        $(this).find(".tituloMenu").stop(true, true).animate({
            marginTop: 14 + "px"
        }, { duration: tempoAnimacao, easing: "easeOutQuad" });
        $(this).find(".detalhe").show();
        if ($.browser.msie) {
            $(this).find(".detalhe").show();
            $(this).find(".detalhe").stop(true, true).animate({
                top: 19 + "px"
            }, { duration: tempoAnimacao, easing: "easeOutQuad" });
        } else {
            $(this).find(".detalhe").stop(true, true).animate({
                top: 19 + "px",
                opacity: 1
            }, { duration: tempoAnimacao, easing: "easeOutQuad" });
        }
    }, function() {
        $(this).find(".tituloMenu").stop(true, true).animate({
            marginTop: 22 + "px"
        }, { duration: tempoAnimacao, easing: "easeOutQuad" });
        if ($.browser.msie) {            
            $(this).find(".detalhe").stop(true, true).animate({
                top: 0 + "px"
            }, { duration: tempoAnimacao, easing: "easeOutQuad", complete: function() {
                $(this).hide();
            }
            });
        } else {
            $(this).find(".detalhe").stop(true, true).animate({
                top: 0 + "px",
                opacity: 0
            }, { duration: tempoAnimacao, easing: "easeOutQuad", complete: function() {
                $(this).hide();
            }
            });
        }
        
    });

}

function animaFechar(objeto, tempo, acao) {
    if (acao == 0) {
        objeto.delay(tempo).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 17%");
        });
        objeto.delay(tempo * 2).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 33%");
        });
        objeto.delay(tempo * 3).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 50%");
        });
        objeto.delay(tempo * 4).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 67%");
        });
        objeto.delay(tempo * 5).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 83%");
        });
        objeto.delay(tempo * 6).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 100%");
        });
    } else {
        objeto.delay(tempo * 1).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 83%");
        });
        objeto.delay(tempo * 2).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 67%");
        });
        objeto.delay(tempo * 3).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 50%");
        });
        objeto.delay(tempo * 4).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 33%");
        });
        objeto.delay(tempo * 5).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 17%");
        });
        objeto.delay(tempo * 6).fadeIn(0, function () {
            objeto.find(".icone").css("background-position", "0 0%");
        });
    }
}

function focusBlur() {
    $(".boxInput").click(function () {
        $(this).find(".inputForm").focus();
    });
    $('.boxInput .inputForm').keypress(function () {
        $(this).parent().find(".txtBlur").hide("fast");
    });
    $(".boxInput .inputForm").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).parent().find(".txtBlur").show("fast");
        }
    });

    $(".boxTextarea").click(function () {
        $(this).find(".inputForm").focus();
    });
    $('.boxTextarea textarea').keypress(function () {
        $(this).parent().find(".txtBlur").hide("fast");
    });
    $(".boxTextarea textarea").blur(function () {
        if ($(this).attr("value") == "") {
            $(this).parent().find(".txtBlur").show("fast");
        }
    });
}

function goObra(empId) {

    if (empId != "") {
        //window.location.href = 'acompanhe-sua-obra.asp?empId=' + empId;
        window.location.href = empId;
    }

}

function goObraAut() {

    var empId = $("#empId").val();
    goObra(empId);

}

//google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25173894-2']);
_gaq.push(['_trackPageview']);
(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
