﻿
var html = "<ul>";
var menuCount = 0;
InitMenu();
function InitMenu() {
    $(document).ready(function() {
        $.get('XML/Menu.xml', function(obj) {
            SetTree("menu", obj);
            $("#menu_list").html(html + "</ul>");
            SetHide("#menu_list li");
            SetDotPic("#menu_list ul li span li");
        });
    });
}

function SetDotPic(treeName) {
    $(treeName).each(function() {
    $(this).html("<img src='Skin/default/images/menu_dot.gif'/>" + $(this).html());
        $(this).addClass("dot_Img");
    });
}


function SetHide(treeName) {
    $(treeName).each(function() {
        var id = $(this).attr("id");
        $("#" + id + " a").click(
            function() {
                $("#" + id + "_child").toggle();
            });
    });
}

function SetTree(treeName, object) {
    $(object).find(treeName).each(function() {
        SetChildTree($(this));
    });
}

function SetChildTree(object) {
    menuCount += 1;
    var menuTitle = object.attr("title");
    var menuURL = object.attr("url");
    var imgUrl = object.attr("imgUrl");
    html += "<li id='menu_" + menuCount + "' style='background-image:url(\"" + imgUrl + "\")'>";
    if (menuURL.indexOf("http") > -1) {
        html += '<a href="' + menuURL + '" target="_blank">' + menuTitle + '</a>';
    }
    else {
        html += '<a onclick="javascript:ShowPage(\'' + menuURL + '\');" >' + menuTitle + '</a>';
    }
    if (menuURL == '#') {
        html += "<span style='display:none' id='menu_" + menuCount + "_child'>";
        SetTree("item", object);
        html += "</span>";
    }
    html += '</li>';
}

$("#Content").html("<iframe width='590px' src='Main.aspx'  id='Iframe' name='Iframe' height='800px' frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='no'></iframe>");

function ShowPage(url) {
    if (url != '#') {
        $("#Content").html("<iframe width='590px' src='" + url + "'  id='Iframe' name='Iframe' onload='Javascript:SetIframeHeight()' frameborder='no' border='0' marginwidth='0' marginheight='0'  scrolling='no'></iframe>");
    }
}