   $("#mode ul li."+lastmode).removeClass("mode_active")
   #console.log($("#mode ul li."+mode))
 
+activatepanel = (panel_id) ->
+  $(panel_id).fadeTo "20000", 0.33 
+deactivatepanel = (panel_id) ->
+  console.log(panel_id + " deactivated")
+  $(panel_id).fadeTo "20000" ,1 
 
 initInputBox = (params = {region:"de",direction:"to",selector:"#from_input_field", showpanel:true}) ->
   if not $("#"+params.direction+"_panel").is(":visible") and params.showpanel
-    $("#"+params.direction+"_panel").fadeTo "20000", 0.33
+    activatepanel("#"+params.direction+"_panel")
     console.log("showing panel")
   console.log "initInputBox called with parameter: "
   #removing any autocomplete functionality 

  $("#mode .from").click -> switchmode "from", App.mode
  $("#mode .splash").click -> switchmode "splash", App.mode
  $("#mode .result").click -> switchmode "result", App.mode
  $("#to_input_field").focus()
  initInputBox({region:"de",direction:"to",selector:"#to_input_field",showpanel:false})

  to: {}
  from: {}
  socket: {}
  from_choosen: false
  to_choosen: false
  geotypes: ["locality","sublocality","street_address","route"]
  # "locality", "premise", "subpremise", "route", "street_address
  mode: "splash"


switchmode = (mode, lastmode=App.mode) ->
  if mode is lastmode
    console.log("switchmode changed nothin'. because lastmode was: "+ lastmode + " and new mode is " +mode)
    return
  if mode == "to"
    $("#from_input").hide()
    $("#to_input, #middle_overlay").show()
    activatepanel("#to_panel")
    $("to_input_field").autocomplete "search"
  else if mode == "from"
    $("#to_input").hide()
    $("#from_input, #middle_overlay").show()
    activatepanel("#from_panel")
    $("from_input_field").autocomplete "search"
  else if mode == "result"
    $("#middle_overlay, #to_input, #from_input").hide()
    $("#options").show()
    $("#rides").show()
  if lastmode is "to" or lastmode is "from"
    deactivatepanel "##{lastmode}_panel"
  App.mode = mode
 
  # for debugging
