var SpecialistController = Class.create({
  
  initialize:function()
  {
    // hook up search form submit (for seo friendly url's). not all pages which include this script have the search form
    if ($('specialists_search_form'))
      $('specialists_search_form').observe('submit', this.searchFormSubmit.bind(this));
    
    // make the 'about troplinks' subnav visible and change the body colour, even though this page technically isn't an about page
    var searchSelector = '#nav>ul>li.about-section'; // main about nav item
    searchSelector += ', #nav>ul>li.about-section>a.about-section'; // main about nav item's <a> tag
    searchSelector += ", #nav a[href='about']"; // any nav item pointing to the about section
    searchSelector += ", #nav a[href='about/specialists']"; // any nav item pointing to our alternate url
    $$(searchSelector).each(function(liElement) {
      liElement.addClassName('current');
    }.bind(this));
  },
  
  searchFormSubmit:function(submitEvent)
  {
    // country only
    if ($F('country_field') && !$F('category_field') && !$F('keywords_field')) {
      submitEvent.stop();
      document.location = $('baseTag').href + 'specialists/' + $F('country_field').toLowerCase();
    }
    
    // category only
    if ($F('category_field') && !$F('country_field') && !$F('keywords_field')) {
      submitEvent.stop();
      document.location = $('baseTag').href + 'specialists/' + $F('category_field');
    }
    
    // allow submit to take place for any other search
  }

});

var specialistsController = false;
document.observe('dom:loaded', function() {
  specialistsController = new SpecialistController();
});

