
/* - ddmenu.js - */
// vim:ft=javascript:ts=4:sw=4:expandtab

ddmenu_data = {
"root":"",
"items":[
  {"id":"portaltab-team", "items":[
    {"name":"Overview", "href":"/team"},
    {"name":"History", "href":"/team/iit-history"},
    {"name":"Global Board of Directors", "href":"/team/paniit-alumni-global-board"},
    {"name":"India Board of Directors", "href":"http://www.paniitalumni.org/about-paniit-alumni/organization' target='_blank"},
    {"name":"USA Board of Directors", "href":"/team/board-of-directors-pan-iit-inc.-usa-1"},
    {"name":"USA Exec Committee", "href":"/team/usa-executive-committee"}
  ]},
  {"id":"portaltab-news", "items":[
    {"name":"Featured Press", "href":"/news"},
    {"name":"Press Archives", "href":"/news/press-archives"}
  ]},
  {"id":"portaltab-chapters", "items":[
    {"name":"Australia", "href":"http://www.iitaa.org.au/' target='_blank"},
    {"name":"Canada", "href":"http://chapters.iit.org/?page=IITACHOME"},
    {"name":"Chicago (Midwest)", "href":"http://iitmidwest.org/' target='_blank"},
    {"name":"Europe", "href":"http://www.iit-eu.org/' target='_blank"},
    {"name":"Houston", "href":"http://iitagh.org/' target='_blank"},
    {"name":"London (UK)", "href":"http://www.iitlc.org/' target='_blank"},
    {"name":"New York", "href":"/chapters/gny"},
    {"name":"New England", "href":"http://chapters.iit.org/?page=IITSINE"},
    {"name":"North Texas", "href":"http://www.iitnt.org/' target='_blank"},
    {"name":"Pacific Northwest", "href":"http://www.iitpnw.org/' target='_blank"},
    {"name":"San Francisco Bay Area", "href":"http://www.iitbayarea.org/' target='_blank"},
    {"name":"Singapore", "href":"http://www.iit-alumni.org.sg/htm/hom/home.html' target='_blank"},
    {"name":"Southeast", "href":"http://www.iitsoutheast.com/' target='_blank"},
    {"name":"Southern California, LA", "href":"http://chapters.iit.org/?page=Socal"},
    {"name":"Tennessee", "href":"/chapters/tn/"},
    {"name":"Washington, DC", "href":"http://chapters.iit.org/?page=capitalIIT"}

  ]},
  //{"id":"portaltab-books", "items":[
  //  {"name":"Books about IIT", "href":"/books"},
  //  {"name":"Books by IIT Alum", "href":"/books/books-by-iit-alum"}
  //]},
  {"id":"portaltab-news-letters", "items":[
    {"name":"2010 Letter from the <br/>President", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102925582330.html' target='_blank"},
    {"name":"September 09", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102730651987.html' target='_blank"},
    {"name":"Special Edition for <br/>Pan IIT 2009 USA", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102637554604.html' target='_blank"},
    {"name":"May 09", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102589230155.html' target='_blank"},
    {"name":"April 09", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102564824282.html' target='_blank"},
    {"name":"March 09", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102532925614.html' target='_blank"},
    {"name":"February 09", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102464469465.html' target='_blank"},
    {"name":"January 09", "href":"http://archive.constantcontact.com/fs090/1101844292916/archive/1102415796344.html' target='_blank"},
    {"name":"Archives", "href":"/news-letters/archives' target='_blank"}
  ]}
]}

dojo.declare("ddmenu", null, {
    getMenu: function() {
        if (typeof(ddmenu_data) == "undefined") {
            dojo.xhrGet({
                url: "menu.json",
                load: dojo.hitch(this, this.renderMenu),
                error: function(response, ioArgs) {
                    console.log("ddmenu error:" + response)
                },
                handleAs: "json"
            })
        } else {
            this.renderMenu(ddmenu_data)
        }
    },

    renderMenu: function(response, ioArgs){
        console.log(response)
        this.response = response
        for (var x = 0; x < response.items.length; x++) {
            var item = response.items[x]
            var pmenu = dojo.byId(item.id)
            if (!pmenu) { continue }

            // Create the html
            var out = "<ul>"
            out = out + this.renderItems(item.items, 10)
            out = out + "<li class='menulastitem'></li>"
            out = out + "</ul>"

            pmenu.innerHTML = pmenu.innerHTML + out
        }
    },

    renderItems: function(items, depth) {
        var out = ""
        for (var x = 0; x < items.length; x++) {
            var item = items[x]
            var cls = (depth >= 20?'menuitemsmall':'')
            out = out + "<li><a href='" + (item.href?this.response.root + item.href:"#") + "' class='" + cls + "' style='padding-left:" + depth + "px'>" + item.name + "</a></li>"
            if (item.items) {
                out = out + this.renderItems(item.items, depth + 10)
            }
        }

        return out

    }

})

dojo.addOnLoad(function() {
    var ddm = new ddmenu()
    ddm.getMenu()
})
