Autocompleter.Base.prototype.updateChoices = function(choices) {
    if(!this.changed && this.hasFocus) {
      this.update.innerHTML = choices;
      Element.cleanWhitespace(this.update);
      Element.cleanWhitespace(this.update.down());

      if(this.update.firstChild && this.update.down().childNodes) {
        this.entryCount = 
          this.update.down().childNodes.length;
        for (var i = 0; i < this.entryCount; i++) {
          var entry = this.getEntry(i);
          entry.autocompleteIndex = i;
          this.addObservers(entry);
        }
      } else { 
        this.entryCount = 0;
      }

      this.stopIndicator();
      this.index = -1;
      
      if(this.entryCount==1 && this.options.autoSelect) {
        this.selectEntry();
        this.hide();
      } else {
        this.render();
      }
    }
  };
Autocompleter.Base.prototype.onKeyPress = function(event) {
    if(this.active)
      switch(event.keyCode) {
       case Event.KEY_TAB:
       case Event.KEY_RETURN:
         if(this.index == -1){
           this.active = false;
           this.hide();
           return;
         }
         this.selectEntry();
         return;
         //Event.stop(event);
       case Event.KEY_ESC:
         this.hide();
         this.active = false;
         Event.stop(event);
         return;
       case Event.KEY_LEFT:
       case Event.KEY_RIGHT:
         return;
       case Event.KEY_UP:
         this.markPrevious();
         this.render();
         Event.stop(event);
         return;
       case Event.KEY_DOWN:
         this.markNext();
         this.render();
         Event.stop(event);
         return;
      }
     else 
       if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 
         (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;

    this.changed = true;
    this.hasFocus = true;

    if(this.observer) clearTimeout(this.observer);
      this.observer = 
        setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  };
Autocompleter.Base.prototype.markPrevious = function() {
  if(this.index > 0) this.index--
    else this.index = this.entryCount-1;
  this.getEntry(this.index)//.scrollIntoView(true);
};
  
Autocompleter.Base.prototype.markNext =  function() {
  if(this.index < this.entryCount-1) this.index++
    else this.index = 0;
  this.getEntry(this.index)//.scrollIntoView(false);
};

var InputHelper = Class.create({
  initialize: function(input, helperText){
    this.input = $(input);
    if(!this.input){return;}
    this.helperText = helperText || "";
    this.input.value = this.helperText; 
    this.input.observe("focus", this.onFocus.bind(this));
    this.input.observe("blur", this.onBlur.bind(this));
    this.input.up("form").observe("submit", this.onSubmit.bindAsEventListener(this));
  },
  onFocus: function(){
    if($F(this.input) == this.helperText){this.input.clear(); this.input.setStyle({color: '#636363'});}
  },
  onBlur: function(){
    if($F(this.input).blank()){this.input.value = this.helperText; this.input.setStyle({color: '#DEDEDE'}); }
  },
  onSubmit: function(event){
    if($F(this.input).blank()){
      event.stop();
  		try {Effect.Shake(this.input.up("fieldset"), { 
        distance: 5,
        duration: 0.225
      });} catch(e){}
			try{new Effect.Highlight(this.input, {queue: {position:'end', scope: "sc"+this.input.id, limit:1}, duration: 0.4, startcolor: "#EB26A3"});} catch(e){}
      this.input.activate();
    }
  }
});
var InputScale = Class.create({
  initialize: function(container, inputField, options){
    this.container = $(container);
    this.inputField = $(inputField);
    if(!(this.container && this.inputField)){return;}
    this.moveX = 200;
    this.moveY = 200;
    this.options = Object.extend({
      scaleHeightKoef: 4,
      scaleWidthKoef: 3.5,
      inputDimensions: { originalHeight: 20, originalWidth: 120 },
      containerDimensions: { originalHeight: 22, originalWidth: 100 },
      containerPosition: { top: 16, left: 150 }
    }, options);
    this.inputField.observe("focus", this.increase.bind(this));  
	  this.inputField.observe("blur", this.decrease.bind(this)); 
    this.state = "initialized";
  },
  increase: function(){
    if(this.state == "increased" || this.state == "running"){return;}
    this.state = "running";
    var x = parseInt(Math.min(document.body.clientWidth, document.documentElement.clientWidth)/2
                      -this.options.inputDimensions.originalWidth*this.options.scaleWidthKoef/2 
                      - this.options.containerPosition.left);
    var y = parseInt(Math.min(document.body.clientHeight, document.documentElement.clientHeight)/2 
                      -this.options.inputDimensions.originalHeight*this.options.scaleHeightKoef/2
                      - this.options.containerPosition.top);                           
    this.moveX = x > 0 ? x : 0;
    this.moveY = y > 0 ? y : 0;
    new Effect.Parallel(
      [ 
        new Effect.Scale(this.inputField, 100*this.options.scaleHeightKoef, { scaleX: false, scaleMode: this.options.inputDimensions, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Scale(this.container, 100*this.options.scaleHeightKoef, { scaleX: false, scaleMode: this.options.containerDimensions, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Scale(this.inputField, 100*this.options.scaleWidthKoef, { scaleY: false, scaleMode: this.options.inputDimensions, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Scale(this.container, 100*this.options.scaleWidthKoef, { scaleY: false, scaleMode: this.options.containerDimensions, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Move(this.container, { x: this.moveX, y: this.moveY, sync: true })
      ], {duration: 0.8, 
          afterFinish: function(){
            //this.inputField.style.lineHeight = this.options.inputDimensions.originalHeight*this.options.scaleHeightKoef+"px";
            //this.inputField.style.fontSize = 16*this.options.scaleHeightKoef+"px";
				    this.container.className = "increased";
            this.state = "increased";
          }.bind(this)
      });
  },
  decrease: function(){
    if(this.state == "decreased" || this.state == "running"){return;}
    this.state = "running";
    new Effect.Parallel(
      [ 
        new Effect.Scale(this.inputField, 100/this.options.scaleHeightKoef, { scaleX: false, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Scale(this.container, 100/this.options.scaleHeightKoef, { scaleX: false, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Scale(this.inputField, 100/this.options.scaleWidthKoef, { scaleY: false, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Scale(this.container, 100/this.options.scaleWidthKoef, { scaleY: false, sync: true, transition: Effect.Transitions.sinoidal, restoreAfterFinish: false}),
        new Effect.Move(this.container, { x: -this.moveX, y: -this.moveY, sync: true })
      ], {duration: 0.8, 
         beforeStart: function(){this.container.className = "decreased";}.bind(this),
         afterFinish: function(){
            //this.inputField.style.lineHeight = this.options.inputDimensions.originalHeight+"px";
            //this.inputField.style.fontSize = "16px";
					  this.container.className = "decreased";
            this.state = "decreased";
          }.bind(this)
    });  
  }
});
var headerInputScale = null;
document.observe("dom:loaded", function(){
  new InputHelper("find_query", "any place");
  new InputHelper("locationSearch", "any place");  
  headerInputScale = new InputScale("locationSearchDiv", "locationSearch");
  Event.observe(document, 'keypress', function (event){
   	var key = event.keyCode || event.which;
  	if(key == 27){
  		Event.stop(event);
     	if(headerInputScale && headerInputScale.state && headerInputScale.state == "increased" && headerInputScale.state != "running"){
       	headerInputScale.decrease();
        headerInputScale.inputField.blur();
     	}
  	}
  }.bindAsEventListener(), false);
});