var Food = Class.create();

Food.prototype = {
    // Initialize class
    initialize: function(root, path){
        this.root = root;
        this.path = path;
        this.shop_id = 0;
    },
    
    list_shops: function(id){
        this.reset_category(id);
        new Ajax.Updater('store-list', this.path + 'list_food_shops/' + id, {
            onLoading: function(request){
                Element.show('store-list-loading');
                Element.hide('store-list-title');
                Element.hide('store-list');
                Element.hide('store-detail');
            },
            onComplete: function(request){
                Element.hide('store-list-loading');
                Element.show('store-list-title');
                Effect.BlindDown('store-list', {
                    duration: 0.5
                });
            },
            asynchronous: true,
            evalScripts: true,
            requestHeaders: ['X-Update', 'store-list']
        });
    },
    
    reset_category: function(id){
        var prefix = 'store-category-';
        var list = $('category-list').getElementsByTagName('a');
        var nodes = $A(list);
        for (var i = 0; i < nodes.length; i++) {
            if (prefix + id == nodes[i].id) {
                Element.addClassName(nodes[i].id, "on");
            }
            else {
                Element.removeClassName(nodes[i].id, "on");
            }
        }
    },
    
    view_detail: function(id){
        this.shop_id = id;
        this.reset_shops(id);
        new Ajax.Updater('store-detail', this.path + 'view_food_detail/' + id, {
            onLoading: function(request){
                Element.show('detail-loading');
                Element.hide('store-detail-title');
                Element.hide('store-detail');
            },
            onComplete: function(request){
                Element.hide('detail-loading');
                Element.show('store-detail-title');
                Effect.BlindDown('store-detail', {
                    duration: 0.5
                });
            },
            asynchronous: true,
            evalScripts: true,
            requestHeaders: ['X-Update', 'store-detail']
        });
    },
    
    reset_shops: function(id){
        var prefix = 'store-';
        var list = $('store-list').getElementsByTagName('a');
        var nodes = $A(list);
        for (var i = 0; i < nodes.length; i++) {
            if (prefix + id == nodes[i].id) {
                Element.addClassName(nodes[i].id, "on");
            }
            else {
                Element.removeClassName(nodes[i].id, "on");
            }
        }
    }
}
