function [ax] = findaxes(hZoom)
%FINDAXES Find axes under the current mouse position

% Copyright 2002-2004 The MathWorks, Inc.

ax = [];
b = [];
hFigure = get(hZoom,'FigureHandle');

if ~ishandle(hFigure)
    return;
end

allHit = hittest(hFigure,'axes');
allAxes = findobj(allHit,'flat','Type','Axes','HandleVisibility','on');

% Loop through child order and get first axes is zoomable
for i=1:length(allAxes),
   candidate_ax=allAxes(i);
   
   b = hggetbehavior(candidate_ax,'Zoom','-peek');
   if ~isempty(b) && ishandle(b) && ~get(b,'Enable')
       ; % ignore this axes
       
   % 'NonDataObject' is a legacy flag 
   elseif ~isappdata(candidate_ax,'NonDataObject')
       ax = candidate_ax;
       break;
   end
end

% If we found an axes to zoom on, check behavior object to 
% see if it has any peer targets
%if ~isempty(ax) && ishandle(ax) && ~isempty(b) && ishandle(b)
%   ax = [ax,get(b,'AxesPeerTarget')];
%   ax = unique(ax);  % Remove duplicates
%end

