YAHOO.util.Event.onContentReady("productsandservices", function () {

    /*
		Instantiate a MenuBar:  The first argument passed to the constructor
		is the id for the Menu element to be created, the second is an 
		object literal of configuration properties.
    */

    var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", { 
                                                autosubmenudisplay: true, 
                                                hidedelay: 750, 
                                                lazyload: true });
    /*
         Define an array of object literals, each containing 
         the data necessary to create a submenu.
    */

    var aSubmenuData = [
        {
            id: "mIntro", 
            itemdata: [ 
                { text: "Getting Started", url: "/intro/index.html" },
                { text: "Skates", url: "/intro/skates.html" },
                { text: "Equipment", url: "/intro/equipment.html" },
                { text: "Terms", url: "/glossary.html" },
                { text: "Rinks", url: "/rinks/rinkSearch.html" }
            ]
        },
        
        {
            id: "mTraining", 
            itemdata: [
                { text: "Group Lessons", url: "/training/group.html" },
                { text: "Private Instruction", url: "/training/private.html" },
                { text: "Selecting a Coach", url: "/training/coaches.html" },
                { text: "Practice Sessions", url: "/training/practice.html" },
                { text: "Off Ice Training", url: "/training/office.html" }
            ] 
        },
        
        {
            id: "mSkills", 
            itemdata: [ 
                { text: "Intro", url: "/skills/index.html" },
                {
                    text: "Basics", 
                    submenu: { 
						id: "mBasics", 
						itemdata: [
							{ text: "Edges", url: "/basics/edges.html" },
							{ text: "Gliding", url: "/basics/gliding.html" },
							{ text: "Posture",  url: "/basics/posture.html" },
							{ text: "Stopping", url: "/basics/stopping.html" },
							{ text: "Stroking", url: "/basics/stroking.html" },
							{ text: "Crossovers", url: "/basics/crossovers.html" },
							{ text: "Swizzles", url: "/basics/stroking.html" }
						] 
					}
                }, 
                {
                    text: "Turns", 
                    submenu: { 
						id: "mTurns", 
						itemdata: [
							{ text: "3-turn", url: "/skills/turns/3turn.html" },
							{ text: "Bracket", url: "/skills/turns/bracket.html" },
							{ text: "Counter",  url: "/skills/turns/counter.html" },
							{ text: "Mohawk", url: "/skills/turns/mohawk.html" },
							{ text: "Rocker", url: "/skills/turns/rocker.html" },
							{ text: "Choctaw", url: "/skills/turns/choctaw.html" },
							{ text: "Twizzles", url: "/skills/turns/twizzles.html" }
						] 
					}
                }, 
                { text: "Steps", url: "http://promo.yahoo.com/broadband" },
                {
                    text: "Spins", 
                    submenu: { 
						id: "mSpins", 
						itemdata: [
							{ text: "Intro", url: "/skills/spins/intro.html" },
							{ text: "Scratch Spin", url: "/skills/spins/scratchSpin.html" },
							{ text: "Back Spin",  url: "/skills/spins/backSpin.html" },
							{ text: "Sit Spin", url: "/skills/spins/sitSpin.html" },
							{ text: "Camel Spin", url: "/skills/spins/camelSpin.html" },
							{ text: "Layback Spin", url: "/skills/spins/laybackSpin.html" },
							{ text: "Biellmann Spin", url: "/skills/spins/BielmanSpin.html" },
							{ text: "Doughnut Spin", url: "/skills/spins/DoughnutSpin.html" },
							{ text: "Flying Sit Spin", url: "/skills/spins/flyingSitSpin.html" },
							{ text: "Flying Camel Spin", url: "/skills/spins/flyingCamel.html" },
							{ text: "Competing", url: "/skills/spins/compete.html" }
						] 
					}
                
                }, 
                {
                    text: "Jumps", 
                    submenu: { 
						id: "mJumps", 
						itemdata: [
							{ text: "Intro", url: "/skills/jumps/intro.html" },
							{ text: "Waltz Jump", url: "/skills/jumps/waltz.html" },
							{ text: "Loop Jump",  url: "/skills/jumps/loopjump.html" },
							{ text: "Salchow", url: "/skills/jumps/salchowjump.html" },
							{ text: "Axel Jump", url: "/skills/jumps/axeljump.html" },
							{ text: "Toe Loop", url: "/skills/jumps/toeloopjump.html" },
							{ text: "Flip Jump", url: "/skills/jumps/flipjump.html" },
							{ text: "Lutz Jump", url: "/skills/jumps/lutzjump.html" },
							{ text: "Split Jump", url: "/skills/jumps/splitjump.html" },
							{ text: "Stag Jump", url: "/skills/jumps/stagjump.html" },
							{ text: "Competing", url: "/skills/jumps/compete.html" }
						] 
					}
                
                }, 
                {
                    text: "Spirals", 
                    submenu: { 
						id: "mSpirals", 
						itemdata: [
							{ text: "Intro", url: "/skills/spirals/spirals.html" },
							{ text: "Arabesque ", url: "/skills/spirals/arabesque.html" },
							{ text: "Catch Foot",  url: "/skills/spirals/catchfootspiral.html" },
							{ text: "Biellmann", url: "/skills/spirals/biellmann.html" },
							{ text: "Cross Grab", url: "/skills/spirals/crossgrab.html" },
							{ text: "Charlotte", url: "/skills/spirals/charlotte.html" },
							{ text: "Fan Spiral", url: "/skills/spirals/fan.html" },
							{ text: "Kerrigan Spiral", url: "/skills/spirals/kerrigan.html" },
							{ text: "Inverted Spiral", url: "/skills/spirals/inverted.html" },
							{ text: "Spread Eagle", url: "/skills/spirals/spreadeagle.html" },
							{ text: "Patterns", url: "/skills/spirals/spirals.html" }
						] 
					}
                }, 
                { text: "Moves", url: "/skills/mif.html" }
            ]
        },
        
        {
            id: "mTests", 
            itemdata: [
                { text: "Intro", url: "/tests/index.html" },
                {
                    text: "Basic Skills", 
                    submenu: { 
						id: "mBasicSkills", 
						itemdata: [
							{ text: "Basic 1", url: "/tests/BS/tone.html" },
							{ text: "Basic 2", url: "/tests/BS/two.html" },
							{ text: "Basic 3",  url: "/tests/BS/three.html" },
							{ text: "Basic 4", url: "/tests/BS/four.html" },
							{ text: "Basic 5", url: "/tests/BS/five.html" },
							{ text: "Basic 6", url: "/tests/BS/six.html" },
							{ text: "Basic 7", url: "/tests/BS/seven.html" },
							{ text: "Basic 8", url: "/tests/BS/eight.html" }
						] 
					}
                }, 
                {
                    text: "Moves", 
                    submenu: { 
						id: "mMovesTests", 
						itemdata: [
							{ text: "Intro", url: "/tests/MV/intro.html" },
							{ text: "Pre-Preliminary", url: "/tests/MV/prepre.html" },
							{ text: "Preliminary",  url: "/tests/MV/preliminary.html" },
							{ text: "Pre-Juvenile", url: "/tests/MV/prejuve.html" },
							{ text: "Juvenile", url: "/tests/MV/juve.html" },
							{ text: "Intermediate", url: "/tests/MV/intermediate.html" },
							{ text: "Noveice", url: "/tests/MV/novice.html" },
							{ text: "Junior", url: "/tests/MV/junior.html" },
							{ text: "Senior", url: "/tests/MV/senior.html" }
						] 
					}
                }, 
                {
                    text: "Freestyle", 
                    submenu: { 
						id: "mFSTests", 
						itemdata: [
							{ text: "Intro", url: "/tests/FS/intro.html" },
							{ text: "Pre-Preliminary", url: "/tests/FS/prepre.html" },
							{ text: "Preliminary",  url: "/tests/FS/preliminary.html" },
							{ text: "Pre-Juvenile", url: "/tests/FS/prejuev.html" },
							{ text: "Juvenile", url: "/tests/FS/juev.html" },
							{ text: "Intermediate", url: "/tests/FS/intermediate.html" },
							{ text: "Noveice", url: "/tests/FS/novice.html" },
							{ text: "Junior", url: "/tests/FS/junior.html" },
							{ text: "Senior", url: "/tests/FS/senior.html" }
						] 
					}
                }, 
                {
                    text: "Dance", 
                    submenu: { 
						id: "mDanceTests", 
						itemdata: [
							{ text: "Intro", url: "/tests/DN/intro.html" },
							{ text: "Preliminary",  url: "/tests/DN/preliminary.html" },
							{ text: "Pre-Bronze", url: "/tests/DN/prebronze.html" },
							{ text: "Bronze", url: "/tests/DN/bronze.html" },
							{ text: "Pre-Silver", url: "/tests/DN/presilver.html" },
							{ text: "Silver", url: "/tests/DN/silver.html" },
							{ text: "Pre-Gold", url: "/tests/DN/pregold.html" },
							{ text: "Gold", url: "/tests/DN/gold.html" }
						] 
					}
                }, 
                {
                    text: "Pairs", 
                    submenu: { 
						id: "mPairsTests", 
						itemdata: [
							{ text: "Intro", url: "/tests/PR/intro.html" },
							{ text: "Preliminary",  url: "/tests/PR/preliminary.html" },
							{ text: "Juvenile", url: "/tests/PR/juve.html" },
							{ text: "Intermediate", url: "/tests/PR/intermediate.html" },
							{ text: "Noveice", url: "/tests/PR/novice.html" },
							{ text: "Junior", url: "/tests/PR/junior.html" },
							{ text: "Senior", url: "/tests/PR/senior.html" }
						] 
					}
                } 
            ] 
        },
        {
            id: "mCompeting", 
            itemdata: [
                { text: "Intro", url: "/compete/index.html" },
                {
                    text: "Freestyle", 
                    submenu: { 
						id: "mFSComp", 
						itemdata: [
							{ text: "Intro", url: "/compete/FS/intro.html" },
							{ text: "Pre-Preliminary", url: "/compete/FS/prepre.html" },
							{ text: "Preliminary",  url: "/compete/FS/preliminary.html" },
							{ text: "Pre-Juvenile", url: "/compete/FS/prejuve.html" },
							{ text: "Juvenile", url: "/compete/FS/juev.html" },
							{ text: "Intermediate", url: "/compete/FS/intermediate.html" },
							{ text: "Noveice", url: "/compete/FS/novice.html" },
							{ text: "Junior", url: "/compete/FS/junior.html" },
							{ text: "Senior", url: "/compete/FS/senior.html" }
						] 
					}
                }, 
                { text: "Dance", url: "/compete/dance.html" },
                { text: "Pairs", url: "/compete/pairs.html" },
                { text: "Qualifying", url: "/compete/qualifying.html" },
                { text: "Scoring", url: "/compete/scoring.html" },
                { text: "Olympics", url: "/compete/olympics.html" },
                { text: "Music", url: "/compete/music.html" }              
            ] 
        }
    ];


    var ua = YAHOO.env.ua,
        oAnim;  // Animation instance

    /*
         "beforeshow" event handler for each submenu of the MenuBar
         instance, used to setup certain style properties before
         the menu is animated.
    */

    function onSubmenuBeforeShow(p_sType, p_sArgs) {

        var oBody,
            oElement,
            oShadow,
            oUL;

        if (this.parent) {
            oElement = this.element;

            oShadow = oElement.lastChild;
            oShadow.style.height = "0px";
        
            if (oAnim && oAnim.isAnimated()) {
                oAnim.stop();
                oAnim = null;
            }

            oBody = this.body;

            if (this.parent && 
                !(this.parent instanceof YAHOO.widget.MenuBarItem)) {

                if (ua.gecko || ua.opera) {
                    oBody.style.width = oBody.clientWidth + "px";
                }
                
                if (ua.ie == 7) {
                    oElement.style.width = oElement.clientWidth + "px";
                }
            }
            oBody.style.overflow = "hidden";

            oUL = oBody.getElementsByTagName("ul")[0];
            oUL.style.marginTop = ("-" + oUL.offsetHeight + "px");
        }
    }


    function onTween(p_sType, p_aArgs, p_oShadow) {

        if (this.cfg.getProperty("iframe")) {
            this.syncIframe();
        }
        if (p_oShadow) {
            p_oShadow.style.height = this.element.offsetHeight + "px";
        }
    }


    function onAnimationComplete(p_sType, p_aArgs, p_oShadow) {

        var oBody = this.body,
            oUL = oBody.getElementsByTagName("ul")[0];

        if (p_oShadow) {
            p_oShadow.style.height = this.element.offsetHeight + "px";
        }

        oUL.style.marginTop = "";
        oBody.style.overflow = "";

        if (this.parent && 
            !(this.parent instanceof YAHOO.widget.MenuBarItem)) {

            // Clear widths set by the "beforeshow" event handler

            if (ua.gecko || ua.opera) {
                oBody.style.width = "";
            }
            
            if (ua.ie == 7) {
                this.element.style.width = "";
            }
        }
    }

    function onSubmenuShow(p_sType, p_sArgs) {

        var oElement,
            oShadow,
            oUL;
    
        if (this.parent) {

            oElement = this.element;
            oShadow = oElement.lastChild;
            oUL = this.body.getElementsByTagName("ul")[0];

            oAnim = new YAHOO.util.Anim(oUL, 
                { marginTop: { to: 0 } },
                .5, YAHOO.util.Easing.easeOut);

            oAnim.onStart.subscribe(function () {
                oShadow.style.height = "100%";
            });


            oAnim.animate();

            if (YAHOO.env.ua.ie) {
                oShadow.style.height = oElement.offsetHeight + "px";
                oAnim.onTween.subscribe(onTween, oShadow, this);
            }
            oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this);
        }
    }

    oMenuBar.subscribe("beforeRender", function () {

		var nSubmenus = aSubmenuData.length, i;
        if (this.getRoot() == this) {

			for (i = 0; i < nSubmenus; i++) {
            	this.getItem(i+2).cfg.setProperty("submenu", aSubmenuData[i]);
			}
        }
    });

    oMenuBar.subscribe("beforeShow", onSubmenuBeforeShow);
    oMenuBar.subscribe("show", onSubmenuShow);
    oMenuBar.render();         

});
