function addTs(h,ts,varargin)

%% Is the time series already there?
% if isequal(h.Timeseries1,ts) || isequal(h.Timeseries2,ts)
%     return
% end

%% Add the new time series
%% Case 1: No time series yet added
if isempty(h.Timeseries1) && isempty(h.Timeseries2)
    h.Timeseries1 = ts;
    h.Timeseries2 = ts;
    % If necessary build the @corrplot
    if isempty(h.Plot)
        viewpanel = tsguis.uitspanel(h.Figure,'Time series correlation');
        h.Plot = tsguis.corrplot(viewpanel,...
            h.Timeseries1.getContainer('Data').SampleSize(1),...
            h.Timeseries2.getContainer('Data').SampleSize(1));
        h.Plot.Parent = h; %  Install parent
        propedit(h.Plot.AxesGrid.Parent);
        h.setDropAdaptor(h.DropAdaptor);
    end
    %% Add the time series
    h.Plot.addTs(h.Timeseries1,h.Timeseries2);
%% Case 2: Two timeseries already there - ask which one to replace
elseif ~isempty(h.Timeseries1) && ~isempty(h.Timeseries2)
    if h.Timeseries1~=ts && h.Timeseries2~=ts
        if isempty(varargin)
            if h.Timeseries1~=h.Timeseries2
                ButtonName = questdlg('Replace which Time Series object?', ...
                           'Time Series Tools', ...
                           ['' h.Timeseries1.Name '' ' '],['' h.Timeseries2.Name '' '  '],'Cancel','Cancel');
                switch ButtonName,
                    case ['' h.Timeseries1.Name '' ' '], 
                        h.Timeseries1 = ts;
                    case ['' h.Timeseries2.Name '' '  '],
                        h.Timeseries2 = ts;
                    case 'Cancel',
                        return
                end 
                h.Plot.addTs(h.Timeseries1,h.Timeseries2);
            else
                h.Timeseries1 = ts;
                h.Plot.addTs(h.Timeseries1,h.Timeseries2);
            end
        else
           if  strcmp(varargin,'x')
               h.Timeseries1 = ts;
           else
               h.Timeseries2 = ts;
           end
           h.Plot.addTs(h.Timeseries1,h.Timeseries2);
        end
    else
        if isempty(varargin)
            return
        else
            if strcmp(varargin,'x')
                h.Timeseries1 = ts;
            else
                h.Timeseries2 = ts;
            end
            h.Plot.addTs(h.Timeseries1,h.Timeseries2);
        end
    end
%% Case 3: Put the time series in the missing spot and show
else
   if isempty(h.Timeseries1)
       h.Timeseries1 = ts;
   else
       h.Timeseries2 = ts;
   end
   %% Add the time series
   h.Plot.addTs(h.Timeseries1,h.Timeseries2);
end
% Hide status text
set(h.Handles.InitTXT,'Visible','off')
%% Fire tschanged event to announce the change
h.send('tschanged',handle.EventData(h,'tschange'));
%% Refresh
h.Plot.Visible = 'on';
 