/*
 * menu.js
 * used to add the ajax menu control to the project. Requires jquery.js
 * JQuery version for this project 1.3.2
 */

$(function() {
    // hide drop down menus
    $("#menu-list li ul").hide();

    // toggle the display of drop down menus
    $("#menu-list li h3 a").click(function() {
        $(this.hash).toggle(500);
        return false;
    });

    // Take all the <a> tags that are in the #menu-list ul
    // that also have a class of clickable and listen for a click
    // 1. Hide the main div (where cahnges will be made)
    // 2. Check the id of the <a> tag clicked and load the info from tpl file
    // 3. Show the main div
    // 4. "return false;" stops the browser from going to the link in the <a> tags href
    $("#menu-list a.clickable").click(function(){
        $("#bd").hide("slide", {
            direction: "right"
        }, 250);

        if ($(this).attr("id") == "home") {                      // home clicked
            $("#main").load("./tpl/home.tpl", showinfo);
        }
        else if ($(this).attr("id") == "ss") {                   // sunday school clicked
            $("#main").load("./tpl/sundayschool.tpl", showinfo);
        }
        else if ($(this).attr("id") == "cw") {                   // children's worship clicked
            $("#main").load("./tpl/cw.tpl", showinfo);
        }
        else if ($(this).attr("id") == "es") {                   // extended session clicked
            $("#main").load("./tpl/es.tpl", showinfo);
        }
        else if ($(this).attr("id") == "me") {                   // Mission Explorers clicked
            $("#main").load("./tpl/me.tpl", showinfo);
        }
        else if ($(this).attr("id") == "cc") {                   // children choir clicked
            $("#main").load("./tpl/choir.tpl", showinfo);
        }
        else if ($(this).attr("id") == "cec") {                   // cec info clicked
            $("#main").load("./tpl/cec.tpl", showinfo);
        }
        else if ($(this).attr("id") == "cec-con") {                   // cec info clicked
            $("#main").load("./tpl/cec-contact.tpl", showinfo);
        }
        else if ($(this).attr("id") == "cal") {                   // calendar clicked
            if ($.browser.msie) {                                 // workaround for iframe/hidden div problem in IE
                $("#bd").show(100, function(){
                    $("#main").load("./tpl/calendar.tpl");
                });
            }
            else {
              $("#main").load("./tpl/calendar.tpl", showinfo);
            }
        }
        else if ($(this).attr("id") == "cm-con") {                   // children ministry contact clicked
            $("#main").load("./tpl/ccm-contact.tpl", showinfo);
        }

        //$("#main").slideDown(500);
        return false;
    });

    function showinfo() {
        $("#bd").show("slide", {
            direction: "right"
        }, 1000);
    }

});

