DiagramPaneCtxMenuCallback = function(oContextMenu,  itemIndex, inputname) {
    
    this.itemIndex = itemIndex;
    this.name = inputname;
    this.oContextMenu = oContextMenu;
    this.menuItemClickedEvent = new YAHOO.util.CustomEvent(
        "MenuItemClickedEvent", this);
    this.customevents = {
        onSuccess : function(eventType, args) {
            var t = this;
            //var menuItemsList = eval('(' + args[0].responseText + ')');
            var menuItemsList = getJsonFromRawText( args[0].responseText);
            var submenu = document
            .getElementById(t.name + "submenu");
    //        submenu.show();
	    document.getElementById(t.name + "submenu").style.visibility = "visible";
            var itemsubmenu = t.oContextMenu
            .getItem(t.itemIndex)._oSubmenu;
            if(t.name == "otherpathways"){

            if(menuItemsList.top_pathways.length > 0){
            t.oContextMenu
					.getItem(t.itemIndex).cfg
					.setProperty(
							"disabled",
							false);
                            t.oContextMenu
					.getItem(t.itemIndex).cfg
					.setProperty(
							"text",
							"Other Pathways");
            }else {
                            t.oContextMenu
					.getItem(t.itemIndex).cfg
					.setProperty(
							"text",
							"No Other Pathways");

            }
        
            for(var pathwayI=0; pathwayI<menuItemsList.top_pathways.length; pathwayI++){
                var currentItem = itemsubmenu
                .addItem( {
                    text : menuItemsList.top_pathways[pathwayI].displayname
                });
                currentItem.cfg
                .addProperty(
                    "dbid",
                    {
                        value : menuItemsList.top_pathways[pathwayI].dbid
                    });
                currentItem.cfg
                .addProperty(
                    "nodedbid",
                    {
                        value : menuItemsList.top_pathways[pathwayI].nodedbid
                    });
                currentItem.cfg
                .addProperty(
                    "title",
                    {
                        value : menuItemsList.top_pathways[pathwayI].displayname
                    });
                // The source attribute used by listeners to determing which sub menu
                // generated the event (Other Pathway, Participating Mols etc)
                currentItem.cfg
                .addProperty(
                    "source",
                    {
                        value : "otherpathways"
                    
                    });
             
                    
            }
            } else if(t.name == "participatingmols"){
            	//console.log("received response for participating molecules");
            	//var o = eval('(' + args[0].responseText + ')');
            	var o = getJsonFromRawText(args[0].responseText);
				var components = menuItemsList.clxs.cpts;
				if(components.length){
				for ( var nodeitem = 0; nodeitem < components.length; nodeitem++) {
					 var currentItem = itemsubmenu
		                .addItem( {
		                    text : components[nodeitem].name
		                });
					    currentItem.cfg.title = "vlah";
		                currentItem.cfg
		                .addProperty(
		                    "dbid",
		                    {
		                        value : components[nodeitem].dbid
		                    });
		                currentItem.cfg
		                .addProperty("source",		                    
		                        {value : "participatingmols"
		                    });
				}
				}else{
					// If only one component found components will not be 
					// set as an array with one element but will point to the
					// element itself.
					 var currentItem = itemsubmenu
		                .addItem( {
		                    text : components.name
		                });
		                currentItem.cfg
		                .addProperty(
		                    "dbid",
		                    {
		                        value : components.dbid
		                    });
		                currentItem.cfg
		                .addProperty("source",		                    
		                        {value : "participatingmols"
		                    });
				}
            	
            }
            itemsubmenu
            .subscribe(
                "click",
                function(
                    p_sType,
                    p_aArgs) {
                    oMenuItem = p_aArgs[1];
                    if (oMenuItem) {
                    	var source = oMenuItem.cfg.getProperty("source");
                    	if(source == "participatingmols"){
                    	t.menuItemClickedEvent.fire(oMenuItem.cfg.getProperty("dbid")
                    					, source);	
                    	}else{ // Other pathways
                        t.menuItemClickedEvent.fire(
                        		oMenuItem.cfg.getProperty("dbid"), 
                        		oMenuItem.cfg.getProperty("nodedbid"), 
                        		source, 
                        		oMenuItem.cfg.getProperty("title")
                            );
                    	}
                    }
                });

            t.oContextMenu
            .render();
            t.oContextMenu
            .show();


        }.bind(this),
        onFailure : function(
            eventType, args) {
         //  console.log("Failed");
        }
    };
    this.customevents.onSuccess.bind(this);
};

