var Search = {
  observingId : '',
  defaultMsg  : '',
  lastTimeout : false,
  
  observe : function(id, targetClass) {
    Search.observingId = id;
    
    $(id).observe('keyup', function(elm) {
        if (Search.lastTimeout) {
          clearTimeout(Search.lastTimeout);
        }
        
        Search.lastTimeout = setTimeout("Search.update('" + $(id).value + "', '" + targetClass + "')", 600);
    });
    
    $(id).observe('click', function(evt) {
        if ($(id).value == Search.defaultMsg) {
          $(id).value = '';
        }
    });
  },
  
  setDefault : function(id, value) {
    $(id).value       = value;
    Search.defaultMsg = value;
  },
  
  update : function(value, targetClass) {
    if (value.length > 2) {
      new Ajax.Updater($$('.' + targetClass).first(), '/pages/search/' + value, {
           asynchronous : true,
           evalScripts  : true,
           onComplete   : function (request) {
           },
           onLoading:function(request) {
             $(Search.observingId).stopObserve();
           },
           method:'post'
      })
    }
  }
  
}


//Search.setDefault("livesearch", "Livesearch");
Search.observe("livesearch", "content_inner");