var Advertise = {

    SIZE : {
        'button135' : { w : 135, h :  45 },
        'fulls'  : { w : 450, h :  57 },
        'full'   : { w : 468, h :  60 },
        'half'   : { w : 234, h :  60 },
        'button' : { w : 120, h :  60 },
        'square' : { w : 120, h : 120 },
        'rect'   : { w : 180, h : 150 },
        'sky'    : { w : 120, h : 600 },
        'leader' : { w : 728, h :  90 }
    },

    ValueCommerce : {

        SID : 2249859,

        space : {
            '#adText876070930' : { pid : 876070930, t : 'タレント・モデルにも選ばれる、自家用レーザー脱毛器。' },

            '#adFullAnyHotel'    : { pid : 873725090, k : 'full'    },
            '#adFullAnySearch'   : { pid : 873725145, k : 'fulls'   },
            '#adButton135Dating' : { pid : 876076491, k : 'button135' },
            '#adButton135Sexual' : { pid : 876076415, k : 'button135' },

            '#adText873725115' : { pid : 873725115, t : '理想のパートナー探し' },
            '#adText873725104' : { pid : 873725104, t : 'サクラのいない出会い系' },
            '#adText873725109' : { pid : 873725109, t : '安心の出会い・お見合い' },
            '#adText873725111' : { pid : 873725111, t : '外国人の友達づくり' },

            '#adText875221810' : { pid : 875221810, t : 'ラブホテル体験談', j : 'http%3a%2f%2fwww%2elovecosmetic%2ejp%2fset%2fhotel%2ftaiken_0701%2ehtml' },
            '#adText876075953' : { pid : 876075953, t : 'ふたりのラブホテル体験談', j : 'http%3a%2f%2fwww%2elovecosmetic%2ejp%2fset%2fhotel%2ftaiken_0701%2ehtml', i : '/image/advertise/ban_lvcm_450.jpg', k : 'fulls' }

//          '#adText876070930' : { pid : 876070930, t : '' },
        },

        html : function(id) {
            var pid = this.space[id].pid;
            var s = Advertise.SIZE[this.space[id].k];
            var t = this.space[id].t;
            var j = this.space[id].j;
            var i = this.space[id].i;
            // MyLink with image
            if (j && i) {
                return '<a class="mb15" href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=' +this.SID+ '&amp;pid=' +pid+ '&amp;vc_url=' +j+ '"><img src="' +i+ '" width="' +s.w+ '" height="' +s.h+ '" alt="' +t+ '" /><br /><img clas="dn" src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=' +this.SID+ '&amp;pid=' +pid+ '" height="1" width="1" border="0" />' +t+ '</a>';
            // Banner link
            } else if (s) {
                return '<iframe class="mb15" frameborder="0" allowtransparency="true" height="'+ s.h +'" width="'+ s.w +'" marginheight="0" scrolling="no" src="http://ad.jp.ap.valuecommerce.com/servlet/htmlbanner?sid=' + this.SID + '&amp;pid=' + pid + '" marginwidth="0"><script type="text/javascript" src="http://ad.jp.ap.valuecommerce.com/servlet/jsbanner?sid=' + this.SID + '&amp;pid=' +pid + '"></script></iframe>';
            // Mylink without image
            } else if (j && t) {
                return '<a href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=' +this.SID+ '&amp;pid=' +pid+ '&amp;vc_url=' +j+ '" target="_blank" ><img class="dn" src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=' +this.SID+ '&amp;pid=' +pid+ '" height="1" width="1" border="0" />' +t+ '</a>';
            // Text link
            } else if (t) {
                return '<a href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=' +this.SID+ '&amp;pid=' +pid+ '" target="_blank" ><img class="dn" src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=' +this.SID+ '&amp;pid=' +pid+ '" height="1" width="1" border="0" />' +t+ '</a>';
            }
        },

        loadRandom : function(pid, cat) {
            if (10 <= lotateNum++) clearInterval(lotateId);
            var time = (new Date()).getTime();
            var url = '/ads/api';
            var param = { 'id' : pid, 'c' : cat };
            j$('#adRandom').load(url, param, function(html, status) {
                if (status == 'success') {
                    j$('#adRandom').show();
                    j$('#adRandom a[@href^="http://"]').attr('target', '_blank');
                }
            });
        },

        load : function() {
            // Random pick up
            if (j$('#adRandom').html()) {
                var pid = j$('#adRandom').html().split(/:/)[1];
                var cat = j$('#adRandom').html().split(/:/)[2] || '';
                lotateNum = 1;
                this.loadRandom(pid, cat);
                lotateId = window.setInterval('Advertise.ValueCommerce.loadRandom('+pid+', "'+cat+'")', 30000);
            }
            // Normal space
            for (var id in this.space) {
                j$(id).html(this.html(id));
                j$(id).show();
            }
            j$('#adText').show();
        }

    },

    KPG : {
        load : function() {
            var swfObj1 = new SWFObject('/image/advertise/ban_kpg_loveflowers.swf', 'ban_top_1', '220', '80', '6', '#000000');
            var swfObj2 = new SWFObject('/image/advertise/ban_kpg_sevenseas.swf', 'ban_top_2', '220', '80', '6', '#000000');
            swfObj1.write('ban_1');
            swfObj2.write('ban_2');
        }
    }

};
