faders = new Array ();

function imgfade (who, level) {
  img = document.getElementById (who + '_f');
  img.style.opacity = level / 10.0;
  img.style.filter = 'alpha(opacity=' + (level * 10) + ')';
  nlev = level - 1;
  if (level > 0) {
    try {
      var tt = faders[who];
      if (tt != null) {
        clearTimeout (tt);
        faders[who] = null;
      }
    } catch (e) {}
    faders[who] = setTimeout ("imgfade('" + who + "', " + nlev + " )", 100);
  }
  else {
    imgb = document.getElementById (who + '_b');
    attr = imgb.attributes;
    for (var attri=0; attri < attr.length; attri++) {
      if (attr[attri].name == 'src') {
        var url = attr[attri].value;
        break;
      }
    }
    imgf = document.getElementById (who + '_f');
    attr = imgf.attributes;
    for (var attri=0; attri < attr.length; attri++) {
      if (attr[attri].name == 'src') {
        attr[attri].value = url;
        break;
      }
    }
    imgf.style.opacity = 1.0;
    img.style.filter = 'alpha(opacity=100)';
  }
}

function imgswitch (who, n) {
  img = document.getElementById (who + '_b');
  attr = img.attributes;
  for (var attri=0; attri < attr.length; attri++) {
    if (attr[attri].name == 'src') {
      var url = attr[attri].value;
      break;
    }
  }
  aft = url.substring (url.length -4);
  bef = url.substring (0, url.length -4);
  num = bef;
  bef = bef.replace (/\d+$/, '');
  num = num.substring (bef.length);
  num = (num * 1) + n;
  if (num < 0) { num = 0; }
  attr[attri].value = bef + num + aft;
  try {
    var tt = faders[who];
    if (tt != null) {
      clearTimeout (tt);
      faders[who] = null;
    }
  } catch (e) {}
  faders[who] = setTimeout ("imgfade('" + who + "', 8)", 100);
  return num;
}

function imgnext (who) {
  imgswitch (who, 1);

  prevel = document.getElementById (who + '_prev');
  nextel = document.getElementById (who + '_next');
  prevel.style.visibility = 'visible';
  req = getrequest ();
  req.onreadystatechange = function () {
    if (req.readyState == 4) {
      if (req.status != 200) {
        nextel.style.visibility = 'hidden';
      } else {
        nextel.style.visibility = 'visible';
      }
    }
  }
  req.open ('HEAD', bef + (num+1) + aft, true);
  req.send (null);
}

function imgprev (who) {
  num = imgswitch (who, -1);

  prevel = document.getElementById (who + '_prev');
  nextel = document.getElementById (who + '_next');
  nextel.style.visibility = 'visible';
  if (num == 0) {
    prevel.style.visibility = 'hidden';
  } else {
    prevel.style.visibility = 'visible';
  }
}

function getrequest () {
  var req = false;
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest ();
  }
  else if (window.ActiveXObject) {
    try {
      req = new ActiveXObject ('Msxml2.XMLHTTP');
    } catch (e) {
      req = new ActiveXObject ('Microsoft.XMLHTTP');
    }
  }
  return req;
}

function mapit () {
  tfrom = document.mapit.travel_from;
  tto = document.mapit.travel_to;
  var locs = new Array();
  locs['cmi'] = 'CMI+-+University+Of+Illinois-Willard+Airport';
  locs['bmi'] = 'BMI+-+Central+Il+Regl+Arpt+At+Bloomington-Normal+Airport';
  locs['ord'] = 'ORD';
  locs['mdw'] = 'MDW+-+Chicago+Midway+Intl+Airport';
  locs['ind'] = 'IND';
  locs['stl'] = 'STL';
  locs['house'] = '701+S+State+St,+Champaign,+IL+61820';
  locs['park'] = '400+W+University+Ave,+Champaign,+IL';
  locs['arboretum'] = '1800+S+Lincoln,+Urbana+IL';
  locs['regent'] = '1406+Regency+Dr+W,+Savoy,+IL+61874';
  locs['hilton'] = '1501+S.+Neil+Street,+Champaign,+IL';
  locs['homewood'] = '1501+S.+Neil+Street,+Champaign,+IL';
  locs['hawthorn'] = '101+Trade+Center+Drive,+Champaign,+IL';
  locs['bestwestern'] = '709+N.+Dunlap+Avenue,+Savoy,+IL';
  fromloc = locs[tfrom.value];
  toloc = locs[tto.value];
  if (pagelang == 'de') {
    var url = 'http://maps.google.de';
  } else {
    var url = 'http://maps.google.com';
  }
  url += '/maps?saddr=' + fromloc + '&daddr=' + toloc;
  window.location = url;
}
