function overlay_temporallyoffset_pscs(scaler,secondscaler,samplerange,samplestep,numberreps,recorded_noise,splitsiterequirements,find_unique_segments,breakpoints_mustbe_consecutive,max_segments)
%description: called to combine waveforms in recombined noise at known intervals, average these, and plot the results
%call as overlay_temporallyoffset_pscs(1.5031,1.5031,20,2,100,noise20070319T125639trial16,[3 3 3 3],1,0,0); 

close
tic
time_vector=1:100;
seed_vals=[14.16371820548567  11.31185487577630  19.35826590564763 0 0]; %the standard template
template=monoexprisedecay_template_generator(seed_vals,time_vector);
templatelength=length(template);
first_waveform=template*scaler;
second_waveform=template*secondscaler;

minimal_noise_length=2000; %in samples, the minimal noise allowed 
start_point=1000;


[below0segs,above0segs]=noise_segmenter(recorded_noise,splitsiterequirements,find_unique_segments,breakpoints_mustbe_consecutive)

overall_array=nan(samplerange/samplestep,50+samplerange+templatelength);

for i=0:samplestep:samplerange
    eventsatthisinterval=[];
    for j=1:numberreps
       noiz=noise_recombinase(below0segs,above0segs,recorded_noise,max_segments);
       if length(noiz)>minimal_noise_length
           padded_event=zeros(1,length(noiz));
           padded_event(start_point:(start_point+templatelength-1))=first_waveform;
           
           second_start_point=start_point+i;
           padded_event(second_start_point:(second_start_point+templatelength-1))=padded_event(second_start_point:(second_start_point+templatelength-1))+second_waveform;
           
           event_in_noiz=padded_event+noiz;
       else error('noise too short')
       end
       
       eventsatthisinterval=[eventsatthisinterval;-1*event_in_noiz(start_point-49:start_point+samplerange+templatelength)];
    end
    overall_array(i/samplestep+1,:)=(mean(eventsatthisinterval));
end

w=waterfall(flipud(overall_array));
set(w,'edgecolor','k')

axis off
box off
set(gcf,'position',[100 10 1100 550])
view(-17.5,20)  %view(17.5,20) to show falling phase

% figure
% hold on
% clr=colormap(hsv(size(overall_array,2)));
% for k=1:size(overall_array,1)
%     plot(overall_array(k,:),'color','k','linewidth',.5)
% end
    
toc