/*
    Copyright © 2009 - 2010, Datrim Web Design Ltd. All rights reserved.
*/

YAHOO.namespace("datrim");

YAHOO.datrim.PageLoad = function() {
    /**
     * The returned object here will be assigned to YAHOO.datrim.PageLoad and its members will then be 
     * publicly available.
     */
    return {
        
        /**
         * Sets things up by telling the DOM to call the adjustPanels function when the page has loaded.
         * Also sets up listeners for the search form input control.
         * 
         */
        init: function() {
            // Assign onDOMReady handler.
            YAHOO.util.Event.onDOMReady(this.initSearchBox);
        },

        /**
         * Called when the document has loaded. 
         * 
         * returns none.
         */
        initSearchBox: function() {
            var dom  = YAHOO.util.Dom;
            var lang = YAHOO.lang;
            
            var pageLoad   = YAHOO.datrim.PageLoad;
            var searchText = dom.get('ajaxSearch_input');
            
            if (!lang.isNull(searchText)) {
                // Hijack the search form text input control.
                YAHOO.util.Event.addFocusListener(searchText, pageLoad.searchFocus);
                YAHOO.util.Event.addBlurListener(searchText, pageLoad.searchBlur);
            }
        },
        
        searchFocus: function(e) {
            YAHOO.util.Event.preventDefault(e);
            
            if (this.value === 'Search') {
                this.value = '';
            }
        },
        
        searchBlur: function(e) {
            YAHOO.util.Event.preventDefault(e);
            
            if (this.value === '') {
                this.value = 'Search';
            }
        }
    };
}();

YAHOO.datrim.PageLoad.init();

