﻿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 + "?v=" + Math.floor(Math.random() * 110),
            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 "operacao":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.operacao a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/Operacao.xml", null, ucMapaInterativo.LoadOperation);
                    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-servicos":
                    $("#ContentPage .box-mapa-interativo ul.navigation li.pm-servicos a").css("background-position", "0 -15px");
                    ucMapaInterativo.Ajax("/Xml/PM-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[ANCHIETA - IMIGRANTES - CÔNEGO DOMÊNICO RANGONI - PADRE MANOEL DA NOBREGA + Sentido]
    this.GetPositionByRoad = function(pRoad, pHeightImg) {
        try {

            var positionTop = Number();
            var imgPosition = parseInt(parseInt(pHeightImg) / 2);
            switch (pRoad) {
                case "ANCHIETA-NORTE":
                    positionTop = 90;
                    break;
                case "ANCHIETA-SUL":
                    positionTop = 155;
                    break;
                case "IMIGRANTES-NORTE":
                    positionTop = 190;
                    break;
                case "IMIGRANTES-SUL":
                    positionTop = 260;
                    break;
                case "CÔNEGO DOMÊNICO RANGONI-OESTE":
                    positionTop = 19;
                    break;
                case "CÔNEGO DOMÊNICO RANGONI-LESTE":
                    positionTop = 80;
                    break;
                case "PADRE MANOEL DA NOBREGA-OESTE":
                    positionTop = 305;
                    break;
                case "PADRE MANOEL DA NOBREGA-LESTE":
                    positionTop = 255;
                    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");
            }
            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);
        }
    }

    this.CloseBoxInfo = function() {
        try {
            $("#ContentPage .box-mapa-interativo .box-info-item").hide();
            clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
        }
        catch (e) {
            //alert(e);
        }

    }

    /**********************
    TRAFEGO / TEMPO VIAGEM
    **********************/

    //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"));

                //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) + 5) + "px",
                    'left': (parseInt(positionLeft)) + "px",
                    'width': "55px",
                    'textAlign': "center",
                    'fontSize': "12px",
                    '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.CreateChronometer("anchieta", "litoral");
            ucMapaInterativo.CreateChronometer("imigrantes", "litoral");
            ucMapaInterativo.CreateChronometer("anchieta", "cidade");
            ucMapaInterativo.CreateChronometer("imigrantes", "cidade");

            ucMapaInterativo.CreateBoxInfo(Type);

            //ucMapaInterativo.SetBoxInfoVehiclesPerHour(pContent);
        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Retorna a posicao do carro por:
    //pRoad[ANCHIETA - IMIGRANTES - CÔNEGO DOMÊNICO RANGONI - PADRE MANOEL DA NOBREGA + Sentido]
    this.GetTrafficPositionByRoad = function(pRoad) {
        try {
            var positionTop = Number();
            switch (pRoad) {
                case "ANCHIETA-Sul":
                    positionTop = 113;
                    break;
                case "ANCHIETA-Norte":
                    positionTop = 95;
                    break;
                case "IMIGRANTES-Sul":
                    positionTop = 210;
                    break;
                case "IMIGRANTES-Norte": 
                    positionTop = 190;
                    break;
                case "CÔNEGO DOMÊNICO RANGONI-Leste":
                    positionTop = 65;
                    break;
                case "CÔNEGO DOMÊNICO RANGONI-Oeste":
                    positionTop = 15;
                    break;
                case "PADRE MANOEL DA NOBREGA-Leste":
                    positionTop = 295;
                    break;
                case "PADRE MANOEL DA NOBREGA-Oeste":
                    positionTop = 240;
                    break;
                default:
                    positionTop = -9000;
                    break;
            }
            return positionTop.toString() + "px";
        }
        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.GetTrafficPositionByZone = function(pZone, pWay, pRoad) {
        try {
            var positionLeft = Number();
            switch (pZone) {
                case "PLANALTO":
                    positionLeft = 230;
                    break;
                case "SERRA":
                    positionLeft = 460;
                    break;
                case "BAIXADA":
                    positionLeft = 730;
                    break;
                default:
                    positionLeft = -9000;
                    break;
            }

            if (pRoad == "CÔNEGO DOMÊNICO RANGONI")
                positionLeft = 800;
            else if (pRoad == "PADRE MANOEL DA NOBREGA")
                positionLeft = 520;

            positionLeft = ((pWay == "Sul") || (pWay == "Leste")) ? (positionLeft + 65) : positionLeft;

            positionLeft = ((pRoad == "CÔNEGO DOMÊNICO RANGONI") && (pWay == "Leste")) ? (positionLeft-100) : positionLeft;

            return positionLeft.toString() + "px";
        }
        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") == "Sul") || ($(e).attr("sentido") == "Leste")) ? "d" : "u";
            
            if(($(e).attr("regiao") == "SERRA") && (pArrRunway != undefined))
                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 {
            $("#MapInfoCarRoadWay").text($(pObj).attr("nome") + " / " + $(pObj).attr("sentido"));
            $("#MapInfoCarZone").text($(pObj).attr("regiao"));
            $("#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().toLowerCase() + "']").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-imigrantes .veiculo-sul").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "IMIGRANTES", "sul") + " veículos / hora");
            $(".box-veiculos-hora .road-imigrantes .veiculo-norte").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "IMIGRANTES", "norte") + " veículos / hora");

            $(".box-veiculos-hora .road-anchieta .veiculo-sul").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "ANCHIETA", "sul") + " veículos / hora");
            $(".box-veiculos-hora .road-anchieta .veiculo-norte").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "ANCHIETA", "norte") + " veículos / hora");

            $(".box-veiculos-hora .road-conego .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "CÔNEGO DOMÊNICO RANGONI", "leste") + " veículos / hora");
            $(".box-veiculos-hora .road-conego .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "CÔNEGO DOMÊNICO RANGONI", "oeste") + " veículos / hora");

            $(".box-veiculos-hora .road-manoel .veiculo-leste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "PADRE MANOEL DA NOBREGA", "leste") + " veículos / hora");
            $(".box-veiculos-hora .road-manoel .veiculo-oeste").text(ucMapaInterativo.GetInfoVehiclesPerHour(pContent, "PADRE MANOEL DA NOBREGA", "oeste") + " veículos / hora");
        }
        catch (e) {
            //alert(e);
        }
    }    

    //Cria as imagens de Cronometro
    //pRoad[anchieta - imigrantes]
    this.CreateChronometer = function(pRoad, pSentido) {
        try {
            var cssObjImg = {
                'position': "absolute",
                'top': (pRoad == "anchieta") ? "100px" : "198px",
                'left': (pSentido == "litoral") ? "30px" : "875px",
                'cursor': "pointer",
                'zIndex': "10"
            }

            var cssObjTrajeto = {
                'position': "absolute",
                'top': (pRoad == "anchieta") ? "70px" : "70px",
                'left': (pSentido == "litoral") ? "70px" : "90px",
                'display': "none",
                'zIndex': "20"
            }

            //Cria elemento Img
            $(document.createElement("img"))
                .attr({ src: "/Themes/" + Main.Theme + "/Img/ucMapaInterativo/ico-chronometer-small.png", alt: " " })
                .css(cssObjImg)
                .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                .hover(function() {
                    $("#ContentPage .box-mapa-interativo .box-info-" + pRoad.toString().toLowerCase() + "-" + pSentido.toString().toLowerCase()).show();
                    $("#ContentPage .box-mapa-interativo .item-mapa").hide();
                    $("#img-percursso-" + pRoad + "-" + pSentido).show();
                },
                function() {
                    $("#ContentPage .box-mapa-interativo .box-info-tempo-viagem").hide();
                    $("#ContentPage .box-mapa-interativo .item-mapa").show();
                    $("#ContentPage .box-mapa-interativo .item-percurso").hide();
                })


            //Cria elemento Img para trajeto
            $(document.createElement("img"))
                    .attr({ src: "/Themes/" + Main.Theme + "/Img/ucMapaInterativo/img-percursso-" + pRoad + "-" + pSentido + ".png", id: "img-percursso-" + pRoad + "-" + pSentido, alt: " " })
                    .css(cssObjTrajeto)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .addClass("item-percurso");

            if (!this.LoadedTempoViagem) {
                this.LoadedTempoViagem = true;
                ucMapaInterativo.Ajax("/Xml/TempoViagem.xml", null, ucMapaInterativo.CreateTempoViagem, pRoad);
            }
        }
        catch (e) {
            //alert(e);
        }
    }

    //Cria o tempo de viagem no mapa
    this.LoadedTempoViagem = false;
    this.CreateTempoViagem = function(pContent, pRoad) {
        try {
            $(pContent).find("LITORALSUL").each(function(i, e) {

                if (i == 0)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "IMIGRANTES", "LITORALSUL", "litoral");
                else if (i == 2)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "ANCHIETA", "LITORALSUL", "litoral");
                else if (i == 1)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "LITORALSUL", "IMIGRANTES", "cidade");
                else if (i == 3)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "LITORALSUL", "ANCHIETA", "cidade");


            });
            $(pContent).find("SAOVICENTE").each(function(i, e) {
                if (i == 0)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "IMIGRANTES", "SAOVICENTE", "litoral");
                else if (i == 2)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "ANCHIETA", "SAOVICENTE", "litoral");
                else if (i == 1)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "SAOVICENTE", "IMIGRANTES", "cidade");
                else if (i == 3)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "SAOVICENTE", "ANCHIETA", "cidade");
            });
            $(pContent).find("SANTOS").each(function(i, e) {
                if (i == 0)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "IMIGRANTES", "SANTOS", "litoral");
                else if (i == 2)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "ANCHIETA", "SANTOS", "litoral");
                else if (i == 1)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "SANTOS", "IMIGRANTES", "cidade");
                else if (i == 3)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "SANTOS", "ANCHIETA", "cidade");
            });
            $(pContent).find("GUARUJA").each(function(i, e) {
                if (i == 0)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "IMIGRANTES", "GUARUJA", "litoral");
                else if (i == 2)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "ANCHIETA", "GUARUJA", "litoral");
                else if (i == 1)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "GUARUJA", "IMIGRANTES", "cidade");
                else if (i == 3)
                    ucMapaInterativo.CreateBoxTempoViagem($(this).attr("MINUTOS"), "GUARUJA", "ANCHIETA", "cidade");
            });
        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Cria box com as informacoes do tempo de viagem
    this.CreateBoxTempoViagem = function(pTime, pRoad, pWay, pTipo) {
        try {
            var sClassName = "box-info-" + pRoad.toString().toLowerCase() + "-" + pTipo.toString().toLowerCase();
            if (pTipo.toString().toLowerCase() == "cidade")
                sClassName = "box-info-" + pWay.toString().toLowerCase() + "-" + pTipo.toString().toLowerCase();

            var sTempo = pTime + " Min.";
            if (pTime == "0")
                sTempo = "N/D";

            $(document.createElement("div")).addClass("box-info-tempo-viagem").addClass("box-info-tempo-viagem-" + pTipo).addClass(sClassName).addClass("box-info-" + pRoad.toString().toLowerCase()).addClass("box-info-" + pWay.toString().toLowerCase() + "-" + pRoad.toString().toLowerCase()).appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo");
            $(document.createElement("div")).addClass("info").appendTo("#ContentPage .box-mapa-interativo .box-info-" + pWay.toString().toLowerCase() + "-" + pRoad.toString().toLowerCase());
            $(document.createElement("span")).appendTo("#ContentPage .box-mapa-interativo .box-info-" + pWay.toString().toLowerCase() + "-" + pRoad.toString().toLowerCase() + " .info").text(sTempo);
        }
        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.GetCameraPositionByRoad($(e).attr("rodovia"));
                var positionLeft = ucMapaInterativo.GetPositionByKm($(e).attr("km"), "25px");

                //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) + 17) + "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.toString().toUpperCase()) {
                case "ANCHIETA":
                    positionTop = 110;
                    break;
                case "IMIGRANTES":
                    positionTop = 205;
                    break;
                case "CÔNEGO DOMÊNICO RANGONI":
                    positionTop = 45;
                    break;
                case "PADRE MANOEL DA NOBREGA":
                    positionTop = 250;
                    break;
                case "INTERLIGAÇÃO":
                    positionTop = 155;
                    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", "-");
            $("#MapInfoCamRoad").text($(pObj).attr("rodovia"));
            $("#MapInfoCamLnkImg").attr("href", "/Content/Cameras/" + $(pObj).attr("img")).attr("title", $(pObj).attr("trecho") + " - Atualizado: " + $(pObj).attr("data"));
            $("#MapInfoCamImg").attr("src", "/Content/Cameras/" + $(pObj).attr("img"));
            $("#MapInfoCamIfo").text($(pObj).attr("trecho") + " / Km " + $(pObj).attr("kmExibe"));

            $("a[rel='CameraLiveMap']").colorbox();
            
            var topBox = parseInt(pCssObj.top) - $("#ContentPage .box-mapa-interativo .box-info-item").height() - 7;
            $("#ContentPage .box-mapa-interativo .box-info-item .tip").show();
            
            //hack para camera 15 aparecer o box abaixo
            if($(pObj).attr("id") == 15) {
                topBox = parseInt(pCssObj.top) + 35;
                $("#ContentPage .box-mapa-interativo .box-info-item .tip").hide();
            }
            
            $("#ContentPage .box-mapa-interativo .box-info-item").css({
                'top': topBox,
                'left': pCssObj.left
            }).show();
        }
        catch (e) {
            //alert(e);
        }
    }


    /**********************
    OPERACAO
    **********************/

    //Carrega Informacoes de Trafego
    //pContent[Objeto Xml]
    this.LoadOperation = function(pContent) {
        try {

            var Type = new String("Operacao");
            var objOperation = ucMapaInterativo.ConvertOperationObj($(pContent).find("operacao").attr("pistas"));
            var positionTop = Number();
            var positionLeft = Number();
            var nameImage = String();
            var imgWidth = 19;
            var x = 1;
            var t = 1;
            var j = 1;
            var q = 1;
            
            //Cria instrucoes Css e posicionamento do titulo
            var cssObjTitle = {
                'display': "block",
                'position': "absolute",
                'top': "40px",
                'left': "0",
                'height': "28px",
                'padding': "0 0 0 35px",
                'font': "bold 18px Arial, verdana",
                'color': "#393",
                'background': "transparent url(/Themes/" + Main.Theme + "/Img/ucMapaInterativo/ico-operation-arrow.png) no-repeat 0 0",
                'zIndex': "10"
            }

            //Cria elemento Titulo
            $(document.createElement("h4"))
                    .css(cssObjTitle)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                    .text("Operação: " + objOperation.Dow.length + " x " + objOperation.Up.length);

            var cssObjTitleStrong = {
                'fontWeight': "normal",
                'color': "#666"
            }

            //Cria elemento Img
            $(document.createElement("span"))
                    .css(cssObjTitleStrong)
                    .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo h4")
                    .text(" // " + objOperation.Dow.length + " Litoral x " + objOperation.Up.length + " Capital");

            for (var i = 1; i <= objOperation.Total.length; i++) {
                //1 ao 3 Imigrantes Pista SUL
                if (i <= 3) {
                    positionLeft = (475 + (imgWidth * x));
                    positionTop = 242;
                    x++;
                }
                //4 ao 6 Imigrantes Pista NORTE
                else if ((i > 3) && (i <= 6)) {
                    positionLeft = (425 + (imgWidth * t));
                    positionTop = 177;
                    t++;
                }
                //7 e 8 Anchieta Pista SUL
                else if ((i > 6) && (i <= 8)) {
                    positionLeft = (475 + (imgWidth * j));
                    positionTop = 142;
                    j++;
                }
                //9 e 10 Anchieta Pista Norte
                else if ((i > 8) && (i <= 10)) {
                    positionLeft = (425 + (imgWidth * q));
                    positionTop = 85;
                    q++;
                }

                //Cria instrucoes Css e posicionamento da imagem
                var cssObjImg = {
                    'position': "absolute",
                    'top': positionTop.toString() + "px",
                    'left': positionLeft.toString() + "px",
                    'zIndex': "10"
                }

                //Cria elemento Img
                if ((objOperation.Total[i - 1] == "D") || (objOperation.Total[i - 1] == "S")) {
                    nameImage = (objOperation.Total[i - 1] == "D") ? "ico-operation-r.png" : "ico-operation-l.png";
                    $(document.createElement("img"))
                        .attr({ src: "/Themes/" + Main.Theme + "/Img/ucMapaInterativo/" + nameImage, id: Type + "_" + i, alt: " " })
                        .css(cssObjImg)
                        .appendTo("#ContentPage .box-mapa-interativo .content-mapa-interativo")
                }
            }

            //ucMapaInterativo.CreateBoxInfo(Type);
        }
        catch (e) {
            //alert(e);
        }
    }

    //Converte o nó pista em objeto Operacao
    this.ConvertOperationObj = function(pRunway) {
        try {
            var obj = new Object();
            var arrRunway = new Array();
            var d = new Number();
            var s = new Number();
            var x = new Number();

            arrRunway = Main.TransformStringArray(pRunway, "");
            obj.Total = new Array(arrRunway);
            obj.Dow = new Array();
            obj.Up = new Array();
            obj.Close = new Array();

            for (i in arrRunway) {
                if (arrRunway[i] == "D") {
                    obj.Dow[d] = arrRunway[x];
                    d++;
                }
                else if (arrRunway[i] == "S") {
                    obj.Up[s] = arrRunway[x];
                    s++;
                }
                else if (arrRunway[i] == "X") {
                    obj.Close[x] = arrRunway[x];
                    x++;
                }

                obj.Total[i] = arrRunway[i];
            }
            return obj;
        }
        catch (e) {
            //alert(e);
        }
    }

    //Carrega Informacoes de Operacoes
    //pContent[Objeto Xml]
    this.LoadOperationInfo = function(pContent) {
        try {
            
            var objOperation = ucMapaInterativo.ConvertOperationObj($(pContent).find("operacao").attr("pistas"));
            var nameCss = String();

            //Box Operacoes
            $(".box-featured-operacao .type-operacao").html("<span>" + objOperation.Dow.length + " x " + objOperation.Up.length + "</span> // " + objOperation.Dow.length + " Litoral x " + objOperation.Up.length + " Capital<br />");
            //Mapa Interativo barra de Info Operacoes
            $(".box-featured-operacao .txt-operacao").html("<strong>Operação: " + objOperation.Dow.length + " x " + objOperation.Up.length + "</strong> // " + objOperation.Dow.length + " Litoral x " + objOperation.Up.length + " Capital");
            

            for (var i = 1; i <= objOperation.Total.length; i++) {
                if ((objOperation.Total[i - 1] == "D") || (objOperation.Total[i - 1] == "S")) {
                    nameCss = (objOperation.Total[i - 1] == "D") ? "down" : "up";
                    //1 ao 3 Imigrantes Pista SUL
                    if (i <= 3)
                        $(".box-featured-operacao .road-imigrantes .sul label.road_" + i).addClass(nameCss);
                    //4 ao 6 Imigrantes Pista NORTE
                    else if ((i > 3) && (i <= 6))
                        $(".box-featured-operacao .road-imigrantes .norte label.road_" + i).addClass(nameCss);
                    //7 e 8 Anchieta Pista SUL
                    else if ((i > 6) && (i <= 8))
                        $(".box-featured-operacao .road-anchieta .sul label.road_" + i).addClass(nameCss);
                    //9 e 10 Anchieta Pista Norte
                    else if ((i > 8) && (i <= 10))
                        $(".box-featured-operacao .road-anchieta .norte label.road_" + i).addClass(nameCss);
                }
            }
        }
        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': "150px",
                    '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[Planalto - Serra - Baixada]
    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[Planalto - Serra - Baixada]
    this.GetWeatherPositionByZone = function(pZone) {
        try {
            var positionLeft = new String();
            switch (pZone.toString()) {

                case "Planalto":
                    positionLeft = this.GetPositionByKm("15", "20");
                    break;
                case "Serra":
                    positionLeft = this.GetPositionByKm("45", "20");
                    break;
                case "Baixada":
                    positionLeft = this.GetPositionByKm("74", "20");
                    break;
                default:
                    positionLeft = -9000;
                    break;
            }
            return positionLeft.toString();

        }
        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 {
            $("#MapInfoWeatherTitle").text(pObj.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.GetPositionByRoad($(e).attr("rodovia") + "-" + $(e).attr("sentido"), "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.CreateTollMaskRoad("127px", "255px", "11px");
            ucMapaInterativo.CreateTollMaskRoad("222px", "255px", "15px");
            ucMapaInterativo.CreateTollMaskRoad("50px", "785px", "4px");
            ucMapaInterativo.CreateTollMaskRoad("285px", "620px", "4px");
        }
        catch (e) {
            //alert(e);
        }
    }

    //Retorna caminho da image camera:
    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 do trafego
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenTollInfo = function(pObj, pCssObj) {
        try {
            $("#MapInfoTollTitle").text("ROD. " + $(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);
        }
    }

    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);
        }
    }

    /**********************
    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"), "22");
                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.OpenServicesInfo(e, cssObjDiv);
                        clearTimeout(ucMapaInterativo.setTimeOpenBoxInfo);
                    },
                    function() {
                        ucMapaInterativo.setTimeOpenBoxInfo = setTimeout(ucMapaInterativo.CloseBoxInfo, 2000);
                    });

                ucMapaInterativo.SetServicesImagens(arrTipos, Type + "_" + i);
            });
            ucMapaInterativo.CreateBoxInfo(Type);
        }
        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);
        }
    }
  
     //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 "SAU":
                    ImageName = "ico-serv-sau.png";
                    break;
                case "Patio":
                    ImageName = "ico-serv-patio.png";
                    break;
            }
            
            return ImagePath + ImageName;
        }
        catch (e) {
            //alert(e);
        }
    }
    
     //Abre modal com informacoes do servico
    //pObj[objeto Fluxo] 
    //pCssObj[objeto css da img carro]
    this.OpenServicesInfo = function(pObj, pCssObj) {
        try {
            
            $("#MapInfoServiceInfo").text($(pObj).attr("nome") + ": ");
            $("#MapInfoServiceKm").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);
        }
    }

    /**********************
    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);
        }
    }

