Element.implement({
    inputHint : function(val){
        switch (this.get('tag')){
            case 'form':
                this.getElements('input[type="text"],textarea').inputHint(val);
                return this;
            case 'input':
            case 'textarea':
                this.store('default', (val||this.get('value')));
                this.addEvents({
                    'focus':function(){
                        if(this.get('value') == this.retrieve('default')){
                            this.set('value', '');
                        }
                    },
                    'blur':function(){
                        if(this.get('value').clean() == ''){
                            this.set('value', this.retrieve('default'));
                        }
                    }
                }).fireEvent('blur');
            default: return this;
        }
    },

    replaceClass: function(className, replaceWith) {
        this.className = this.className.replace(className, replaceWith);
        return this;
    },

    display: function(show) {
        this.setStyle('display', ((show === false || show == 'none') ? 'none' : ''));    
    },

    toggleDisplay: function() {
        this.setStyle('display', (this.getStyle('display') == 'none' ? '' : 'none'));    
    }
}); 

(function() {
    function initAutoHide() {
        $$('.autohide').each(function(el) {
            (function(){ el.slide('out'); }).delay(3000);
        });
    }
    function createUIButton() {
        $$('input.ws-button').each(function(el){
            el.removeClass('ws-button');
            var className = el.className;
            el.className = '';
            new Element('div', {'class': 'x-button'}).addClass(className).wraps(
               el.addClass('x-button-y')).adopt(
               new Element('div', {'class': 'x-button-rw'}).adopt(
               new Element('div', {'class': 'x-button-r'})));
        });
        $$('a.as-button').each(function(el){
            var label = el.get('text');
            el.set('text', '').replaceClass('as-button', 'a-button').adopt(
                new Element('span', {'text':label,'class':'a-button-l'})).adopt(
                new Element('span', {'class':'a-button-rw'}).adopt(
                new Element('span', {'class':'a-button-r'})));
        });
    }
    function initSearchInput() {
        var box = $('search_keyword');
        if (!box) return;
        box.inputHint();
    }
    function initFormFocus() {
        var frm = $(document.body).getElement('form');
        if (!frm || frm.hasClass('nofocus')) return;
        var fields = frm.getElements('input');
        if (fields.length == 0) return;
        try { // incase of this element is invisible, ie will throw out an exception
            fields[0].focus();
        } catch (e) {}
        for (var i = 0, l = fields.length; i < l; i++) {
            var li = fields[i].getParent('li');
            if (li && li.hasClass('error')) {
                fields[i].focus();
                break;
            } 
        }
    }
    window.addEvent('domready', function() {
        // createUIButton();
        initAutoHide();
        initSearchInput();
        initFormFocus();
    });    
})();

