/*
Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype, Effect.Base.prototype), {
initialize: function(element) {
    this.element = $(element);
    this.posTop = Position.cumulativeOffset(this.element)[1];
    this.posBot = this.posTop + this.element.offsetHeight;
    this.winTop =  window.scrollY ? window.scrollY : document.body.scrollTop;
    this.winHeight = window.innerHeight ? window.innerHeight : document.body.clientHeight;
    this.winBot = this.winTop + this.winHeight;
    
    this.destTop = this.ensureVisible();
    
    this.start(arguments[1]);
},
update: function(position) {
    var diff = this.winTop + (this.destTop-this.winTop)*position;
    window.scrollTo(0, diff);
},
ensureVisible: function() {
    if (this.posTop < this.winTop) {
        return this.posTop;
    } else if (this.posBot > this.winBot) {
        if (this.element.offsetHeight < this.winHeight) {
            return this.posTop - (this.winHeight - this.element.offsetHeight);
        } else {
            return this.posTop;
        }
    } else { 
        return this.winTop;
    }
}
});
  */

Event.observe(window, 'load', function(){
    
if($('pgtop')){
    Event.observe($('pgtop'), 'click', function(){ Element.scrollTo($('container')); return false;}, false);
}

var searchResult = Class.create();
searchResult.prototype = {
    initialize: function() {
        this.searchbox = $('side-searchbox-result');
        this.searchbox.innerHTML='<img src="/images/loading.gif" width="20" height="20" />';
        Element.show(this.searchbox);
        new Ajax.Request("/phpmanual/side_result.php", { method: 'post', parameters: Form.serialize($('search-box-form')), onComplete: this.showResult.bind(this) });
    },
    showResult: function(response){
        Element.hide(this.searchbox);
        this.searchbox.innerHTML=response.responseText;
        Effect.SlideDown(this.searchbox);
    }
};

//Event.observe($('keyword'), 'keypress', function(event){if (event.keyCode == Event.KEY_RETURN) Event.stop(event);}, false);
//Event.observe($('search-box-form'), 'keypress', function(event){if (event.keyCode == Event.KEY_RETURN) Event.stop(event);}, false);

/* for Autocompleter */
if($('keyword-choices')){
    new Ajax.Autocompleter('keyword', 'keyword-choices', '/phpmanual/keywords.php', { tokens: ' ', min_chars: 1, select: 'keyword-title' });
}
if($('side-keyword-choices')){
    new Ajax.Autocompleter('side-keyword', 'side-keyword-choices', '/phpmanual/keywords.php', { tokens: ' ', min_chars: 1, select: 'keyword-title' });
    Event.observe($('search-box-form'), 'submit', function(){ new searchResult(); return false; }, false);
}

});