var baseNameId = 0, menuImageNr=1, timerID=null, timerRunning=false, randomImage=false;
var bid=0;
var menuImageLocation = new Array();
var menuImagePre = new Image();
var myLayers = new Array();
var mylid=0;

menuImageLocation[0] = new Array("grey",1);
menuImageLocation[1] = new Array("canada",8);
menuImageLocation[2] = new Array("srilanka",10);
menuImageLocation[3] = new Array("tunisia",8);
menuImageLocation[4] = new Array("ghana",15);
menuImageLocation[5] = new Array("argentina",7);
menuImageLocation[5] = new Array("chile",9);

function getRandom(min,max)
{
   return (Math.round(Math.random()*(max-min)))+min;
}

function changeMenuImage()
{
	if (document.images)
	{
		if (menuImageNr > menuImageLocation[baseNameId][1]) menuImageNr = 1;
		if (document.images.menuImage) document.images.menuImage.src='/menu_images/' + menuImageLocation[baseNameId][0] + menuImageNr + '.jpg';

		if (true==randomImage)
		{
			baseNameId=getRandom(1,menuImageLocation.length-1);
			menuImageNr=getRandom(1,menuImageLocation[baseNameId][1]);
		}
		else
			++menuImageNr;
		if (menuImageNr > menuImageLocation[baseNameId][1]) menuImageNr = 1;
		if (document.images.menuImagePre) document.images.menuImagePre.src='/menu_images/' + menuImageLocation[baseNameId][0] + menuImageNr + '.jpg';
		timerID=setTimeout("changeMenuImage()",15000);
		timerRunning=true;
	}
}

function showMenuImage(baseImageName, specificNr)
{
	var i;
	if (timerRunning)
	{
		clearTimeout(timerID);
		timerRunning=false;
	}
	if (baseImageName)
	{
		for(i=0;(i<menuImageLocation.length) && (menuImageLocation[i][0]!=baseImageName);i++);
		if (i==menuImageLocation.length)
		{
			baseNameId=getRandom(0,menuImageLocation.length-1);
			menuImageNr=getRandom(1,menuImageLocation[baseNameId][1]);
			randomImage=true;
		} else
		{
			baseNameId=i;
			randomImage=false;
			if (specificNr) menuImageNr=specificNr;
		}
	}
	changeMenuImage();
}

function change(i,color)
{
//	if (document.layers)
//		window.document.layers['id' + i].bgColor = color;
//	else if (document.all)
//		window.document.all['id' + i].style.background = color;
  if (document.all)
  {
    window.document.all['id' + i].style.background = color;
  }
  else
  {
    var banner = xbGetElementById('id' + i);
    var bannerstyle = new xbStyle(banner);
    bannerstyle.setBackgroundColor(color);
  }
}

function button(text,link, color1, color2, width) {
	id = bid++;
//return '<table border="0" width="'+ width +'" height="18" cellpadding="0" cellspacing="0"><tr><td bgcolor="'+color1+'" valign="middle" height="18"><a class="menutree" href="'+link+'"><p align="center"><font face="Arial" color="#FFFFFF" size="2">'+text+'</font></a></td></tr></table>';
	if (document.all)
		return '<table border="0" width="'+ width +'" height="18" cellpadding="0" cellspacing="0"><tr><td style="cursor:hand" id="id' + id +'" class="relative" bgcolor="'+color1+'" valign="middle" height="18" onclick=\'location.href="'+link+'"\'  onmouseover=\'change('+id+',"'+color2+'")\' onmouseout=\'change('+id+',"'+color1+'")\'><p align="center"><font face="Arial" color="#FFFFFF" style="font-size:10pt;">'+text+'</font></td></tr></table>';
	else
        return '<DIV ID="id' + id +'" onmouseover=\'change('+id+',"'+color2+'")\' onmouseout=\'change('+id+',"'+color1+'")\' onclick=\'location.href="'+link+'"\' STYLE="position: relative; cursor:pointer; text-align:center; color: white; background-color: '+color1+'; height: 18px; font-size:10pt; font-family:Arial,Helvetica,sans-serif;">'+text+'</DIV>';
		
}


function init()
{
  var width = 145, height = 19, ind = 10;

  var bgColor = "#CCCCCC";
  l = new List(true, width, height);
  l.setIndent(0);
  l.addItem(button("Home","/","#30476D","#566C90",120));
  diar = new List(false, width, height);
    diar.setIndent(ind);
    diar.addItem(button("Buenos Aires","/buenos_aires.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Puerto Natales","/puerto_natales.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Torres del Paine","/torres_del_paine.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("To O'Higgins","/ohiggins.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Rafting","/rafting.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Impressions","/impressions.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Mendoza","/mendoza.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Pampa restaurants","/pampa_restaurant.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("La Serena","/laserena.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Talampaya","/talampaya.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Paso Jama","/paso_jama.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Laguna Verde","/lagunaverde.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Parinacota","/parinacota.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Most dangerous","/most_dangerous.shtml",'#4A4A4A','#707070',110));
    diar.addItem(button("Maldonado down","/maldonado_down.shtml",'#4A4A4A','#707070',110));
    l.addList(diar, button("Travel stories","/diary.shtml","#30476D","#566C90",120));
  photo = new List(false, width, height);
    photo.setIndent(ind);
    photo.addItem(button("S-America 1","/photobooks/southamerica1/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("S-America 2","/photobooks/southamerica2/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("S-America 3","/photobooks/southamerica3/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("S-America 4","/photobooks/southamerica4/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("S-America 5","/photobooks/southamerica5/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("S-America 6","/photobooks/southamerica6/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("S-America 7","/photobooks/southamerica7/index.shtml",'#4A4A4A','#707070',110));
    photo.addItem(button("Previous Trips","/photos.shtml#previous_trips",'#4A4A4A','#707070',110));
    l.addList(photo, button("Photos","/photos.shtml","#30476D","#566C90",120));
  stats = new List(false, width, height);
    stats.setIndent(ind);
    stats.addItem(button("Max min","/stat_maxmin.shtml",'#4A4A4A','#707070',110));
    stats.addItem(button("Bike problems","/stat_problems.shtml",'#4A4A4A','#707070',110));
    stats.addItem(button("Data","/stat_data.shtml",'#4A4A4A','#707070',110));
    l.addList(stats, button("Statistics","/statistics.shtml","#30476D","#566C90",120));
  offmap = new List(false, width, height);
    offmap.setIndent(ind);
    offmap.addItem(button("O'Higgins","/ohiggins_map.shtml",'#4A4A4A','#707070',110));
    offmap.addItem(button("Laguna Verde","/lagunaverde_map.shtml",'#4A4A4A','#707070',110));
    offmap.addItem(button("Tunupa","/tunupa_map.shtml",'#4A4A4A','#707070',110));
    offmap.addItem(button("Surire","/surire_map.shtml",'#4A4A4A','#707070',110));
    offmap.addItem(button("Mapiri","/mapiri_map.shtml",'#4A4A4A','#707070',110));
    offmap.addItem(button("Maldonado","/maldonado_map.shtml",'#4A4A4A','#707070',110));
    l.addList(offmap, button("Off the map","/offmap.shtml","#30476D","#566C90",120));
  l.addItem(button("Recipes","/recipes.shtml","#30476D","#566C90",120));
  prep = new List(false, width, height);
    prep.setIndent(ind);
    prep.addItem(button("Bike","/bike.shtml",'#4A4A4A','#707070',110));
    prep.addItem(button("Route","/route.shtml",'#4A4A4A','#707070',110));
    prep.addItem(button("Financial","/financial.shtml",'#4A4A4A','#707070',110));
    prep.addItem(button("Formalities","/formalities.shtml",'#4A4A4A','#707070',110));
    prep.addItem(button("Equipment","/package_list.shtml",'#4A4A4A','#707070',110));
    l.addList(prep, button("Preparations","/preparation.shtml","#30476D","#566C90",120));
  prev = new List(false, width, height);
    prev.setIndent(ind);
    prev.addItem(button("Sri Lanka","/sri_lanka.shtml",'#4A4A4A','#707070',110));
    prev.addItem(button("Tunisia","/tunisia.shtml",'#4A4A4A','#707070',110));
    prev.addItem(button("Canada","/canada.shtml",'#4A4A4A','#707070',110));
    prev.addItem(button("Ghana","/ghana.shtml",'#4A4A4A','#707070',110));
    prev.addItem(button("Photos","/photos.shtml#previous_trips",'#4A4A4A','#707070',110));
    l.addList(prev, button("Previous trips","/previous_trips.shtml","#30476D","#566C90",120));
  links = new List(false, width, height);
    links.setIndent(ind);
    links.addItem(button("Sites","/sites.shtml",'#4A4A4A','#707070',110));
    links.addItem(button("Books","/books.shtml",'#4A4A4A','#707070',110));
    l.addList(links, button("Links","/links.shtml","#30476D","#566C90",120));
  l.addItem(button("Notes","/notes.shtml","#30476D","#566C90",120));
  l.addItem(button("Search","search.shtml",'#4A4A4A','#707070',120));
  l.addItem(button("Contact Us","/contact_us.shtml",'#4A4A4A','#707070',120));
  l.addItem(button("Colofon","/colofon.shtml",'#4A4A4A','#707070',120));

  l.build(5,185);
}

function close_other(listid) 
{
	for(var i = 1; i < document.lists.length; i++)
		if(listid!=i && document.lists[i] && document.lists[i].visible)
		{
			document.lists[i].visible=false;
			document.lists[document.lists[i].pid].rebuild();
		}
}

function init_page()
{
	// Build menu
	init();
	// Convert menuNameId to listid
	menuNameConvert = new Array();
	menuNameConvert[0]=0; // Home
	menuNameConvert[1]=1; // Travel stories
	menuNameConvert[2]=2; // Photos
	menuNameConvert[3]=4; // Off map
	menuNameConvert[4]=5; // Preparations
	menuNameConvert[5]=6; // Previous trips
	menuNameConvert[6]=3; // Statistics
	menuNameConvert[7]=7; // Links
	listid = menuNameConvert[menuNameId];
	// Close all menu items except active one. Do nothing if 99
	if (menuNameId != 99 && document.lists) close_other(listid);	
	// Open active menu item
	if (menuNameId != 99 && listid != 0 && document.lists && document.lists[listid] && !document.lists[listid].visible) xbcl_expand(listid);
	if (baseImage) showMenuImage(baseImage);
}







