// JavaScript Document

YAHOO.example.init = function () {
    // Called when a menu choice is clicked
    function onMenuItemClick(p_sType, p_aArgs, p_oItem) {
        // The text of the choice
        var bird = p_oItem.cfg.getProperty('text');
        // Testing the choice text        
        if (bird == "Show White")
        {
			/*Give me all the DIVs that have an 
    attribute 'class' with the value 'whiteSpace'*/
"//div[@class='whiteSpace']"
         var allWhite = document.evaluate("//div[@class='whiteSpace']", 
     document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
                    
for (var i = 0; i < allWhite.snapshotLength; i++)
 {
   allWhite.snapshotItem(i).style.backgroundColor = "red";
 }
           
        }
        else
        {
         "//div[@class='whiteSpace']"
		 var allWhite = document.evaluate("//div[@class='whiteSpace']",
		document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
		 for (var i = 0; i < allWhite.snapshotLength; i++)
		 {
			 allWhite.snapshotItem(i).style.backgroundColor = "white";
		 }
        }                               
    }
    
    // You could change the text of the menu choices here
    var aMenuButton4Menu = [
        // Both choices trigger onMenuItemClick
        { text: "Show White", value: 1, onclick: { fn: onMenuItemClick } },
        { text: "Reset", value: 2, onclick: { fn: onMenuItemClick } },
    ];
    // Creating the button  
    var oMenuButton4 = new YAHOO.widget.Button({ type: "menu", 
        // I modified the spacing of the button label        
        label: "Birds      ", 
        name: "mymenubutton", menu: aMenuButton4Menu, 
        container: "menubuttonsfromjavascript" });            
    
    // The engine that creates the button
    YAHOO.util.Event.onContentReady("menubuttonsfromjavascript", function () {                      
        var oOverlay = new YAHOO.widget.Overlay("menubutton4menu", { visible: false });        
        oMenuButton4.appendTo(this);
        oOverlay.render(this);    
    });
} ();

