var Shopping = Class.create();

Shopping.prototype = {
    // Initialize class
    initialize: function(root, path){
        this.root = root;
        this.path = path;
        this.image_w = 1439;
        this.image_h = 411;
        this.image_zoom_w = 1600;
        this.image_zoom_h = 363;
        this.visible_w = 679;
        this.visible_h = 244;
        this.offset_h = this.image_w - this.visible_w;
        this.offset_v = this.image_h - this.visible_h;
        this.shop_id = 0;
        this.zoom = 0;
        this.position_h = 0.7;
        this.position_v = 0.5;
    },
    list_shops: function(id){
        this.reset_category(id);
        new Ajax.Updater('store-list', this.path + 'list_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_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']
        });
        
        var mapFlashObj = this.getFlashObject('map');
        mapFlashObj.setPoints(id);
    },
    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");
            }
        }
    },
    getFlashObject: function(movieName){
        if (window.document[movieName]) {
            return window.document[movieName];
        }
        if (navigator.appName.indexOf("Microsoft Internet") == -1) {
            if (document.embeds && document.embeds[movieName]) {
                return document.embeds[movieName];
            }
        } else {
            return document.getElementById(movieName);
        }
    }
}
