track5 = ""
function main()

	reaper.Undo_BeginBlock() -- Begining of the undo block. Leave it at the top of your main function.
	
	count_sel_items = reaper.CountSelectedMediaItems(0)
	if count_sel_items  == nil then return end	
	for i = 1, count_sel_items do
	
		item = reaper.GetSelectedMediaItem(0, count_sel_items - i)
	
		track = reaper.GetMediaItem_Track(item)

		item_id = reaper.GetMediaItemInfo_Value(item, "IP_ITEMNUMBER")
		
		next_item = reaper.GetTrackMediaItem(track, item_id + 1)

		if next_item ~= nil then
		
			item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
			item_length = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
			
			next_item_pos = reaper.GetMediaItemInfo_Value(next_item, "D_POSITION")
						item_length2 = reaper.GetMediaItemInfo_Value(next_item,  "D_LENGTH")
long =item_length2- item_length
			reaper.SetMediaItemInfo_Value(item, "D_POSITION", next_item_pos+ long )
						reaper.SetMediaItemInfo_Value(		next_item, "D_POSITION", 			item_pos)
		end
		
	end
	reaper.Undo_EndBlock("nudge item to right", -1) -- End of the undo block. Leave it at the bottom of your main function.	


end

reaper.PreventUIRefresh(1)

main() -- Execute your main function

reaper.UpdateArrange() -- Update the arrangement (often needed)

reaper.PreventUIRefresh(-1)
