                                                   "module-finder-sidebar")))
 
     (.click ($ :#timetable-builder-tab-link)
-            (fn []
-              (hide ($ :#module-finder))
-              (.removeClass (parent ($ :#module-finder-tab-link)) "active")
-              (.addClass (parent ($ :#timetable-builder-tab-link)) "active")
-              (show ($ :#timetable-builder))
-              (select2/shift-select2-container-to "module-finder-sidebar"
-                                                  "timetable-builder-controls")
-              (aset js/window "ActiveTab" TIMETABLE-TAB-INDEX)))
+            timetable-builder-tab-click-handler)
 
     ; Add module lesson groups from the hash of the url
     (let [urlHash (aget (aget js/document "location") "hash")]

(ns ^{:doc "main entry point for the cljs-nusmods project"}
  cljs-nusmods.main
  (:use [jayq.core :only [$ $deferred $when attr document-ready done hide is one
                          parent prevent resolve show]])
  (:require [cljs-nusmods.module-array-repr     :as module-array-repr]
            [cljs-nusmods.aux-module-array-repr :as aux-module-array-repr]
            [cljs-nusmods.lesson-array-repr     :as lesson-array-repr]

       :private true}
  MODULE-FINDER-SCRIPTS-DLED? false)

(defn- timetable-builder-tab-click-handler
  "Click event handler for the `Timetable Builder` tab"
  []
  (hide ($ :#module-finder))
  (.removeClass (parent ($ :#module-finder-tab-link)) "active")
  (.addClass (parent ($ :#timetable-builder-tab-link)) "active")
  (show ($ :#timetable-builder))
  (select2/shift-select2-container-to "module-finder-sidebar"
                                      "timetable-builder-controls")
  (aset js/window "ActiveTab" TIMETABLE-TAB-INDEX))

(defn- initialize-exhibit3 [MODULES AUXMODULES]
  "Initialize Exhibit3 database and UI for Module Finder page"
  (if (and (not (aget js/window "Exhibit3_Initialized"))
           (aget js/window "Exhibit3_Loaded")
           MODULE-FINDER-SCRIPTS-DLED?
           (= (aget js/window "ActiveTab") MODULEFINDER-TAB-INDEX))
    (let [$timetable-builder-tab-link ($ :#timetable-builder-tab-link)]
      ; Unbind the click event handler for `Timetable Builder` tab link so
      ; the user cannot switch tabs when we are initializing Exhibit3 here and
      ; screw things up
      (unbind $timetable-builder-tab-link "click")
      (aux-module-array-repr/init!)
      (let [modulesArray (build-modules-array MODULES AUXMODULES)
            itemsArray   (add-aux-info-to-exhibit-items
