You need a bit more checking and 2 loops but this should basically give you what you need:
<?php
$month = ltrim("{segment_3}", 0); // trim leading 0
$year = "{segment_2}";
$base_url = "http://www.retinadance.com/index.php/calendar/"; // for convenience sake, add your own url here
$the_months = array("","january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"); //names of the months, first empty element takes care of the 0 counter
?>
<ul>
<?php
$month=$month-3;
switch ($month) {
case '-2':
$month=10;
$year--;
break;
case '-1':
$month=11;
$year--;
break;
case '0':
$month=12;
$year--;
break;
}
for ($i=0; $i < 3 ; $i++) {
if ($month<10) {
echo "<li><a >"."$the_months[$month]"."</a></li>";
} else {
echo "<li><a >"."$the_months[$month]"."</a></li>";
}
$month++;
if ($month > 12) {
$month=1;
$year++;
};
}
$month = ltrim("{segment_3}", 0);
for ($i=0; $i < 4 ; $i++) {
if ($month<10) {
echo "<li><a >"."$the_months[$month]"."</a></li>";
} else {
echo "<li><a >"."$the_months[$month]"."</a></li>";
}
$month++;
if ($month > 12) {
$month=1;
$year++;
};
}
?>
</ul>