//use browser sniffing to determine if IE or Opera (ugly, but required)
/*var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true;}

//fix both IE and Opera (adjust when they implement this method properly)
if(isOpera || isIE){
  document.nativeGetElementById = document.getElementById;
  //redefine it!
  document.getElementById = function(id){
    var elem = document.nativeGetElementById(id);
    if(elem){
      //verify it is a valid match!
      if(elem.attributes['id'] && elem.attributes['id'].value == id){
        //valid match!
        return elem;
      } else {
        //not a valid match!
        //the non-standard, document.all array has keys for all name'd, and id'd elements
        //start at one, because we know the first match, is wrong!
        for(var i=1;i<document.all[id].length;i++){
          if(document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id){
            return document.all[id][i];
          }
        }
      }
    }
    return null;
  };
}*/



function hideAllButOne(id)
{
	var villages = document.getElementById('villages');
	for(i = 0; i < villages.childNodes.length; i++)
	{
		if (villages.childNodes[i].getAttribute('id').indexOf('vv_')==0)
		{
			villages.childNodes[i].style.display = 'none';
		}
	}
	var levisible = document.getElementById(id);
	levisible.style.display = 'block';
}



function goleft()
{
	villmove(-1);
}

function goright()
{
	villmove(1);
}

function villmove(modif)
{
	if (((document.leftmostID + modif) >= 0) && ((document.leftmostID + modif + 5) < document.totalVill ))
	{
		hideNShowThingies(modif);
		document.leftmostID += modif;
	}
}
function doOnce(tot)
{
	document.leftmostID = 0;
	document.totalVill = tot;
	for(var i=0; i<6; i = i+1)
	{
		var prefix = 'mv_';
		var thisonetoshow = document.getElementById(prefix+i);
		thisonetoshow.style.display = 'inline';
	}
	hideAllButOne('vv_0');
}
function hideNShowThingies(modif)
{
	if (modif > 0)
	{
		var thisonetohide = document.getElementById('mv_'+document.leftmostID);
		thisonetohide.style.display = 'none';
		var thisonetoshow = document.getElementById('mv_'+(document.leftmostID + 5));
		thisonetoshow.style.display = 'inline';
	}
	else
	{
		var thisonetohide = document.getElementById('mv_'+(document.leftmostID + 5));
		thisonetohide.style.display = 'none';
		var thisonetoshow = document.getElementById('mv_'+document.leftmostID);
		thisonetoshow.style.display = 'inline';
	}
}