﻿function ucMapaInterativo() {
    this.setTimeOpenBoxInfo;
    this.pageMapaInterativo;
    this.DateHourNow = new Number();
    
    //Inicializa o Objeto ucMapaInterativo
    //pTypeInfo[Tipo de informacao selecionada]
    this.Initialize = function(pTypeInfo, pDateHourNow) {
        ucMapaInterativo.pageMapaInterativo = pTypeInfo;
        ucMapaInterativo.DateHourNow = pDateHourNow;
        var sTypeInfo = (pTypeInfo == undefined || pTypeInfo == "") ? "trafego" : pTypeInfo;

        $(document).ready(function() {
            ucMapaInterativo.ChangeNavigation(sTypeInfo);
            ucMapaInterativo.Ajax("/Xml/Operacao.xml", null, ucMapaInterativo.LoadOperationInfo);
            $("#ContentPage .box-mapa-interativo ul.navigation li a").click(function() { ucMapaInterativo.ChangeNavigation($(this).parent("li").attr("class")); });
        });
    }

    //Carrega XML e transforma em Objeto
    //pUrl[Url do Xml]
    //pParams[Parametros enviados] 
    //pFunction[Funcao que é chamada após ter realizado a operacao o com sucesso]
    this.Ajax = function(pUrl, pParams, pFunction, pParamsFunc) {
        Main.LoadAjax(".box-mapa-interativo");
        $.ajax({
            url: pUrl,
            data: pParams,
            dataType: "xml",
            error: function(error) {
                //throw (error)
                //alert(error);
                Main.LoadAjaxClear();
            },
            success: function(content) {
                if (pFunction != null && pFunction != undefined)
                    pFunction(content, pParamsFunc);
                Main.LoadAjaxClear();
            }
        });
    }

    //Altera os tipos de informacoes do mapa
    //pType[trafego - cameras - operacao - clima - pedagios - pm-servicos - balancas]
    this.ChangeNavigation = function(pType) {
        try {
            $("#ContentPage .box-mapa-interativo ul.navigation li a").css("background-position", "0 0");
            $("#ContentPage .box-mapa-interativo .content-mapa-interativo  > *").remove();
            switch (pType) {
                case "trafego":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.trafego a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Fluxos.xml", null, ucMapaInterativo.LoadTraffic);
                    break;
                case "cameras":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.cameras a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Cameras.ashx", null, ucMapaInterativo.LoadCamera);
                    break;
                case "clima":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.clima a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Operacao.xml", null, ucMapaInterativo.LoadWeather);
                    break;
                case "pedagios":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.pedagios a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Pedagios.xml", null, ucMapaInterativo.LoadToll);
                    break;
                case "pm-sau": //Pm e Sau
                    $("#ContentPage .box-mapa-interativo ul.navigation li.pm-sau a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/PM-Sau.xml", null, ucMapaInterativo.LoadServices);
                    break;
                case "postos-servicos": // Postos e serviços
                    $("#ContentPage .box-mapa-interativo ul.navigation li.postos-servicos a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Postos-Servicos.xml", null, ucMapaInterativo.LoadServices);
                    break;
                case "balancas":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.balancas a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Balancas.xml", null, ucMapaInterativo.LoadScales);
                    break;                    
            }

            //Navegacao Box de Informacoes
            $("#ContentPage .box-info-map .content").hide();
            $("#ContentPage .box-info-map .title").removeClass("title-active");
            $("#ContentPage .info-" + pType + " .content").show();
            $("#ContentPage .info-" + pType + " .title").addClass("title-active");
            $(document).pngFix();
        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna Posicao conforme Km
    //pKm[0 a 80]
    this.GetPositionByKm = function(pKm, pWidthImg) {
        try {
            var positionLeft = new Number();
            var divisionKm = new Number(113);
            var imgPosition = parseInt(parseInt(pWidthImg) / 2);
            
            positionLeft = ((pKm * 113) / 10) - imgPosition;
            return positionLeft.toString() + "px";
        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna Posicao do topo
    //pTop[0 a 322]
    this.GetPositionByTop = function(pTop, pWidthImg) {
        try {
            var positionTop = new Number();
            var imgPosition = parseInt(parseInt(pWidthImg) / 2);

            positionTop = parseInt(pTop - imgPosition);
            return positionTop.toString() + "px";
        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna a posicao por
    //pRoad[Rodovia + Sentido]
    this.GetPositionByRoad = function(pRoad, pHeightImg) {
        try {

            var positionTop = Number();
            var imgPosition = parseInt(parseInt(pHeightImg) / 2);

            switch (pRoad) {
                case "BR 116-SUL":
                    positionTop = 157;
                    break;
                case "BR 392-SUL":
                    positionTop = 248;
                    break;
                default:
                    positionTop = -9000;
                    break;
            }

            positionTop = (positionTop - imgPosition);
            return positionTop.toString() + "px";
        }
        catch (e) {
            alert(e);
        }
    }    

    //Cria box com informacoes do icone selecionado
    // pType[Trafego - ]
    this.CreateBoxInfo = function(pType) {
        try {

            $(document.createElement("div")).addClass("box-info-item").appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                .hover(function() {
                    clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                },
                function() {
                    ucMapaInterativo.CloseBoxInfo();
                });

            $(document.createElement("div")).addClass("info").appendTo("#ContentPage .box-mapa-interativo .box-info-item");

            if (pType == "Trafego") {
               
                $(document.createElement("strong")).attr({ id: "MapInfoCarRoadWay" }).addClass("title").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).text("Trecho: ").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("strong")).attr({ id: "MapInfoCarZone" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).text("Veículos / hora: ").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("strong")).attr({ id: "MapInfoCarTime" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).text("Condição: ").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("strong")).attr({ id: "MapInfoCarCondition" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "/Mapa-Interativo/Trafego-Tempo-Viagem#idBoxInfo_Trafego", title: "+ detalhes" }).text("+ detalhes").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
            }
            else if (pType == "Cameras") {
                $(document.createElement("strong")).attr({ id: "MapInfoCamRoad" }).addClass("title").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).attr({ id: "MapInfoCamIfo" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "javascript:void(0)", rel: "CameraLiveMap", id: "MapInfoCamLnkImg", alt: "", title: "" }).addClass("lnkFoto").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("img")).attr({ src: "", id: "MapInfoCamImg", width: "130", height: "89", onError: "this.src='/Themes/" + Main.Theme + "/Img/MapaInterativo/nao-disponivel-camera.jpg';  $(this).parents('a').attr('href', '/Themes/" + Main.Theme + "/Img/MapaInterativo/nao-disponivel-camera-gd.gif')" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info .lnkFoto");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "/Mapa-Interativo/Cameras#idBoxInfo_Cameras", title: "+ detalhes" }).text("+ detalhes").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
            }
            else if (pType == "Clima") {
                $(document.createElement("strong")).attr({ id: "MapInfoWeatherTitle" }).addClass("title").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).attr({ id: "MapInfoWeatherIfo" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "Mapa-Interativo/Clima#idBoxInfo_Clima", title: "+ detalhes" }).text("+ detalhes").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
            }
            else if (pType == "Pedagios") {
                $(document.createElement("strong")).attr({ id: "MapInfoTollTitle" }).addClass("title").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).attr({ id: "MapInfoTollInfo" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "/Mapa-Interativo/Pedagios#idBoxInfo_Pedagios", title: "+ detalhes" }).text("+ detalhes").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
            }
            else if (pType == "Servicos") {
                $(document.createElement("span")).attr({ id: "MapInfoServiceInfo" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).attr({ id: "MapInfoServiceKm" }).addClass("featured").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "/Mapa-Interativo/PM-Servicos#idBoxInfo_Servicos", title: "+ detalhes" }).text("+ detalhes").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("div")).attr({ id: "MapInfoServiceIcons" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
            }
            else if (pType == "Balancas") {
                $(document.createElement("span")).attr({ id: "MapInfoScalesInfo" }).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("span")).attr({ id: "MapInfoScalesKm" }).addClass("featured").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("br")).appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
                $(document.createElement("a")).attr({ href: "/Mapa-Interativo/Balancas#idBoxInfo_Balancas", title: "+ detalhes" }).text("+ detalhes").appendTo("#ContentPage .box-mapa-interativo .box-info-item .info");
            }

            $(document.createElement("img")).attr({ src: "/Themes/" + Main.Theme + "/Img/ucMapaInterativo/box-info-tip.png", alt: " " }).addClass("tip").appendTo("#ContentPage .box-mapa-interativo .box-info-item");
        }
        catch (e) {
            alert(e);
        }
    }

    //Fecha Box de informacoes
    this.CloseBoxInfo = function() {
        try {
            $("#ContentPage .box-mapa-interativo .box-info-item").hide();
            clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
        }
        catch (e) {
            alert(e);
        }

    }

    /**********************
    TRAFEGO
    **********************/

    //Carrega Informacoes de Trafego
    //pContent[Objeto Xml]
    this.LoadTraffic = function(pContent) {
        try {
            var Type = new String("Trafego");
            var arrRunway = new Array();
            arrRunway = Main.TransformStringArray($(pContent).find("operacao").attr("pistas"), "");

            $(pContent).find("rodovias rodovia").each(function(i, e) {



                 
                //var positionTop = ucMapaInterativo.GetTrafficPositionByRoad($(e).attr("nome") + "-" + $(e).attr("sentido"));
                //var positionLeft = ucMapaInterativo.GetTrafficPositionByZone($(e).attr("regiao"), $(e).attr("sentido"), $(e).attr("nome"));

            var positionTop = ucMapaInterativo.GetTrafficPositionByRoadAndZone($(e).attr("regiao"), $(e).attr("nome") + "-" + $(e).attr("sentido"), "top");
            var positionLeft = ucMapaInterativo.GetTrafficPositionByRoadAndZone($(e).attr("regiao"), $(e).attr("nome") + "-" + $(e).attr("sentido"), "left");
            
                //Cria instrucoes Css e posicionamento
                var cssObjImg = {
                    'position': "absolute",
                    'top': positionTop,
                    'left': positionLeft,
                    'cursor': "pointer",
                    'zIndex': "10"
                }
                //Cria elemento Img
                $(document.createElement("img"))
                    .attr({ src: ucMapaInterativo.GetTrafficImageName(arrRunway, e), id: Type + "_" + i, alt: " " })
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .addClass("item-mapa")
                    .hover(function() {
                        ucMapaInterativo.OpenTrafficInfo(e, cssObjImg, pContent);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });

                //Cria instrucoes Css e posicionamento do numero
                var cssObjNum = {

                    'position': "absolute",
                    'top': (parseInt(positionTop)) + "px",
                    'left': (parseInt(positionLeft)) + "px",
                    'width': "43px",
                    'textAlign': "center",
                    'fontSize': "11px",
                    'fontWeight': "bold",
                    'color': "#fff",
                    'cursor': "pointer",
                    'zIndex': "20"
                }

                if (ucMapaInterativo.pageMapaInterativo != undefined) {
                    //Cria elemento span com o numero
                    $(document.createElement("span"))
                    .css(cssObjNum)
                    .text(i + 1)
                    .addClass("item-mapa")
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.OpenTrafficInfo(e, cssObjImg, pContent);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });
                }

            });

            ucMapaInterativo.CreateBoxInfo(Type);

            ucMapaInterativo.SetBoxInfoVehiclesPerHour(pContent);
        }
        catch (e) {
            alert(e);
        }
    }

    //Retorna a posicao do carro por:
    //pZone[PLANALTO - SERRA - BAIXADA]
    //pWay[Sul - Norte - Leste - Oeste]
    //pRoad[ANCHIETA - IMIGRANTES - CÔNEGO DOMÊNICO RANGONI - PADRE MANOEL DA NOBREGA]
    this.GetTrafficPositionByRoadAndZone = function(pZone, pRoad, requiredPosition) {
        try {
        

            var positionLeft = Number();
            var positionTop = Number();

            positionLeft = 0;
            positionTop = 0;

            if (pZone == "CAMAQUA - PELOTAS" && pRoad == "BR 116-Jaguarao") {
                positionTop = 110;
                positionLeft = 600;
            }

            if (pZone == "CAMAQUA - PELOTAS" && pRoad == "BR 116-Camaqua") {
                

                positionTop = 140;
                positionLeft = 580;
            }

            if (pZone == "PELOTAS - JAGUARAO" && pRoad == "BR 116-Jaguarao") {
                positionTop = 220;
                positionLeft = 350;

                //positionTop = 180;
                //positionLeft = 425;
            }

            if (pZone == "PELOTAS - JAGUARAO" && pRoad == "BR 116-Camaqua") {
                
                //positionTop = 230;
                //positionLeft = 380;

                positionTop = 210;
                positionLeft = 425;
            }

            if (pZone == "RIO GRANDE - PELOTAS" && pRoad == "BR 392-Rio Grande") {
               // positionTop = 250;
               // positionLeft = 500;

                positionTop = 250;
                positionLeft = 600;
            }

            if (pZone == "RIO GRANDE - PELOTAS" && pRoad == "BR 392-Santana") {
               // positionTop = 220;
               // positionLeft = 480;

                positionTop = 220;
                positionLeft = 580;
            }

            if (pZone == "PELOTAS - BAGE" && pRoad == "BR 293-Pelotas") {
                //positionTop = 140;
                //positionLeft = 350;

                positionTop = 180;
                positionLeft = 300;
            }

            if (pZone == "PELOTAS - BAGE" && pRoad == "BR 293-Bage") {
                //positionTop = 120;
                //positionLeft = 300;

                positionTop = 160;
                positionLeft = 250;
            }

            if (pZone == "PELOTAS - SANTANA" && pRoad == "BR 392-Rio Grande") {
                //positionTop = 90;
                //positionLeft = 420;

                positionTop = 90;
                positionLeft = 320;
            }

            if (pZone == "PELOTAS - SANTANA" && pRoad == "BR 392-Santana") {
                //positionTop = 55;
                //positionLeft = 400;

                positionTop = 55;
                positionLeft = 300;
            }

            if (positionTop == 0 || positionTop == 0) {
                alert(pZone + " " + pRoad);
            }

            if (requiredPosition == "left") {
                return positionLeft.toString() + "px";
            } else if (requiredPosition == "top") {
                return positionTop.toString() + "px";
            } else {
                return "0px";
            }
        }
        catch (e) {
            alert(e);
        }
    }
    
    
    //Retorna o sentido e cor da imagem por
    //pWay[Sul - Norte - Leste - Oeste]
    //pCondition[Bom, Normal, Lento]
    this.GetTrafficImageName = function(pArrRunway, e) {
        try {
            var pathImage = new String("/Themes/" + Main.Theme + "/Img/ucMapaInterativo/");
            var nameImage = new String();
            var conditionType = new String();
            var wayType = (($(e).attr("sentido") == "Camaqua") || ($(e).attr("sentido") == "Rio Grande")|| ($(e).attr("sentido") == "Pelotas")) ? "d" : "u";

            if (($(e).attr("regiao") == "SERRA"))
                wayType = ucMapaInterativo.GetCarWay(pArrRunway, $(e).attr("nome") + "-" + $(e).attr("sentido"));

            switch ($(e).attr("condicao")) {
                case "Bom":
                    conditionType = "good";
                    break;
                case "Normal":
                    conditionType = "good";
                    break;
                case "Baixo":
                    conditionType = "good";
                    break;
                case "Parcial":
                    conditionType = "normal";
                    break;
                case "Lento":
                    conditionType = "slow";
                    break;
                case "Interditado":
                    conditionType = "slow";
                    break;
                case "Congestionado":
                    conditionType = "slow";
                    break;
                case "Intenso":
                    conditionType = "slow";
                    break;
                default:
                    conditionType = "slow";
                    break;
            }
            nameImage = "ico-car-" + conditionType + "-" + wayType + ".png";

            return pathImage + nameImage;
        }
        catch (e) {
            alert(e);
        }
    }

    //Pega posicao do carro
    this.GetCarWay = function(pArrRunway, pRoadWay) {
        try {
            var wayType = new String();

            switch (pRoadWay) {
                case "IMIGRANTES-Sul":
                    wayType = pArrRunway[0];
                    break;
                case "IMIGRANTES-Norte":
                    wayType = pArrRunway[3];
                    break;
                case "ANCHIETA-Sul":
                    wayType = pArrRunway[6];
                    break;
                case "ANCHIETA-Norte":
                    wayType = pArrRunway[8];
                    break;
            }
            return (wayType == "D") ? "d" : "u";
        }
        catch (e) {
            alert(e);   
        }
    }

    //Abre modal com informacoes do trafego
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenTrafficInfo = function(pObj, pCssObj, pContent) {
        try {
            var sentido = $(pObj).attr("sentido");

            switch (sentido.toUpperCase()) {
                case "SANTANA":
                    sentido = "SANTANA DA BOA VISTA";
                    break;
                case "BAGE":
                    sentido = "BAGÉ";
                    break;
                case "JAGUARAO":
                    sentido = "JAGUARÃO";
                    break;
                case "CAMAQUA":
                    sentido = "CAMAQUÃ";
                    break;
            }

            $("#MapInfoCarRoadWay").text("" + sentido);
            $("#MapInfoCarZone").text($(pObj).attr("nome"));
            $("#MapInfoCarTime").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, $(pObj).attr("nome"), $(pObj).attr("sentido")));
            $("#MapInfoCarCondition").text($(pObj).attr("condicao"));

            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            alert(e);
        }
    }

    //Pega no Xml informacoes de quantidade de veiculos por hora
    this.GetInfoVehiclesPerHour = function(pContent, pRoad, pWay) {
        try {
            return $(pContent).find("rodovias_fluxo rodovia[nome*='" + pRoad.toString() + "'] fluxos fluxo[sentido*='" + pWay.toString() + "']").attr("valor");
        }
        catch (e) {
            alert(e);
        }
    }

    // Seta informacao no box de quantidade de veiculos por hora
    this.SetBoxInfoVehiclesPerHour = function(pContent) {
        try {
            $(".box-veiculos-hora .road-br277-smigueldoiguacu .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Sao Miguel do Iguacu", "Leste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-smigueldoiguacu .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Sao Miguel do Iguacu", "Oeste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-ceuazul .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Ceu Azul", "Leste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-ceuazul .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Ceu Azul", "Oeste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-cascavel .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Cascavel", "Leste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-cascavel .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Cascavel", "Oeste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-laranjeirasdosul .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Laranjeiras do Sul", "Leste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-laranjeirasdosul .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Laranjeiras do Sul", "Oeste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-candoi .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Candoi", "Leste") + " veículos / hora");
            $(".box-veiculos-hora .road-br277-candoi .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "Candoi", "Oeste") + " veículos / hora");
        }
        catch (e) {
            alert(e);
        }
    }
    
    /**********************
    CAMERAS
    **********************/

    //Carrega Informacoes das Cameras
    //pContent[Objeto Xml]
    this.LoadCamera = function(pContent) {
        try {
            var Type = new String("Cameras");
            $(pContent).find("camera").each(function(i, e) {
                var positionTop = ucMapaInterativo.GetPositionByTop($(e).attr("positionTop"), "25px");
                var positionLeft = ucMapaInterativo.GetPositionByKm($(e).attr("km"), "50px");

               

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjImg = {
                    'position': "absolute",
                    'top': positionTop,
                    'left': positionLeft,
                    'cursor': "pointer",
                    'zIndex': "10"
                }

                //Cria elemento Img
                $(document.createElement("img"))
                    .attr({ src: ucMapaInterativo.GetCameraImageName(), id: Type + "_" + i, alt: " " })
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.OpenCameraInfo(e, cssObjImg);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });

                //Cria instrucoes Css e posicionamento do numero
                var cssObjNum = {

                    'position': "absolute",
                    'top': (parseInt(positionTop) + 5) + "px",
                    'left': (parseInt(positionLeft) + 15) + "px",
                    'fontSize': "12px",
                    'fontWeight': "bold",
                    'color': "#fff",
                    'cursor': "pointer",
                    'zIndex': "20"
                }
                //Cria elemento span com o numero
                if (ucMapaInterativo.pageMapaInterativo != undefined) {
                    $(document.createElement("span"))
                    .css(cssObjNum)
                    .text(i + 1)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.OpenCameraInfo(e, cssObjImg);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });
                }
            });
            ucMapaInterativo.CreateBoxInfo(Type);
        }
        catch (e) {
            alert(e);
        }
    }
    
    //Retorna a posicao da camera por:
    //pRoad[ANCHIETA - IMIGRANTES - CÔNEGO DOMÊNICO RANGONI - PADRE MANOEL DA NOBREGA]
    this.GetCameraPositionByRoad = function(pRoad) {
        try {

            var positionTop = Number();

            switch (pRoad) {
                case "Rod. Carvalho Pinto":
                    positionTop = 135;
                    break;
                default:
                    positionTop = -9000;
                    break;
            }
           
            return positionTop.toString() + "px";
        }
        catch (e) {
            alert(e);
        }
    }
    
    //Retorna caminho da image camera:
    this.GetCameraImageName = function() {
        try {
            return new String("/Themes/" + Main.Theme + "/Img/ucMapaInterativo/camera.png");
        }
        catch (e) {
            alert(e);
        }
    }

    //Abre modal com informacoes do trafego
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenCameraInfo = function(pObj, pCssObj) {
        try {
            $("#MapInfoCamImg").attr("src", "/Content/Cameras/" + $(pObj).attr("img"));

            $("#MapInfoCamRoad").text($(pObj).attr("rodovia"));
            $("#MapInfoCamLnkImg").attr("href", "/Content/Cameras/" + $(pObj).attr("img")).attr("alt", $(pObj).attr("trecho")).attr("title", $(pObj).attr("trecho"));

            $("#MapInfoCamImg").attr("src", "/Content/Cameras/" + $(pObj).attr("img"));
            $("#MapInfoCamIfo").text($(pObj).attr("trecho") + " / Km " + $(pObj).attr("kmExibe"));

            $("a[rel='CameraLiveMap']").colorbox();
            
            
            
            var cameraInfoTop = parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7;
            

            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': cameraInfoTop,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            alert(e);
        }
    }


    /**********************
    CLIMA
    **********************/

    //Carrega Informacoes do Clima
    //pContent[Objeto Xml]
    this.LoadWeather = function(pContent) {
        
        try {
            var Type = new String("Clima");
            $(pContent).find("tempo").each(function(i, e) {

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjImg = {
                    'position': "absolute",
                    'top': ucMapaInterativo.GetWeatherPositionByTop($(e).attr("local")),
                    'left': ucMapaInterativo.GetWeatherPositionByZone($(e).attr("local")),
                    'cursor': "pointer",
                    'zIndex': "10"
                }

                var objWeather = ucMapaInterativo.GetWeatherObj($(e).attr("condicao"), $(e).attr("local"));

                //Cria elemento Img
                $(document.createElement("img"))
                    .attr({ src: objWeather.ImagePath + objWeather.ImageName, id: Type + "_" + i, alt: " " })
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.OpenWeatherInfo(objWeather, cssObjImg);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });
            });
            ucMapaInterativo.CreateBoxInfo(Type);
        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Retorna Objeto de Clima
    //pId[1 a 6]
    //pId[]
    this.GetWeatherObj = function(pId, pZone) {
        try {
            var obj = new Object();
            obj.ImagePath = new String("/Themes/" + Main.Theme + "/Img/WidgetPrevisaoTempo/")
            obj.ImageName = new String();
            obj.Legend = new String();
            obj.Zone = new String();
            
            switch (parseInt(pId)) {
                case 1:
                    obj.Legend = "Bom";
                    obj.Zone = pZone;
                    obj.ImageName = (ucMapaInterativo.DateHourNow <= 5 || ucMapaInterativo.DateHourNow >= 19) ? "ico-weather-2n.png" : "ico-weather-2.png";
                    break;
                case 2:
                    obj.Legend = "Com Chuva";
                    obj.Zone = pZone;
                    obj.ImageName = (ucMapaInterativo.DateHourNow <= 5 || ucMapaInterativo.DateHourNow >= 19) ? "ico-weather-5n.png" : "ico-weather-5.png";
                    break;
                case 3:
                    obj.Legend = "Com Garoa";
                    obj.Zone = pZone;
                    obj.ImageName = (ucMapaInterativo.DateHourNow <= 5 || ucMapaInterativo.DateHourNow >= 19) ? "ico-weather-4rn.png" : "ico-weather-4r.png";
                    break;
                case 4:
                    obj.Legend = "Com Neblina";
                    obj.Zone = pZone;
                    obj.ImageName = (ucMapaInterativo.DateHourNow <= 5 || ucMapaInterativo.DateHourNow >= 19) ? "ico-weather-9.png" : "ico-weather-9.png";
                    break;
                case 5:
                    obj.Legend = "Com Sol";
                    obj.Zone = pZone;
                    obj.ImageName = (ucMapaInterativo.DateHourNow <= 5 || ucMapaInterativo.DateHourNow >= 19) ? "ico-weather-1n.png" : "ico-weather-1.png";
                    break;
                case 6:
                    obj.Legend = "Encoberto";
                    obj.Zone = pZone;
                    obj.ImageName = (ucMapaInterativo.DateHourNow <= 5 || ucMapaInterativo.DateHourNow >= 19) ? "ico-weather-3n.png" : "ico-weather-3.png";
                    break;
            }

            return obj;

        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Retorna Posicao da imagem
    //pId[]
    this.GetWeatherPositionByZone = function(pZone) {
        try {
            var positionLeft = new String();
            switch (pZone.toString()) {

                case "Camaqua - Pelotas":
                    positionLeft = "640px"; // this.GetPositionByKm("80", "40");
                    break;
                case "Pelotas - Jaguarao":
                    positionLeft = "350px"; //this.GetPositionByKm("72", "40");
                    break;
                case "Rio Grande - Pelotas":
                    positionLeft = "580px"; //this.GetPositionByKm("67", "40");
                    break;
                case "Pelotas - Santana":
                    positionLeft = "360px"; //this.GetPositionByKm("64", "40");
                    break;
                case "Urbano - Pelotas":
                    positionLeft = "-9000px"; //this.GetPositionByKm("60", "40");
                    break;
                case "Pelotas - Bage":
                    positionLeft = "240px"; //this.GetPositionByKm("54", "40");
                    break;
                default:
                    alert(pZone.toString());
                    break;
            }
            return positionLeft.toString();

        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna Posicao da imagem
    //pId[]
    this.GetWeatherPositionByTop = function(pZone) {
        try {
            var positionTop = new String();
            switch (pZone.toString()) {

                case "Camaqua - Pelotas":
                    positionTop = 85;
                    break;
                case "Pelotas - Jaguarao":
                    positionTop = 210;
                    break;
                case "Rio Grande - Pelotas":
                    positionTop = 210;
                    break;
                case "Pelotas - Santana":
                    positionTop = 85;
                    break;
                case "Urbano - Pelotas":
                    positionTop = -9000;
                    break;
                case "Pelotas - Bage":
                    positionTop = 160;
                    break;
                default:
                    alert(pZone);
                    break;
            }
            return positionTop.toString() + "px";

        }
        catch (e) {
            //alert(e);
        }
    }

    //Abre modal com informacoes do Clima
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenWeatherInfo = function(pObj, pCssObj) {
        try {
            var zone = "";
            switch (pObj.Zone) {
                case "Camaqua - Pelotas":
                    zone = "Camaquã - Pelotas";
                    break;
                case "Pelotas - Jaguarao":
                    zone = "Pelotas - Jaguarão";
                    break;
                case "Pelotas - Santana":
                    zone = "Pelotas - Santana da Boa Vista";
                    break;
                case "Pelotas - Bage":
                    zone = "Pelotas - Bagé";
                    break;
                default:
                    zone = pObj.Zone;

            }

            $("#MapInfoWeatherTitle").text(zone);
            $("#MapInfoWeatherIfo").text(pObj.Legend);

            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            //alert(e);
        }
    }

    /**********************
    PEDAGIO
    **********************/
    //Carrega Informacoes das Cameras
    //pContent[Objeto Xml]
    this.LoadToll = function(pContent) {
        try {
            var Type = new String("Pedagios");
            $(pContent).find("pedagio").each(function(i, e) {
            var positionTop = ucMapaInterativo.GetPositionByTop($(e).attr("positionTop"), "28px");
                var positionLeft = ucMapaInterativo.GetPositionByKm($(e).attr("km"), "27px");

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjImg = {
                    'position': "absolute",
                    'top': positionTop,
                    'left': positionLeft,
                    'cursor': "pointer",
                    'zIndex': "10"
                }

                //Cria elemento Img
                $(document.createElement("img"))
                    .attr({ src: ucMapaInterativo.GetTollImageName($(e).attr("status")), id: Type + "_" + i, alt: " " })
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.OpenTollInfo(e, cssObjImg);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });
            });
            ucMapaInterativo.CreateBoxInfo(Type);

            ucMapaInterativo.CreateTollMaskRoadLeft("235px", "345px", "12px");
            ucMapaInterativo.CreateTollMaskRoadLeft("248px", "350px", "12px");
            ucMapaInterativo.CreateTollMaskRoadLeft("87px", "675px", "12px");
            ucMapaInterativo.CreateTollMaskRoadLeft("98px", "681px", "12px");
            ucMapaInterativo.CreateTollMaskRoadLeft("150px", "535px", "12px");
            ucMapaInterativo.CreateTollMaskRoadLeft("161px", "541px", "12px");
            ucMapaInterativo.CreateTollMaskRoadRight("139px", "435px", "11px");
            ucMapaInterativo.CreateTollMaskRoadRight("150px", "428px", "11px");
            ucMapaInterativo.CreateTollMaskRoadRight("224px", "580px", "11px");
            ucMapaInterativo.CreateTollMaskRoadRight("235px", "573px", "11px");                 
        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna caminho da image do pedagio
    this.GetTollImageName = function(pStatus) {
        try {
            var ImagePath = new String("/Themes/" + Main.Theme + "/Img/ucMapaInterativo/");
            var ImageName = new String();
            ImageName = (pStatus == "ABERTO") ? "ico-toll-open.png" : "ico-toll-close.png";

            return ImagePath + ImageName;
        }
        catch (e) {
            //alert(e);
        }
    }

    //Abre modal com informacoes
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenTollInfo = function(pObj, pCssObj) {
        try {
            $("#MapInfoTollTitle").text($(pObj).attr("rodovia"));
            $("#MapInfoTollInfo").text($(pObj).attr("trecho"));

            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            //alert(e);
        }
    }

    //Cria mascara de pedagio
    this.CreateTollMaskRoad = function(pPositionTop, pPositionLeft, pHeight) {
        try {
            var cssObjImg = {
                'display': "block",
                'position': "absolute",
                'top': pPositionTop,
                'left': pPositionLeft,
                'width': "6px",
                'height': pHeight,
                'backgroundColor': "#484a4d",
                'zIndex': "10"
            }

            //Cria elemento Img
            $(document.createElement("span"))
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo");
        }
        catch (e) {
            //alert(e);
        }
    }

    //Cria mascara de pedagio inclinada para a esquerda
    this.CreateTollMaskRoadLeft = function(pPositionTop, pPositionLeft, pHeight) {
        try {
            var cssObjImg = {
                'display': "block",
                'position': "absolute",
                'top': pPositionTop,
                'left': pPositionLeft,
                'width': "15px",
                'height': pHeight,
                'background-image': "url('/Themes/Default/Img/ucMapaInterativo/ico-toll-marking-left.png')",
                'zIndex': "10"
            }

            //Cria elemento Img
            $(document.createElement("span"))
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo");
        }
        catch (e) {
            //alert(e);
        }
    }

    //Cria mascara de pedagio inclinada para a direita
    this.CreateTollMaskRoadRight = function(pPositionTop, pPositionLeft, pHeight) {
        try {
            var cssObjImg = {
                'display': "block",
                'position': "absolute",
                'top': pPositionTop,
                'left': pPositionLeft,
                'width': "23px",
                'height': pHeight,
                'background-image': "url('/Themes/Default/Img/ucMapaInterativo/ico-toll-marking-right.png')",
                'zIndex': "10"
            }

            //Cria elemento Img
            $(document.createElement("span"))
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo");
        }
        catch (e) {
            //alert(e);
        }
    }      

    /**********************
    PM / SERVICOS
    **********************/
    //Carrega Informacoes das Servico
    //pContent[Objeto Xml]
    this.LoadServices = function(pContent) {
        try {
            var Type = new String("Servicos");
            $(pContent).find("servico").each(function(i, e) {
            var positionTop = ucMapaInterativo.GetPositionByTop($(e).attr("positionTop"), "22px");
                var positionLeft = ucMapaInterativo.GetPositionByKm($(e).attr("km"), "27px");

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjDiv = {
                    'position': "absolute",
                    'top': positionTop,
                    'left': positionLeft,
                    'cursor': "pointer",
                    'zIndex': "10"
                }

                var arrTipos = new Array();
                arrTipos = Main.TransformStringArray($(e).attr("tipo"), ",");

                //Cria elemento Img
                $(document.createElement("div"))
                    .attr({ id: Type + "_" + i })
                    .css(cssObjDiv)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.SetPositionTip(arrTipos[0]);
                        ucMapaInterativo.OpenServicesInfo(e, cssObjDiv, Main.TransformStringArray($(e).attr("tiposub"), ","));
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 600);
                    });

                ucMapaInterativo.SetServicesImagens(arrTipos, Type + "_" + i);
            });
            ucMapaInterativo.CreateBoxInfo(Type);
        }
        catch (e) {
            //alert(e);
        }
    }

    //Muda posicao do tip do box 
    this.SetPositionTip = function(pArrTypeImg) {
        try {
            var tipPosition = (pArrTypeImg == "Servico") ? "3px" : "18px";
            $("#ContentPage .box-mapa-interativo .box-info-item img.tip").css("left", tipPosition);
        }
        catch (e) {
            //alert(e);
        }
    }

    //Seta as imagens no box de cadas servico
    this.SetServicesImagens = function(pArrTypeImg, pObjParent) {
        try {
            for (var i = 0; i < pArrTypeImg.length; i++) {

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjImg = {
                    'display': "block",
                    'float': "left"
                }
                
                //Cria elemento Img
                $(document.createElement("img"))
                    .attr({ src: ucMapaInterativo.GetServicesImageName(pArrTypeImg[i]), alt: " " })
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo #" + pObjParent);
            }
        }
        catch (e) {
            //alert(e);
        }
    }

    //Seta as imagens no box info de cadas servico
    this.SetServicesBoxInfoImagens = function(pArrTypeImg) {
        try {
            $("#MapInfoServiceIcons").html("");
            if (pArrTypeImg != "") {
                for (var i = 0; i < pArrTypeImg.length; i++) {

                    //Cria instrucoes Css e posicionamento da imagem
                    var cssObjImg = {
                        'display': "block",
                        'float': "left"
                    }

                    //Cria elemento Img
                    $(document.createElement("img"))
                    .attr({ src: ucMapaInterativo.GetServicesImageName(pArrTypeImg[i]), alt: " " })
                    .css(cssObjImg)
                    .appendTo("#MapInfoServiceIcons");
                }
            }
        }
        catch (e) {
            //alert(e);
        }
    }
    
  
     //Retorna caminho da image servico
    this.GetServicesImageName = function(pType) {
        try {
            var ImagePath = new String("/Themes/" + Main.Theme + "/Img/ucMapaInterativo/");
            var ImageName = new String();

            switch (pType.toString().trim()) {
                case "Restaurante":
                    ImageName = "ico-serv-restaurant.png";
                    break;
                case "Posto":
                    ImageName = "ico-serv-gas.png";
                    break;
                case "GNV":
                    ImageName = "ico-serv-gnv.png";
                    break;
                case "WC":
                    ImageName = "ico-serv-wc.png";
                    break;
                case "PM":
                    ImageName = "ico-pm.png";
                    break;
                case "PF":
                    ImageName = "ico-pf.png";
                    break;
                case "PE":
                    ImageName = "ico-pe.png";
                    break;
                case "SAU":
                    ImageName = "ico-serv-sau.png";
                    break;
                case "Servico":
                    ImageName = "ico-posto_serv.png";
                    break;       
                case "Borracharia":
                    ImageName = "ico-serv-borracharia.png";
                    break;
                case "Medico":
                    ImageName = "ico_postomedico.png";
                    break;

                          
            }
            
            return ImagePath + ImageName;
        }
        catch (e) {
            //alert(e);
        }
    }
    
     //Abre modal com informacoes do servico
    //pObj[objeto Fluxo]
    //pCssObj[objeto css da img carro]
    //pArrTypeImg[Array com sub tipos dos servicos dentro de um posto de servico]
    this.OpenServicesInfo = function(pObj, pCssObj, pArrTypeImg) {
        try {
            
            $("#MapInfoServiceInfo").text($(pObj).attr("nome") + ": ");
            $("#MapInfoServiceKm").text("Km " + $(pObj).attr("kmExibe"));

            ucMapaInterativo.SetServicesBoxInfoImagens(pArrTypeImg);

            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            //alert(e);
        }
    }


    /**********************
    BALANCA
    **********************/
    //Carrega Informacoes das Servico
    //pContent[Objeto Xml]
    this.LoadScales = function(pContent) {
        try {
            var Type = new String("Balancas");
            $(pContent).find("balanca").each(function(i, e) {
                var positionTop = ucMapaInterativo.GetPositionByRoad($(e).attr("rodovia") + "-" + $(e).attr("sentido"), "45px");
                var positionLeft = ucMapaInterativo.GetPositionByKm($(e).attr("km"), "69px");

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjImg = {
                    'position': "absolute",
                    'top': positionTop,
                    'left': positionLeft,
                    'cursor': "pointer",
                    'zIndex': "10"
                }

                //Cria elemento Img
                $(document.createElement("img"))
                    .attr({ src: ucMapaInterativo.GetScalesImageName($(e).attr("sentido")), id: Type + "_" + i, alt: " " })
                    .css(cssObjImg)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .hover(function() {
                        ucMapaInterativo.OpenScalesInfo(e, cssObjImg);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    })
                   .click(function() {
                       //location.href = "#idBoxInfo_" + Type;
                   });
            });
            ucMapaInterativo.CreateBoxInfo(Type);
        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna caminho da image servico
    this.GetScalesImageName = function(pWay) {
        try {
            var ImagePath = new String("/Themes/" + Main.Theme + "/Img/ucMapaInterativo/");
            var ImageName = (pWay == "SUL") ? "ico-Truck-d.png" : "ico-Truck-u.png";

            return ImagePath + ImageName;
        }
        catch (e) {
            //alert(e);
        }
    }

    //Abre modal com informacoes do servico
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenScalesInfo = function(pObj, pCssObj) {
        try {
            $("#MapInfoScalesInfo").text($(pObj).attr("nome") + ": ");
            $("#MapInfoScalesKm").text("Km" + $(pObj).attr("kmExibe"));

            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            //alert(e);
        }
    }    
}
