prev / next nav codes to be more efficient and flexible
<p>I have working codes that sets the Prev and Next URL based on the available pages numbers and the URL you are currently on.</p>

<p>My codes are way too long and not flexible at all. How can I make it more flexible and production ready?</p>

<p><a href="http://jsfiddle.net/sunflowersh/ppDL7/5/" rel="nofollow">http://jsfiddle.net/sunflowersh/ppDL7/5/</a> </p>

<pre><code>var currentindex = '4'; //updated based on the current index data 

var indexNum = parseInt(currentindex);
var currentURL  =      document.location.href.substring(document.location.href.lastIndexOf("/")+1, document.location.href.length);

var baseURL ="/en_US/";

var leftURL = "";
var rightURL = "";

switch(indexNum)
{
case 2: 
// if there are only index, index1, and index2

if((currentURL.indexOf("index.html")&gt;-1)||(currentURL.indexOf("index.")&gt;-1)){
 leftURL= baseURL + "index" + parseInt(indexNum+1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum+1) + ".html";
 } else {
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum+1) + ".html";
 }
break;
case 3:

// if on index3.html or index.html
// make the right arrow URL go back to index1.html

if((currentURL.indexOf("index3.html")&gt;-1)||(currentURL.indexOf("index.")&gt;-1)){
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum-2) + ".html";
 } else {
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum+1) + ".html";
 }
 break;
case 4:
if((currentURL.indexOf("index4.html")&gt;-1)||(currentURL.indexOf("index.")&gt;-1)){
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum-3) + ".html";
 } else {
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum+1) + ".html";
  }
 break;
 case 5:
 if((currentURL.indexOf("index5.html")&gt;-1)||(currentURL.indexOf("index.")&gt;-1)){
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum-3) + ".html";
 } else {
 leftURL= baseURL + "index" + parseInt(indexNum-1) + ".html";
 rightURL= baseURL + "index" + parseInt(indexNum+1) + ".html";
 }
 break;
 default:
 // if no current index, disable the link
 leftURL= baseURL + "#";
 rightURL= baseURL + "#";

 }

 var leftArrow =$(".leftArrow").find("a").attr("href",leftURL);
 var rightArrow =$(".rightArrow").find("a").attr("href",rightURL);
</code></pre>
