if(window['FD']) {
  FD.BigChairSR = new Class({
    Implements: [Options, Events],
    
    options: {
      currentPage: 1,
      totalPages: 1,
      currentSortName: null,
      minSalary: 100000,
      sortLookup: {"title": 2, "date": 3, "location": 4, "company": 5, "salary": 6, "industry": 7},//, "profession": 8}, // TODO fix these last two values
      listUrl: "/services/SearchResults.ashx",
      navigatorUrl: "/services/SearchResultsNavigator.ashx",
      JobDescURL: "/services/JobDetailsPage.aspx", 
      expressInterestURL: "/consumer/lightbox/express-interest.aspx?jobid=", 
      emailPostURL: "/consumer/lightbox/Forward.aspx?jobid=", 
      postBody: "s=100&tbc=20&ps=10&sf=3",
      pageSize: 10,
      prevLinkID: "fdSTablePrev",
      nextLinkID: "fdSTableNext",
      clearFiltersID: "mycClearFilters"
    },
    
    initialize: function(options) {
      this.setOptions(options);
      var initPostBody = this.options.postBody.split("&"), i = 0, pbVal;
      if(initPostBody) {
        var postBody = {};
        while(pbVal = initPostBody[i]) {
          pbVal = pbVal.split("=");
          postBody[pbVal[0]] = decodeURIComponent(pbVal[1]);
          i++;
        }
      }
      postBody.ps = this.options.pageSize;
      postBody.pg = this.options.currentPage;
      this.originalPostBody = postBody;
      this.postBody = new Hash(postBody);

      this.searchObj = {
        url: this.options.listUrl,
        data: this.data
      };
      
      var reset = this._getResetButton();
      if(reset) {
        reset.addEvent("click", this._reset.bind(this, reset));
      }
      
      this._initCookieCheck();
      this._initSlider();
      this._initRefine();
      this._initSearchResultsPanel();
      this._initLightBoxes();
      this._initShowHide();
      this._initSort();
      this._initPagination();
    }, 
    
    /* SLIDER */
    _initSlider: function() {
      var slider = this._getSlider();
      var button = this._getSliderButton();
      var select = this._getSliderSelect();
      
      if(slider && button && select) {
        select.setStyle('display', 'none');
        slider.addEvent("click", this._doSliderClick.bindWithEvent(this));
        // Create the button drag options
        var dragOptions = {
          grid: 20,
          container: select,
          onDrag: this._doSliderSnap.bind(this),
          onComplete: this._doSliderRefine.bind(this),
          limit: {
            x: [0, 160],
            y: [0, 0]
          },
          snap: false // Removes annoying 8px default.
        };
        
        // Create the Drag object.
        var thisDrag = new Drag(button, dragOptions);
        
        // set initial slider position
        if (lastSearchSalary != 0){
            var pos = this._getInitPosition(lastSearchSalary);
            button.setStyle("left", (pos * 20)+"px");
            this._setSliderPos(pos);
        }
      }
    }, 
    
    _getInitPosition: function(salary){
        var pos;
        switch (salary){
            case 100000: 
                pos = 0;
                break;
           case 125000: 
                pos = 1;
                break;
           case 150000: 
                pos = 2;
                break;
           case 175000: 
                pos = 3;
                break;
           case 200000: 
                pos = 4;
                break;
           case 225000: 
                pos = 5;
                break;
           case 250000: 
                pos = 6;
                break;
           case 275000: 
                pos = 7;
                break;
           case 300000: 
                pos = 8;
                break;
           default:
                pos = 0;
                break;
        }
        return pos;
    },
    
    _doSliderSnap: function(button) {
      if(button) {
        var pos = button.getStyle("left").toInt() / 20; // 20 for the number of pixels per pos
        this._setSliderPos(pos);
      }
    },
    
    _doSliderClick: function(e) {
      var slider = this._getSlider();
      if(e && e.target && e.target == slider) {
        var button = this._getSliderButton();
        var x = e.client.x - slider.getLeft() - 12; // 12 for distance from the edge of the div to the start of the bg image
        // Round the x pos to the closest 20px.
        var pos = Math.round((x / 20));
        // Move slider to the correct position
        button.setStyle("left", (pos * 20)+"px");
        // Set the slider position
        this._setSliderPos(pos);
        this._doSliderRefine();
      }
    },
    
    _setSliderPos: function(pos) {
      var select = this._getSliderSelect();
      if(pos >= 0 && select) {
        if(select.options[pos]) {
          select.selectedIndex = pos;
          this._sliderVal = select.options[pos].value;
          this._setSliderLabel(this._sliderVal);
        }
      }
    },
    
    _doSliderRefine: function() {
      var salary = this._sliderVal * 1000;
      var attrib = "sal";
      
      this.postBody.set(attrib, salary);
      var latestSearch = this._updateRecentSearchCookie(attrib, salary);
      this._updateLatestSearchLink(latestSearch, salary, attrib);
      this.postBody.set("pg", 1);
      this.doSearch();
    },
    
    _setSliderLabel: function(val) {
      var label = $('fdSalarySlider_l');
      if(val && label) {
        var text = document.newTextNode("$"+val+"K");
        label.empty().adopt(text);
      }
    },
    
    _resetSlider: function() {
      var attrib = "sal";
      var salary = 100000;
      var button = this._getSliderButton();
      button.setStyle("left", "0px");
      var latestSearch = this._updateRecentSearchCookie(attrib, salary);
      this._updateLatestSearchLink(latestSearch, salary, attrib);
      this._doSliderSnap(button);
    },
    
    /* END SLIDER */
    
    /* LIGHTBOXES */
    
    _initLightBoxes: function() {
      var locationLink = $('myCELocation');
      if (locationLink) {
        locationLink.addEvent("click", this._openLocLB.bindWithEvent(this));
      }
      var express = this._getExpressIntrestButtons();
      if(express) {
        express.addEvent("click", this._createLB.bindWithEvent(this, 'expLB'));
      }
      var email = this._getEmailButtons();
      if(email) {
        email.addEvent("click", this._createLB.bindWithEvent(this, 'emailLB'));
      }
      window.addEvent("resize", this._resizeOverlay.bind(this));
    },
    
    _createLB: function(e, id) {
      if(e && e.target && id) {
        e.stop();
        var target = $(e.target);
        if(target.get('tag') == "img") {
          target = target.getParent();
        }
        var src = target.href;
        
        var overlay = this._getOverlay();
        if(!overlay) {
          var overlay = new Element("div", {
            'opacity': 0.75,
            'display': 'none',
            'events': {
              'click': this._closeAllLBs.bind(this)
            }
          });
          overlay.set('id', 'overlay');
          var body = $$('body')[0];
          body.adopt(overlay);
        }
        var div = $(id);
        if(!div) {
          div = new Element("div", {
            'class': 'fdLightBox',
            id: id
          });
          
          var iFrame = new Element("iframe", {
            scrolling: "no",
            frameborder: 0,
            marginheight: 0,
            marginwidth: 0,
            hspace: 0,
            vspace: 0,
            allowtransparency: "true"
          });
          
          div.adopt(iFrame);
        } else {
          iFrame = div.getElement("iframe");
        }
        this._resizeOverlay();
        iFrame.src = src;
       
        var body = $$('body')[0];
        body.adopt(div);
        if(overlay) {
          overlay.setStyle("display", "block");
        }
        var wScroll = Document.getScroll();
        var wProps = Document.getSize();
        div.setStyle("display", "block");
        var boxCoords = div.getCoordinates();
        div.setStyles({
          top: (wScroll.y + (wProps.y - boxCoords.height) / 2),
          left: (wScroll.x + (wProps.x - boxCoords.width) / 2)
        });
      }
    },
    
    _openLocLB: function(e) {
      if(e && e.target) {
        e.stop();
        var button = $(e.target);
        var locationLB = this._getLocationsLB()
        if(locationLB) {
          if(!this.locationsEventAdded) {
            locationLB.addEvent("click", this._injectLocation.bindWithEvent(this));
            this.locationsEventAdded = true;
          }
          locationLB.empty();
          var pos = {
            top: (button.getTop() - 120),
            left: (button.getLeft() + 100)
          };
          locationLB.addClass("loading").setStyles(pos);
          var loc = button.href + "?" +this._getPostBody();
          new Request({
            url: loc,
            onComplete: this._updateLocationsLB.bind(this)
          }).get();
          locationLB.setStyle("display", "block");
        }
      }
    },

    _closeAllLBs: function() {
      $$('div.fdLightBox').setStyle("display", "none");
      var overlay = this._getOverlay();
      if(overlay) {
        overlay.setStyle("display", "none");
      }
    },
    
    _updateLocationsLB: function(resp) {
      var locationLB = this._getLocationsLB()
      if(resp && locationLB) {
        locationLB.removeClass("loading"); 
        var trimBody = resp.replace(/<\/?form+[^>]*>/gi, ""); 
        trimBody = trimBody.replace(/<\/?input.+type=\"hidden\"[^>]*>/gi, ""); 

        locationLB.empty().innerHTML = trimBody;
      }
    },
    
    _injectLocation: function(e) {
      if(e && e.target) {
        var thisLoc = $(e.target);
        if(thisLoc.hasClass("fdLBClose")) {
          this._closeAllLBs();
          return;
        }
        if(thisLoc.get('tag') == "a") {
          thisLoc = thisLoc.getParent().getParent();
        } else if(thisLoc.get('tag') == "span") {
          thisLoc = thisLoc.getParent();
        }
        var locationsBox = this._getLocationsList();
        if(locationsBox) {
          var thisLi = $('extraLoc');
          if(!thisLi) {
            thisLi = new Element("li", {
              id: "extraLoc"
            });
          } else {
            thisLi.empty();
          }
          if(thisLoc.get('tag') == "li") {
            // Remove Selected class from all anchors
            locationsBox.getElements("a").removeClass("selected");
            // Close the lightbox
            $('fdlb_myCELocation').setStyle("display", "none");
            
            // Search by this additional location.
            // the additional location html: <span><a href/></span>
            // hence we need to get the additional location <span> first
            var spanAdditionalLocation = thisLoc.getFirst();
            if (spanAdditionalLocation)
            {
                //get the additional location <a href/>
                var additionalLocationHref = spanAdditionalLocation.getFirst();
                if (additionalLocationHref)
                {
                	//do search
                    this._refineBy(additionalLocationHref, "l");
                }
            }
          }
        }
      }
    },

    /*
      Function: resizeOverlay
        Resizes the overlay div to be the same size as the window. 
        This method is called on window.onResize.
     */
    _resizeOverlay: function() {
      var overlay = this._getOverlay();
      if(overlay) {
        overlay.setStyle("height", 1);
        overlay.setStyle("width", 1);
        var wWidth = Window.getScrollWidth();
        var wHeight = Window.getScrollHeight();
        if(wWidth > Window.getWidth()) {
          wWidth = Window.getWidth();
        }
        if(wHeight == Window.getHeight() + 4) { // IE weirdness
          wHeight = Window.getHeight();
        }
        overlay.setStyle("height", wHeight+"px");
        overlay.setStyle("width", wWidth+"px");
      }
    },
   
    /* END LIGHTBOXES */
    
    /* REFINE */
    
    _initRefine: function() {
      var locations = this._getLocationsList();
      var industries = this._getIndustyList();
      if(locations) {
        locations.addEvent("click", this._refineLocation.bindWithEvent(this));
      }
      if(industries) {
        industries.addEvent("click", this._refineIndustry.bindWithEvent(this));
      }
    },
    
    _refineLocation: function(e) {
      if(e && e.target) {
        e.stop();
        this._refineBy($(e.target), 'l');
      }
    },
    
    _refineIndustry: function(e) {
      if(e && e.target) {
        e.stop();
        this._refineBy($(e.target), 'tbc');
      }
    },
    
    _fetchLatestSearchString: function(recentSearchesCookie) {
        //get most recent search string (always at the front of the list)
        var latestSearchArr = recentSearchesCookie.split("|");
        return latestSearchArr[0];
    },
    
    _resetRecentSearchInCookie: function(){
        // get cookie and the latest search
        var recentSearchesCookie = Cookie.get("RecentExecutiveJobSearches");
        var latestSearch = this._fetchLatestSearchString(recentSearchesCookie); 
        var initSearchStrNoSalary = lastSearchInitString.replace(/&sal=[^&]+/i, "&sal=100000");
        var initSearchTitleNoSalary = lastSearchInitTitle.replace(/\d\d\d,\d\d\d/gi, "100,000");
        
        // update and save cookie (lastSearchInitString registered in .Net code)
        var newCookieValue = recentSearchesCookie.replace(latestSearch, initSearchStrNoSalary);
        Cookie.set("RecentExecutiveJobSearches", newCookieValue, {duration: 30, path: "/"}); //save this cookie for 30 days and to root path
        
        // upate last search link (lastSearchInitTitle registered in .Net code)
        var recentSearchLink = this._getRecentSearchLink();
        recentSearchLink.empty().innerHTML = initSearchTitleNoSalary; 
        recentSearchLink.setProperty('href', '/jobseeker/search/results.aspx?' + initSearchStrNoSalary);
    },
    
    _updateRecentSearchCookie: function(attrib, value){
        // get cookie
        var recentSearchesCookie = Cookie.get("RecentExecutiveJobSearches");

        var latestSearch = this._fetchLatestSearchString(recentSearchesCookie);    
        var originalSearch = latestSearch;
        
        // find current search string in the cookie.        
        if (latestSearch){
            
            var regString = "&" + attrib + "=[^&]+";
            var pattern = new RegExp(regString, "i");
            var oldAttrib = pattern.exec(latestSearch);
            
            if (oldAttrib){
                var newAttrib = "&" + attrib + "=" + value;
                latestSearch = latestSearch.replace(oldAttrib, newAttrib);
            }
            else{
                // append new attrib to the search string
                latestSearch = latestSearch + "&" + attrib + "=" + value;
            }
            
            // update and save cookie
            var newCookieValue = recentSearchesCookie.replace(originalSearch, latestSearch);
            Cookie.set("RecentExecutiveJobSearches", newCookieValue, {duration: 30, path: "/"}); //save this cookie for 30 days and to root path
            
            return latestSearch;
        }

    },
    
    _updateLatestSearchLink: function(latestSearch, newValue, attrib)
    {
        var recentLink = this._getRecentSearchLink();
        recentLink.setProperty('href', '/jobseeker/search/results.aspx?' + latestSearch);
    
        if (attrib == 'l'){
            lastSearchLocation = ' in ' + newValue;              
        }
        else if(attrib == 'tbc'){
            lastSearchIndustry = newValue;
        }
        else if(attrib == 'sal'){
            lastSearchSalary = ' with salary of at least $' + newValue / 1000 + 'K';
        }
        
        var keyword = '';
        if(lastSearchKeyword.length>0){
             keyword = ' matching "' + lastSearchKeyword + '"';
        }
        
        // there should never be industry and job title displayed together, but just in case empty JobTitle
        if (lastSearchIndustry.length>0){
            lastSearchJobTitle = '';
        }    
        
        var newSearchTitle = lastSearchIndustry + lastSearchJobTitle + ' Jobs ' + keyword + lastSearchLocation + this._parseSalary(lastSearchSalary);   
        
        recentLink.empty().innerHTML  = newSearchTitle
        recentLink.setProperty('title', newSearchTitle); 
    },
    
    _parseSalary: function(salary)
    {
        if (salary == 0)
        {
            return '';
        }
        return salary;
    },
    
    /* 
      Attrib:  
        tbc = industry
          l = location
     */ 
    _refineBy: function(a, attrib) {
      var list = this._getRefineList(attrib);
      if(a && list) {
        if(a.get('tag') == "li") {
          a = a.getFirst();
        }
        if(a.get('tag') == "a" && !a.hasClass("fdLightBox")) {
          list.getElements("a").removeClass("selected");
          a.addClass("selected");

          var id = a.getAttribute(attrib);
          if(!id) {
            this.postBody.remove(attrib);
          } else {
            this.postBody.set(attrib, id);
            var latestSearch = this._updateRecentSearchCookie(attrib, id);
            this._updateLatestSearchLink(latestSearch, a.innerHTML, attrib);
          }
          this.postBody.set("pg", 1);
          this.doSearch();

        }
      }
    },
    
    _resetRefines: function() {
      var locations = this._getLocationsList();
      var industries = this._getIndustyList();
      if(locations) {
        var locs = locations.getElements("li a");
        locs.removeClass("selected");
        locs[0].addClass("selected");
      }
      if(industries) {
        var inds = industries.getElements("li a");
        inds.removeClass("selected");
        inds[0].addClass("selected");
      }
    },
    
    /* END REFINE */   
    
    /* SORT */
    
    _initSort: function() {
      var sortBy = $$('select.selectAction');
      if(sortBy) {
        sortBy.addEvent("change", this._sortBy.bindWithEvent(this));
      }
    },
    
    _sortBy: function(e) {
      if(e && e.target) {
        var sortBy = $$('select.selectAction'), sB, x = 0;
        var value = e.target.options[e.target.selectedIndex].value;
        var selIndex = e.target.selectedIndex;
        if(value) {
          this.postBody.set("sf", value);
          while(sB = sortBy[x]) {
            if(sB != e.target) {
              sB.selectedIndex = selIndex;
            }
            x++;
          }
        }
        this.postBody.set("pg", 1);
        this.doSearch();
      }
    },
    
    /* END SORT */
        
    /* PAGINATION */
    
    _initPagination: function() {
      var pages = this._getPageLists();
      pages.addEvent("click", this._changePage.bindWithEvent(this));
    },
    
    _changePage: function(e) {
      if(e && e.target) {
        e.stop();
        var a = $(e.target), page = this.options.currentPage, ele;
        if(a.get('tag') == "li") {
          a = a.getFirst();
        }
        if(!a.hasClass("inactive") && !a.hasClass("active")) {
          if(a.hasClass("next")) {
            if(this.options.currentPage + 1 <= this.options.totalPages) {
              page++;
            }
          } else if(a.hasClass("prev")) {
            if(page > 1) {
              page--;
            }
          } else {
            page = a.get('html').toInt();
          }
          this.postBody.set('pg', page);
          this.doSearch();
        }
      }
    },
    
    _setPageNumber: function(pageNum) {
      this.options.currentPage = pageNum;
      this.postBody.set("pg", pageNum);
    },
    
    _updatePages: function(pageCount) {
      this.options.totalPages = pageCount;
      var set = Math.ceil(this.options.currentPage / 5); 
      var page = this.postBody.get('pg');
      this.options.currentPage = page;
      if(page) {
        var pages = this._getPageLists();
        var startPage = ((set - 1) * 5) + 1;
        var x = 0;
        while(ul = pages[x]) {
          var i = 0, li, ul;
          var pageNo = startPage;
          var as = ul.getElements("li a");
          as.removeClass('active').removeClass('inactive');
          while(a = as[i]) {
            if(!a.hasClass("prev") && !a.hasClass("next")) {
              a.empty().set('html', pageNo);
              if(a.get('html').toInt() == page) {
                a.addClass("active");
              }
              if(pageNo > pageCount) {
                a.setStyle("display", "none");
              } else {
                a.setStyle("display", "block");
              }
              pageNo++;
            } else {
              if(a.hasClass("next") && page == pageCount || pageCount == 1) {
                a.addClass("inactive");
              } else if(a.hasClass("prev") && page == 1 || pageCount == 1) {
                a.addClass("inactive");
              }
            }
            i++;
          }
          x++;
        }
      }
    },
    
    /* END PAGINATION */
            
    /* SEARCH RESULTS PANEL */
    
    _initSearchResultsPanel: function() {
      var searchResults = this._getSearchResultsTable();
      if(searchResults) {
        searchResults.addEvent("click", this._doJobClick.bindWithEvent(this));
      }
    },
    
    _doJobClick: function(e) {
      if(e && e.target) {
        e.stop();
        var job = this._getParentLi($(e.target));
        this._loadJobDesc(job);
      }
    },
    
    _getParentLi: function(ele) {
      if(ele.get('tag') == 'li') {
        return ele;
      }
      var parent = ele;
      while(parent = parent.getParent()) {
        if(parent.get('tag') == "body") {
          break;
        }
        if(parent.get('tag') == "li") {
          return parent;
        }
      }      
    },
    
    _createRow: function(job) {
      if(job) {
        var row = new Element("li", {
          id: job.ID
        });
        var a = new Element("a", {
          href: this.options.JobDescURL + "?id="+job.ID
        });
        var small = new Element("small", {
          html: job.Refreshed
        });
        var h3 = new Element("h3", {
          html: this._limitText(job.Title, 27)
        });
        var h4 = new Element("h4", {
          html: this._limitLocText(job.Location) + " | " + this._limitText(job.Company, 15) + " | "
        }).adopt(new Element("span", {
          'class': 'pay',
          html: this._limitSalary(job.Salary)
        }));
        
        row.adopt(a.adopt(small).adopt(h3).adopt(h4).appendText(this._limitText(job.Summary, 60)));
        
        return row;
      }
    },
    
    _limitSalary: function(salary) {
      var salaryMatch = salary.match(/([0-9]+)/g), i = 0, sal, out = "";
      if(salaryMatch) {
        while(sal = salaryMatch[i]) {
          if(sal.length < 3) {
            return "Witheld";
          }
          if(sal.toInt() > 0) {
            if(i > 0) {
              out += " - ";
            }
            out += "$"+sal+"K";
          }
          i++;
        }
        salary = out;
      }
      return salary;
    },
    
    _limitLocText: function(loc) {
      if(loc) {
        return this._limitText(loc.substr(0, loc.indexOf(",")), 15);
      }
    },
    
    _limitText: function(text, len) {
      if(text.length > len) {
        text = text.substr(0, len).trim()+"...";
      }
      return text;
    },
    
    _parseResult: function(resp) {
      if(resp) {
        this._setPageNumber(this.postBody.get('pg'));
        this._setJobsTotal(resp.TotalCount.toInt());
        this._updatePages(resp.PageCount.toInt());
        this._updateRows(resp.Results);
      }
    },

    _updateRows: function(results) {
      if(results) {
        // Update the rows.
        $('searchDesc').removeClass("active");
        this._getPageLists().removeClass("hidden");
        var row, i = 0, jobCookies = Cookie.get("TBCViewedJobs");
        var searchResults = this._getSearchResultsTable();
        var resultsModule = this._getResultsModule();
        if(searchResults) {
          searchResults.empty();
          if(results.length && results.length > 0) {
            if(resultsModule) {
              resultsModule.removeClass("noresults");
            }
            while(row = this._createRow(results[i])) {
              if(i == 0) {
                row.addClass('expanded');
                this._loadJobDesc(row);
              }
              if(jobCookies && jobCookies.indexOf(row.id) > 0) {
                row.addClass("visited");
              }
              searchResults.adopt(row);
              i++;
            }
          } else {
            // no results
            $('searchDesc').addClass("active");
            //console.debug(resultsModule);
            if(resultsModule) {
              resultsModule.addClass("noresults");
            }
            this._getPageLists().addClass("hidden");
          }
          searchResults.removeClass("loading");
        }
      }
    },
    
    /* END SEARCH RESULTS PANEL */
    
    /* JOB DESCRIPTION */
    
    _updateJD: function(id) {
      new Request({
        url: this.options.JobDescURL,
        onComplete: this._displayJD.bind(this)
        //update: jdHolder
      }).post({
        ajax: true,
        id: id
      });
    },
    
    _displayLocationList: function(locationList) {
      if(locationList) {
        var jdHolder = this._getLocationsSlider();
        if (jdHolder)
        {
            jdHolder.empty().set('html', locationList);
            var locations = this._getLocationsList();
            if(locations) {
                locations.addEvent("click", this._refineLocation.bindWithEvent(this));
                //reinitialise the lightbox again
                this._initLightBoxes();
                }
            }
        }
    },
    
    _displayIndustryList: function(industryList) {
      if(industryList) {
        var jdHolder = this._getIndustrySlider();
        
        if (jdHolder)
        {
            jdHolder.empty().set('html', industryList);
            var industries = this._getIndustyList();
            if(industries) {
                industries.addEvent("click", this._refineIndustry.bindWithEvent(this));
                var locationLink = $('myCELocation');
                if (locationLink) {
                    locationLink.addEvent("click", this._openLocLB.bindWithEvent(this));
                    //reinitialise the lightbox again
                    this._initLightBoxes();
                }
      	    }
      	}
      }
    },
    
    _displayJD: function(jd) {
      if(jd) {
        var jdHolder = this._getJobDescription();
        jdHolder.empty().set('html', jd);
      }
    },
    
    _loadJobDesc: function(job) {
      if(job && job.id) {
        job.addClass("visited");
        this.addJobCookie(job.id);
        var id = job.id, jdHolder = this._getJobDescription();
        this._getSearchResultsTable().getElements("li").removeClass("expanded");
        jdHolder.empty();
        jdHolder.addClass("loading");
        job.addClass("expanded");
        this._updateJD(id);
        // Update Express buttons
        var express = this._getExpressIntrestButtons();
        if(express) {
          var i = 0, e;
          while(e = express[i]) { 
            e.href = this.options.expressInterestURL+job.id;
            i++;
          }
        }
        var email = this._getEmailButtons();
        if(email) {
          var i = 0, e;
          while(e = email[i]) { 
            e.href = this.options.emailPostURL+job.id;
            i++;
          }
        }
        var printLinks = this._getPrintLinks();
        if(printLinks){
            var i = 0, link;
            while(link = printLinks[i]) { 
                var oldPrintUrl = link.getProperty("href");
                var newPrintUrl = oldPrintUrl.replace(/\id=[0-9]+/, "id="+id);
                link.setProperty("href", newPrintUrl);
                i++;
            }
        }        

        FD.doNielsonImpression("jobDescription", this.options.expressInterestURL+job.id);
      }
    },
    
    // Add the selected job id to cookie
    addJobCookie: function(thisId) {
      var cookieJobIDs = Cookie.get("TBCViewedJobs");
      if(!cookieJobIDs) {
        cookieJobIDs = thisId;
      } else {
        cookieJobIDs = cookieJobIDs + "," + thisId;
      }
      Cookie.set("TBCViewedJobs", cookieJobIDs, {duration: 30, path: "/"}); //save this cookie for 30 days and to root path
    },
    
    _rowIsVisited: function(row) {
      if(row) {
        var cookieJobIDs = Cookie.get("TBCViewedJobs");
        var regex = "[,]*"+row.id;
        var match = new RegExp(regex, "g");
        if(match.exec(cookieJobIDs)) {
          return true
        }
      }
      return false;
    },
    
    _initCookieCheck: function() {
      var searchResults = this._getSearchResultsTable();
      if(searchResults) {
        var lis = searchResults.getElements("li"), li, x = 0;
        while(li = lis[x]) { 
          if(this._rowIsVisited(li)) {
            li.addClass("visited");
          }
          x++;
        }
      }
    },
    
    /* END JOB DESCRIPTION */
    
    /* SEARCH */
    
    doSearch: function(reset) {
      // Update the URL for the Additional locations button
      var locationLB = this._getLocationsLB();
      var resetButton = this._getResetButton();
      if(!reset && resetButton) {
        resetButton.addClass("active");
      }
      var resultsTable = this._getSearchResultsTable();
      if(resultsTable) {
        resultsTable.empty();
        resultsTable.addClass("loading");
        var aOpts = {
          url: this.searchObj.url,
          data: this.postBody.toQueryString(),
          onComplete: this._parseResult.bind(this)
        };
        new Request.JSON(aOpts).post();
      }
      //do ajax call to update location list
      var locationAjax =  new Request({
        url: this.options.navigatorUrl + "?type=location&" + this.postBody.toQueryString(),
        onComplete: this._displayLocationList.bind(this)
        }).get();
      
      //do ajax call to update industry list
      var industryAjax =  new Request({
        url: this.options.navigatorUrl + "?" + this.postBody.toQueryString(),
        onComplete: this._displayIndustryList.bind(this)
        }).get();   
        
      // must call content impression after we display the search result
      FD.doNielsonImpression("searchResults", window.location.href+"?"+aOpts.data);
      

          
    },
    
    _reset: function(resetButton) {
      if(resetButton) {
        resetButton.removeClass('active');
      }
      // Reset Slider
      this._resetSlider();
      this._resetRefines();
      this._resetRecentSearchInCookie();
      this.postBody = new Hash(this.originalPostBody);
      this.doSearch(true);
    },
    
    /* END SEARCH */
    
    /* SHOW HIDE */
    
    _initShowHide: function() {
      $$('h3.showhide').addEvent('click', this._doShowHide.bindWithEvent(this));
    },
    
    _doShowHide: function(e) {
      if(!this.showhiding && e && e.target) {
        this._closeAllLBs();
        var next = $(e.target).getNext();
        var nHeight = next.offsetHeight;
        if(nHeight > 0) {
          next.set('origHeight', nHeight);
        }
        var height = (nHeight) ? "0" : next.get('origHeight');
        this.showhiding = true;
        next.setStyle("height", next.offsetHeight+"px");
        var fx = new Fx.Morph(next, {
          onComplete: this._showHideComplete.bind(this, next),
          duration: 250
        }).start({
          height: height
        });
      }
    }, 
    
    _showHideComplete: function(next) {
      if(next.offsetHeight > 0) {
        next.setStyle("height", "auto");
      }
      this.showhiding = false;
    },
    
    /* END SHOW HIDE */
    
    /* GETTERS */
    
    _getPostBody: function() {
      return this.postBody.toQueryString() + "&" + Math.ceil(Math.random() * 1000000000);
    },
    
    _getJobDescription: function() {
      return $('JobDetails');
    },
    
    _getResetButton: function() {
      return $(this.options.clearFiltersID);
    },
    
    _getRefineList: function(attrib) {
      if(attrib == "l") {
        return this._getLocationsList();
      } else if(attrib == "tbc") {
        return this._getIndustyList();
      }
    },
    
    _getLocationsSlider: function() {
      return $('locationSlider');
    },
    
    _getLocationsList: function() {
      return $('myCELocationsList');
    },
    
    _getIndustrySlider: function() {
      return $('industrySlider');
    },
    
    _getIndustyList: function() {
      return $('myIndustryList');
    },
    
    _setJobsTotal: function(total) {
      $('totalJobs').set('html', total+" jobs");
    },
    
    _getPageLists: function() {
      return $$('div.pagination ul');
    },
        
    _getSearchResultsTable: function() {
      return $('searchResults');
    },
    
    _getSlider: function() {
      return $('fdSalarySlider_s');
    }, 
    
    _getSliderSelect: function() {
      return $('fdSalarySlider');
    }, 
    
    _getSliderButton: function() {
      return $('fdSLbut_fdSalarySlider');
    },
    
    _getSearchDetailsWrap: function() {
      return $('searchdetails-wrap');
    },
    
    _getExpressIntrestButtons: function() {
      return this._getSearchDetailsWrap().getElements('a.expressInterest');
    },
    
    _getRecentSearchLink: function() {
      return $('recentSearchesList').getElement('li').getElement('a');
    },
    
    _getEmailButtons: function() {
      return this._getSearchDetailsWrap().getElements('a.iconEmail');
    },

    _getLocationsLB: function() {
      return $('fdlb_myCELocation');
    },
    
    _getOverlay: function() {
      return $('overlay');
    },
    
    _getPrintLinks: function() {
        return $('searchdetails-wrap').getElements('a.iconPrint');
     },  
    
    _getResultsModule: function() {
      return $$('div.resultsModule');
    }
    
    /* END GETTERS */
    
  });
  
  var BigChairSR;
  function initBigChairSR() {
    BigChairSR = new FD.BigChairSR(window['bigChairOpts']);
    // Backwards compatibility
    window['FDLBController'] = {};
    FDLBController.lbs = [];
    var dummyLB = {
      close: BigChairSR._closeAllLBs.bind(BigChairSR)
    };
    FDLBController.lbs["fdlb_mycExpressInterest"] = dummyLB;
    FDLBController.lbs["fdlb_mycEmailJob"] = dummyLB;
  }
  
  FD.register("BigChairSR");
}

