var FUTABA = {};

$(document).ready(function(){
    window.FUTABA.updater.run( {} );
});

FUTABA.updater = {
    VERSION: '0.01',
    BASEURL: 'http://jr.futaba-soccerspike.net',
    TYPES: [
        {'type':'training', 'title':'ジュニアトレーニングシューズ', 'listname':'ジュニアトレーニングシューズ一覧へ', 'catid': '25'},
        {'type':'spike', 'title':'ジュニアスパイク', 'listname':'ジュニアスパイク特価商品一覧へ', 'catid': '24'},
        {'type':'wear', 'title':'ジュニアサッカーウェア', 'listname':'新商品一覧へ', 'catid': '19'},
        {'type':'sale', 'title':'ジュニア激安SALE', 'listname':'ジュニア激安SALE一覧へ', 'catid': '338'}
    ],


    run: function( arg ) {
        var __this = this;
        __this.get_contents();
    },

    get_contents: function( arg ) {
        var __this = this;
        var restUri = __this.BASEURL + '/futaba.json';
        var callback = function ( data ) {
            for ( var i = 0; i < __this.TYPES.length; i++) {
                __this.display_contents(__this.TYPES[i], data[__this.TYPES[i].type]);
            }
        };
        jQuery.getJSON( restUri, {}, callback );
    },

    display_contents: function( type_ref, items ) {
        var __this = this;
        var div = $('#futaba-' + type_ref.type);
        div.empty();
        div.append('<h3>' + type_ref.title + '</h3>');
        for (var i = 0; i < 4; i++) {
            var block = __this._display_content(items[i]);
            div.append(block);
        }
        div.append('<p><a href="' + __this.BASEURL + '/products/list/' + type_ref.catid + '/">' + type_ref.listname + '</a></p>');
    },

    _display_content: function( item ) {
        var __this = this;
        var block = '<dl><dt><a href="' + item.href + '"><img src="' + item.src + '" width="120" /></a></dt><dd><strong><a href="' + item.href + '">' + item.name + '</a></strong><br />' + item.desc + '</dd></dl>';
        return block;
    }

};


