function tsLineButtonDown(eventSrc, eventData, h)

%% Switchyard for clicking on axes

%% Set the callbacks
if strcmp(h.State,'None')
    set(ancestor(h.AxesGrid.Parent,'figure'),'WindowButtonMotionFcn',@hoverfig, ...
          'WindowButtonDownFcn','',...    
          'WindowButtonUpFcn','')
    tip = linetip(eventSrc);
    return
elseif any(strcmp(h.State,{'TimeseriesScale','TimeseriesTranslate'}))
    set(ancestor(h.AxesGrid.Parent,'figure'),'WindowButtonMotionFcn',{@tsWindowButtonMotionFcn h}, ...  
          'WindowButtonUpFcn',{@tsWindowButtonUpFcn h},...
          'KeyPressFcn',{@tsKeyPressFcn h})
else % Other states are handled by tsWindowButtonDown
    return
end


%% Figure must be interuptable for the release to update
%% the current point
set(h.AxesGrid.Parent,'Interruptible','on')

%% Turn off limit management so that the axestable/tstables on the 
%% viewnode panel do not try to update during a selection
%% TO DO: could come in off already
h.AxesGrid.LimitManager = 'off';

switch h.State
    % Timeseries selected for scaling/translation    
    case {'TimeseriesScale','TimeseriesTranslate'}
        %% Set the line select callback for the selected wave
        for k=1:length(h.Waves)
            if any(eventSrc == h.Waves(k).View.Curves)
                set(h.Waves(k).View.Curves,'Selected','on',...
                    'markerFaceColor','r');
                h.SelectionStruct.Selectedwave = h.Waves(k);
            end
        end

        %% Set into the wave resizing/moving state
        if strcmp(h.State,'TimeseriesScale')
            h.State = 'TimeseriesScaling';
            % Record the start position
            pt = get(gca,'CurrentPoint');
            h.SelectionStruct.StartPoint = pt(1,2);
            % Record the centroid which will be preserved under rescaling
            h.SelectionStruct.Centroid = ...
               tsnanmean(tsnanmean(h.SelectionStruct.Selectedwave.Data.Amplitude));  

        elseif strcmp(h.State,'TimeseriesTranslate')
            h.State = 'TimeseriesTranslating';
            % Record the start position
            pt = get(gca,'CurrentPoint');
            xdata = get(h.SelectionStruct.Selectedwave.View.Curves(1),'Xdata');
            [junk,ind] = min(abs(xdata-pt(1,1)));
            h.SelectionStruct.StartPoint = ind(1);
        end
        
        %% Cache limit modes
        h.SelectionStruct.YLimMode = h.Axesgrid.YLimMode;
        h.SelectionStruct.XLimMode = h.Axesgrid.XLimMode;
        
        %% Arrowpressed status must be false to allow mouse translation
        h.SelectionStruct.Arrowpressed = false;

        %% Customize the cursor
        set(ancestor(h.AxesGrid.Parent,'Figure'),'Pointer','fleur')
        
        %% Set the watermark
        h.SelectionStruct.Selectedwave.Data.setwatermark;
        
        set(h.Axesgrid,'XLimMode',{'Manual'},...
            'YLimMode',repmat({'Manual'},[h.Axesgrid.size(1) 1]))
        figure(double(ancestor(h.Axesgrid.Parent,'Figure')))
end