Difficult DOM manipulation problem

Difficult DOM manipulation problem

I cant seem to get my head around this :S

I have the following code from the pagination of a Gallery Module:

<ul class="pagination" style="">
      <li>Start</li>
      <li>Previous</li>
      <li>1</li>
      <li><strong><a title="2" href="blablabla">2</a></strong></li>
      <li><strong><a title="3" href="balbalbla">3</a></strong></li>
      <li><strong><a title="Next" href="balbalbalba">Weiter</a></strong></li>
      <li><strong><a title="End" href="balbalbal">End</a></strong></li>
</ul>

This is what appears on the first page. I just want to display the links previous and next, and the rest make it disappear. But the number of pages might change. How could I do it?