// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Event.observe(window, 'load',
function() {
  fix_external_links();
}
);

function fix_external_links() {
  $$('a').findAll(
    function(e) {
      res = false
      if(location.hostname == e.hostname) {
        if(e.pathname.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
          res = true
        }
      } else {
        res = true
      }
      return res
    }
  ).each(function(e) {
    if(e.href.substr(0,6) != 'mailto') {
      e.target = "new"
    }
    Event.observe(e, 'click', function(event) {
      try {
        e = Event.element(event);
        path = "";
        if (e.href.substr(0,6) == 'mailto') {
          path = "/mailto/" + e.href.substr(7)
        } else if (location.hostname != e.hostname) {
          path = "/external/" + e.hostname
        } else {
          path = e.pathname
        }
        urchinTracker(path)
      }
      catch(err) { }
    });
  })
}

// bookings
function update_location(select) {
  l_id = select.options[select.selectedIndex].value;
  v_select = $('booking_venue_id');
  v_select.options.length = 0;
  lv[l_id].each(function(v) {
    v_select.options[v_select.options.length] = new Option(v[0], v[1])
  })
}

// testimonials
function showTestimonial(n){
  for(i=0; i < num_testimonials; i++) {
    t = $("t_"+i);
    a = $("a_"+i);
    if(i==n) {
      t.show();
      a.addClassName('active');
    } else {
      t.hide();
      a.removeClassName('active');
    }
  }
}