(function(){
    
    var frontpage = function(){
        Alces.Core.Component.call(this);
        
        this.dom = {
            core: null,
            wpForm: null,
            wpWhere: null,
            ypForm: null,
            ypWhat: null,
            ypWhere: null,
            mapForm: null,
            mapWhere: null,
            routeForm: null,
            routeFrom: null,
            routeTo: null
        };
        
        this.autoSuggests = null;
        
        (function(self){
            self.dom.core = jQuery('#frontpage');
            self.dom.wpForm = self.dom.core.find('form.wp-searchbox');
            self.dom.wpWhere = jQuery('#txt-wp-searchbox-where');
            self.dom.ypForm = self.dom.core.find('form.yp-searchbox');
            self.dom.ypWhat = jQuery('#txt-yp-searchbox-what');
            self.dom.ypWhere = jQuery('#txt-yp-searchbox-where');
            self.dom.ypIsCategory = jQuery('#txt-yp-searchbox-is-category');
            self.dom.mapForm = self.dom.core.find('form.map-search');
            self.dom.mapWhere = jQuery('#txt-map-search-where');
            self.dom.routeForm = self.dom.core.find('form.route-search');
            self.dom.routeFrom = jQuery('#txt-route-search-from');
            self.dom.routeTo = jQuery('#txt-route-search-to');
            
            self.autoSuggests = {
                wpWhere: new Alces.autoSuggest({
                    id: 'autosuggest-wp-where',
                    container: self.dom.wpForm,
                    input: self.dom.wpWhere,
                    type: 'where'
                }),

                ypWhat: new Alces.autoSuggestComposite({
                    id: 'autosuggest-yp-what',
                    container: self.dom.ypForm,
                    input: self.dom.ypWhat,
                    isCategoryInput: self.dom.ypIsCategory,
                    types: [
                        {
                            type: 'what',
                            title: 'Hakusanat'
                        },
                        {
                            type: 'company',
                            title: 'Yritykset'
                        }
                    ]
                }),

                ypWhere: new Alces.autoSuggest({
                    id: 'autosuggest-yp-where',
                    container: self.dom.ypForm,
                    input: self.dom.ypWhere,
                    type: 'where'
                }),

                mapWhere: new Alces.autoSuggest({
                    id: 'autosuggest-map-where',
                    container: self.dom.mapForm,
                    input: self.dom.mapWhere,
                    type: 'where'
                }),

                routeFrom: new Alces.autoSuggest({
                    id: 'autosuggest-route-from',
                    container: self.dom.routeForm,
                    input: self.dom.routeFrom,
                    type: 'where'
                }),

                routeTo: new Alces.autoSuggest({
                    id: 'autosuggest-route-to',
                    container: self.dom.routeForm,
                    input: self.dom.routeTo,
                    type: 'where'
                })
            };
        })(this);
    };
    
    frontpage.prototype = new Alces.Core.Component();
    
    jQuery(document).ready(function(){
        new frontpage();
    });
})();
