﻿function Main() {
    this.Theme = new String();
    //Inicializa o Objeto Main
    this.Initialize = function(pTheme) {
        this.Theme = pTheme;
        $(document).ready(function() {
            $(document).pngFix();
            Navigation.Initialize();
            Main.SelectGroupSites();
            Main.TemplateColunas();
            Main.LinkExternal();

        });
    }

    //Seta Imagem no header
    this.SetHeaderImage = function(pImage) {
    try {
            if(pImage != "")
                $("#Ecorodovias").css("backgroundImage", "url(/Themes/" + Main.Theme + "/Img/Main/Header/" + pImage + ")");
        }
        catch (e) {
            //alert(e);
        }
    }

    //Seleciona os itens do Grupo ecovias
    this.SelectGroupSites = function() {
        try {
            $("#fldSelectGroupSite").change(function() {
                if ($(this).val() != 0) {
                    switch ($(this).val()) {
                        case "1":
                            window.open("http://www.ecorodovias.com.br/");
                            break;
                        case "2":
                            window.open("http://www.ecovias.com.br");
                            break;
                        case "3":
                            window.open("http://www.ecovia.com.br");
                            break;
                        case "4":
                            window.open("http://www.ecopistas.com.br");
                            break;
                        case "5":
                            window.open("http://www.ecocataratas.com.br");
                            break;
                        case "6":
                            window.open("http://www.ecosul.com.br");
                            break;
                        case "7":
                            window.open("http://www.ecopatio.com.br");
                            break;
                        case "8":
                            window.open("http://www.mzweb.com.br/ecorodovias/web/default_pt.asp?idioma=0&conta=28#");
                            break;
                        case "9":
                            window.open("http://www.eloglogistica.com.br/");
                            break;
                    }
                }
            });
        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Configura altura no template de 3 colunas
    this.TemplateColunas = function() {
        try {
            $("#Content").height('auto');
            if ($("#BarInfoMain").attr("id")) {
                var maxHeight = $("#Content").height();

                if (maxHeight < $("#BarInfo").height())
                    maxHeight = $("#BarInfo").height();
                if (maxHeight < $("#BarInfoMain").height())
                    maxHeight = $("#BarInfoMain").height();

                $("#Content").height(maxHeight);
            }
        }
        catch (e) {
            //alert(e);
        }
    }

    //Coloca Target Blank em Links externos [rel='external']
    this.LinkExternal = function() {
        try {
            $("a[rel*=External]").live("click", function() {
                window.open(this.href);
                return false;
            });
        }
        catch (e) {
            //alert(e);
        }
    }

    //Transforma String em Array
    this.TransformStringArray = function(pString, pRegExp) {
        try {
            var array = new Array();
            array = pString.toString().split(pRegExp);
            return array;
        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Abre e fecha box
    this.OpenBoxInfo = function(pElement) {
        try {
            $("." + pElement).toggle(
                function() {
                    $(this).addClass("title-active"); 
                    $(this).next("div").show();
                },
                function() {
                    $(this).removeClass("title-active");
                    $(this).next("div").hide();
                });
        }
        catch (e) {
            //alert(e);
        }
    }
   
    //Exibe icone de carregando quando a funcao ajax
    this.LoadAjax = function(pParentElement) {
        try {
            var objParent = $(pParentElement);
            var cssWidth = objParent.width();
            var cssHeight = objParent.height();
            var imgLoadingWidth = 32;
            var imgLoadingHeight = 32;


            //Cria elemento div container loading
            var cssObjContainerLoading = {
                position: "absolute",
                top: 0,
                left: 0,
                width: cssWidth.toString() + "px",
                height: cssHeight.toString() + "px",
                cursor: "progress",
                backgroundColor: "#ccc",
                overflow: "hidden",
                zIndex: "100",
                opacity: "0.6",
                filter: "alpha(opacity=60)"
            }

            $(document.createElement("div"))
                    .addClass("loading-ajax")
                    .css(cssObjContainerLoading)
                    .appendTo(objParent)

            //Cria elemento div container loading
            var cssPositionTop = (cssHeight / 2) - (imgLoadingHeight / 2);
            var cssPositionLeft = (cssWidth / 2) - (imgLoadingWidth / 2);
            
            var cssObjImgLoading = {
                position: "absolute",
                top: cssPositionTop.toString() + "px",
                left: cssPositionLeft.toString() + "px",
                cursor: "progress",
                zIndex: "110"
            }

            $(document.createElement("img"))
                    .attr({ src: "/Themes/" + Main.Theme + "/Img/Main/loading.gif" })
                    .addClass("loading-ajax-img")
                    .css(cssObjImgLoading)
                    .appendTo(objParent)
        }
        catch (e) {
            //alert(e);
        }
    }
    //Exclui icone carregando quando acaba funcao ajax
    this.LoadAjaxClear = function() {
        try {
            $(".loading-ajax-img").remove();
            $(".loading-ajax").remove();
        }
        catch (e) {
            //alert(e);
        }
    }
    
    //Customiza modal color box
    this.CustonModal = function() {
        try {
            $(document.createElement("div")).addClass("md-header").appendTo("#cboxContent");
            $(document.createElement("img")).addClass("md-header-logo").attr({ src: "/Themes/" + Main.Theme + "/Img/Main/Header/lg-ecovias.gif" }).appendTo("#cboxContent .md-header");
        }
        catch (e) {
            //alert(e);
        }
    }

    //Fecha modal de Layer Banner
    this.CloseModalLayerbanner = function() {
        try {
            $("#mdLayerbanner").remove();
            clearTimeout(_parent.stCloseModalLayerbanner);
        }
        catch (e) {
            //alert(e);
        }

    }


