   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) ->
+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"
-    $("#to_input, #to_panel").show()
-    $("#start_splash").hide()
+    $("#from_input").hide()
+    $("#to_input, #middle_overlay").show()
+    activatepanel("#to_panel")
+    $("to_input_field").autocomplete "search"
   else if mode == "from"
-    $("#from_input, #from_panel").show()
-    $("#start_splash").hide()
+    $("#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

  $("#mode ul li."+lastmode).removeClass("mode_active")
  #console.log($("#mode ul li."+mode))


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
    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
  $("#edit_from_input").click -> switchmode "from", App.mode
  $("#edit_to_input").click -> switchmode "to", App.mode
  $("#to_input_field").focus()
  initInputBox({region:"de",direction:"to",selector:"#to_input_field",showpanel:false})
