 
   return obj
 
+searchTerms = new ReactiveVar("")
+
 getCurrentCategory = ->
   myCat = BootstrapMagic.dictionary.currentCategory.get()
   return _.where(bootstrap_magic_variables, { category: myCat })
 
 getCurrentVariables = ->
-  if noSearchWords
+  if noSearchInput
     subCatId = BootstrapMagic.dictionary.currentSubCategory.get()
-    console.log "original: ",  _.find bootstrap_magic_variables, (group) -> group._id is subCatId
     return _.find bootstrap_magic_variables, (group) -> group._id is subCatId
   else 
     letsSearch()

  BootstrapMagic.dictionary.currentSubCategory.set bootstrap_magic_variables[0]._id

camelToSnake = (str) -> str.replace(/\W+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1-$2')
searchTerms = new ReactiveVar("")

Template._bootstrap_magic.helpers
  "categories" : ->  _.map _.groupBy(bootstrap_magic_variables, 'category'), (obj) ->  obj[0]
  "subCategories" : getCurrentCategory
  "currentVars" : getCurrentVariables
  "mappedVariables" : -> 
    if noSearchWords()
      _.map @data, mapVariableOverrides
    else 
      letsSearch()

  "isSelectedCat" : -> @category is BootstrapMagic.dictionary.currentCategory.get()
  "isSelectedSubCat" : ->  @_id is BootstrapMagic.dictionary.currentSubCategory.get()
  "previewTmpl" : -> Template["bootstrap_magic_preview_#{camelToSnake @_id}"] || null
  "inputTmpl" : -> Template["bootstrap_magic_input_#{@type}"] || null
  "typeIs" : (type) -> @type is type
  "searchInactive" : -> noSearchWords()
  "searchHeader" :-> 
    if letsSearch().length == 0
      return "No Search Results"
    else
      return "Search Results: "

Template._bootstrap_magic.events
  'keyup .magic-search' : (e) -> 

  searchResults = _.filter items, (obj) => obj._id?.indexOf(words) >- 1
  return searchResults

noSearchInput = -> 
  mySearchTerms = searchTerms.get()
  if !mySearchTerms or mySearchTerms.length < 3 then true else false

Template._bootstrap_magic.onCreated ->
  BootstrapMagic.start() if BootstrapMagic.start
