﻿var backParent = "";

function pageload(hash) {
    // hash doesn't contain the first # character.

    if (hash) {
        
        var SplitHash = hash.split('-');
        if(SplitHash.length > 0)
        {
            var HashMenuIndex = 0;
            
            if(SplitHash[0].indexOf(".") != -1 || SplitHash.length == 2)
                HashMenuIndex = 1;
            
            var array = SplitHash[HashMenuIndex].split('/');
                
            if(array.length > 0)
            {
                if(SplitHash.length > 2)
                {
                    showParentThrdLvl(array[0]);
                    var beforeDiv = "";
                    try
                    {
                        beforeDiv = array[1];
                    }
                    catch(ex){}
                    if(SplitHash[0] != "")
                    {
                        var text = SplitHash[2];
                        while(text.indexOf("_") != -1)
                        {
                            text = text.replace("_"," ");
                        }
                        insertContentDynamic(array[0],SplitHash[0],text,beforeDiv);
                    }
                }
                else
                {   
                    if(array.length > 1)
                    {
                        if($(".menu2ndLvl:visible").size() == 0)
                            showParent(array[0]);
                        
                        insertContent(array[0], array[1]);
                    }
                    else
                    {
                        showParent(array[0]);
                    }
                    
                }
            }
            
            if(SplitHash[0] != "" && SplitHash[0].indexOf(".") != -1)
                AjaxLoad(SplitHash[0]);
            
        }
    } 
    else {
        // start page
        
    }
}
function changeBgColor()
{
    var color = $("#animBg").val() != "" ? $("#animBg").val():"#FFF"
    $("body").animate({
            "backgroundColor" : color
    },eval($("#tbxTiempoColor").val()));
}
function changeBgImage()
{
    $("#tester").BgImageTransition($("#animImagen").val());
}
function insertContentDynamic(ParentID,url,Text,beforeDiv)
{
    //if(.is(":animated"))
        
    PathParentID = "path"+ParentID;
    
    
    $("#testDiv").html("<span class='topMenuLevel1 topMenuLevel1On'>/</span>"+$("#div"+beforeDiv+" div").html() + "/<a href=\""+url + window.location.hash +"\" onclick=\"javascript:return LoadPageWithoutMenu('"+url+"');\">"+Text+"</a>");
    
    // obtiene el tamaño que va a tener la capa
    var nextWidth = document.getElementById("testDiv").clientWidth +"px";
    
    // prepara la capa para el repintado
    $("#"+PathParentID+" div.textSub").stop().css("width", "0px");
    
    
    // mete el texto
    $("#"+PathParentID+" div").stop().html(document.getElementById("testDiv").innerHTML).find("a").css("color","#FFFFFF");
    
    // anima repintado
    $("#"+PathParentID+" div.textSub").stop().animate({
        "width" : nextWidth
    },400);
    
    // anima resize de la capa
    $("#"+PathParentID).stop().animate({
        "width" : nextWidth
    },400);
    
    
}
function insertContent(ParentID,itemID)
{
    divItemID = "div"+itemID;
    PathParentID = "path" + ParentID;

    if (!$("#div" + ParentID).hasClass("topMenuLevel1On"))
        $("#div" + ParentID).addClass("topMenuLevel1On").siblings(".topMenuLevel1On").css("color", "").removeClass("topMenuLevel1On");

    document.getElementById("testDiv").innerHTML = "";
    document.getElementById("testDiv").innerHTML = $("#"+divItemID+" div").html();
    
    // obtiene el tamaño que va a tener la capa
    var nextWidth = document.getElementById("testDiv").offsetWidth + 13 + "px";

    

    // prepara la capa para el repintado
    $("#"+PathParentID+" div.textSub").css({"width" : "0px"});
    
    // mete el texto
    $("#"+PathParentID+" div").html("<span class='topMenuLevel1 topMenuLevel1On'>/</span>"+$("#"+divItemID+" div").html()).find("a").css("color","#FFFFFF");
    
    // anima repintado
    $("#"+PathParentID+" div.textSub").animate({
        "width" : nextWidth
    },400);
    
    // anima resize de la capa
    $("#"+PathParentID).animate({
        "width" : nextWidth
    },400);
    
    
    if(!$("#"+divItemID).hasClass("subHidden"))
    {
        // restablecer el anterior
        $(".subHidden").animate({
            "width" : "show"
        },200).removeClass("subHidden");
        
        // el itemIDo clickado
        $("#"+divItemID).stop().animate({
            "width" : "hide"
        }, 200).addClass("subHidden");
    }
}
function showParentThrdLvl(parentID)
{
    var divparentID = "div" + parentID;
    var secondLvl = "sub" + parentID;
    
    $("#"+divparentID).addClass("topMenuLevel1On");
    objParent = document.getElementById(divparentID);
    // oculta el resto de menus inferiores y rutas
    if($("#"+secondLvl).size() > 0)
    {
        // muestra lo nuevo
        $("#"+secondLvl).stop().css({"left":objParent.offsetLeft,"top":objParent.offsetTop+25});
        
        $("#"+secondLvl).stop().show();
    }
    
    backParent = parentID;
}
function showParent(parentID)
{
    var divparentID = "div" + parentID;
    var secondLvl = "sub" + parentID;
    if(!$("#" + divparentID).hasClass("topMenuLevel1On"))
        $("#" + divparentID).addClass("topMenuLevel1On").siblings(".topMenuLevel1On").css("color","").removeClass("topMenuLevel1On");
    // Vuelve a hacer click en el mismo
    if(parentID == backParent)
    {
        // oculta el resto de menus inferiores y rutas
        $(".MenuPath").animate({
            "width":"0px"
        },200,function(){
            $(this).find("div.textSub").html("")
        });
        // restablecer el anterior
        $(".subHidden").animate({
            "width":"show"
        },200).removeClass("subHidden");
    }
    else
    {
        //$("#div"+backParent).removeClass("topMenuLevel1On").css("color", "#D3222A");
        
        objParent = document.getElementById(divparentID);
        // oculta el resto de menus inferiores y rutas
        if($("#"+secondLvl).size() > 0)
        {
            $(".MenuPath").stop().css({
                "width":"0px"
            }).hide();
            
            $(".subHidden").animate({
                "width":"toggle"
            },200).removeClass("subHidden");
            
            $(".menu2ndLvl").stop().hide();
                    
            // muestra lo nuevo
            $("#"+secondLvl).stop().css({"left":objParent.offsetLeft,"top":objParent.offsetTop+25});
            
            $("#"+secondLvl).stop().show();
        }
        else
        {
             $(".MenuPath").stop().css({
                "width":"0px"
            }).hide();
            
            $(".subHidden").animate({
                "width":"toggle"
            },200).removeClass("subHidden");
            
            $(".menu2ndLvl").stop().hide();
        }
    }
    backParent = parentID;
}
function LoadPage(url) {
    return false;
}