var debug = 0;

function Attraction(title, url) { // class constructor
  this.title = title;
  this.url = url;
}

function BandedImage(img, links) { // class constructor
  this.img_path = img;
  this.links = links;
}

function update_mouse_pos(e, mouse_over, stripes, img_width, offset_pos) {
  var mouse_pos = getMouseXY(e);
  if (!mouse_pos) { return; }
  var where = mouse_pos.Xcoord - offset_pos;
  if (where <= 0) {
    mouse_over.title = '';
    mouse_over.onclick = null;
  }
  else {
    var band = Math.floor(where * stripes.links.length / img_width)
           % stripes.links.length;
    mouse_over.title = stripes.links[band].title;
    if (debug) mouse_over.title = mouse_over.title + " (" + mouse_pos.toString() + ")";
    var this_url = window.status = stripes.links[band].url;
    mouse_over.onclick = function() { window.location = this_url; };
  }
  return mouse_pos;
}

var stripes;

function setup_stripes(attr_list) 
{
  if (document.getElementById) {
    var stripes = new BandedImage( img_url, attr_list );
    var mouse_over = document.getElementById("header");
    var h1 = mouse_over.getElementsByTagName("h1")[0];
    var cityname_img = h1.getElementsByTagName("IMG")[0];
    var offset_pos = findPosX(h1);
    if (offset_pos) {
      offset_pos += cityname_img.width;
    }
    else { /* stupid IE */
      offset_pos = parseInt(getStyle(document.getElementById("main"),'marginLeft'));
      var tabs = document.getElementById("leftnav");
      var tab_link = tabs.getElementsByTagName("a")[0];
      offset_pos += parseInt(getStyle(tab_link,'width'));
      var city_img = new Image();
      city_img.src = cityname_img.src;
      offset_pos += city_img.width;
    }

    var img_url = getStyle(h1,'background-image');
    if (!img_url) img_url = getStyle(h1, 'backgroundImage');
    if (!img_url) img_url = getStyle(h1, 'backgroundimage');
    if (!img_url) {
      // Safari is stupid about background-image.
      var h1_img = document.getElementById('h1-backgroundimage');
      if (h1_img) img_url = h1_img.src;
    }
    if (!img_url) {
      alert('No img_url found, h1.style is ' + h1.currentStyle + ' ' + dump_object(h1.currentStyle,0));
      return;
    }

    img_url = img_url.replace(/^url\((")?/,"");
    img_url = img_url.replace(/(")?\)/,"");
    var mouse_over_img = new Image();
    mouse_over_img.src = img_url;
    mouse_over.style.cursor = 'pointer';
    cityname_img.style.cursor = 'auto';

    mouse_over.onmousemove = mouse_over.onmouseover = function(e){
      update_mouse_pos(e, mouse_over, stripes, mouse_over_img.width, offset_pos);
    };
  }
}

