$(document).ready(function() {

  path = location.pathname.split("/");

  // wrap ranges into select menu
  var sel = "<select class='span-5' name='ranges' > \n";
  $.each($("div#ranges a"), function(link_id, link) {
    sel += '  <option value="'+$(link).attr("href")+'" >'+$(link).text()+'</option> \n';
  });
  sel += "</select>\n";
  $("div#ranges").html(sel);
  
  // fetch range from url (if any) and assign to range-menu
  if (path[1]=="letter" && path[3] && path[4]) {
    $("select[name=ranges]").val(decodeURI(location.pathname));
    //$("select[name=ranges]").attr("title", $("select[name=ranges]").val() );
  }
  // set select title
  $("select[name=ranges]").attr("title", 
     $("select[name=ranges] > option[value="+$("select[name=ranges]").val()+"]").text() 
  );
  
  // bind click event on range-menu to change page
  $("select[name=ranges]").livequery("change", function() {
    location.href = $(this).val();
  });  
  
  // show other opts
  $("a#show_opt").click(function(){
  	$("a.smalllink").show();
  	$(this).hide();
	return false;
  });

  
});
