Ozein.NewArrival = new Class.create();
Ozein.NewArrival.prototype = {
    initialize: function(node) {
        this.node = node;
        this.sts = node.getAttribute('ozein_checked');
        var modules = this._getModule(node);
        for (var i=0;i<modules.length;i++) {
            Event.observe(modules[i],'click',this.receive.bindAsEventListener(this, modules[i]));
        }
    },
    _getModule : function (baseNode) {
        return document.getElementsByAttribute('ozein_module', '*', baseNode);
    },
    receive: function(e, child) {
      var status;
      status = child.getAttribute('value');
      if(this.sts == status) {
        this._makeInputTag(status);
        Event.stop(e);
        return;
      }
      var ret = null;
      if(status == 'on') {
        var ans = confirm('配信設定を変更します。（受信）\nよろしいですか?');
        ret = 'off';
      } else {
        var ans = confirm('配信設定を変更します。（停止）\nよろしいですか?');
        ret = 'on';
      }
      if(!ans) {
        this._makeInputTag(ret);
        Event.stop(e);
        return ;
      }
      this.sts = status;
      child.disabled = true;
      var dt = new Date();
      var url = '/Newarrival/modify' + '/status/' + status + '/salt/' + dt.getTime();
      var beacon = new Ozein.Beacon(null,{"url":url,"salt":""});
      beacon.send();
      //エフェクト変更
      new Ozein.Suspender(child, {entity:'image',image:'/img/header/balloon_chg.gif',offsetX:-25,offsetY:0,duration:2.0});
      this._makeInputTag(status);
      child.disabled = false;
    },
    _makeInputTag: function(status) {
      var reconClass = null;
      var recoffClass = null;
      var reconChecked = null;
      var recoffChecked = null;
      if(status == 'on') {
        reconClass = 'class="current"';
        recoffClass = '';
        reconChecked = 'checked="checked"';
        recoffChecked = '';
      } else {
        reconClass = '';
        recoffClass = 'class="current"';
        reconChecked = '';
        recoffChecked = 'checked="checked"';
      }
      var buf = null;
      buf = '<li id="recon" ' + reconClass + '>';
      buf += '<label for="rdo01">';
      buf += '<input type="radio" value="on" name="status" id="rdo01"' + reconChecked + 'ozein_module="ozein"/><span>受信する</span>';
      buf += '</label>';
      buf += '</li>';
      buf += '<li id="recoff" ' + recoffClass + '>';
      buf += '<label for="rdo02">';
      buf += '<input type="radio" value="off" name="status" id="rdo02"' +  recoffChecked + ' ozein_module="ozein"/><span>受信しない</span>';
      buf += '</label>';
      buf += '</li>';
      buf += '';
      this.node.removeChild($('recon'));
      this.node.removeChild($('recoff'));
      $('status').innerHTML = buf;
      $('status').setAttribute('ozein_checked', status);
      Ozein.Invoker.invokeElement($('status'));
      this.sts = status;
      Event.observe($('rdo01'),'click',this.receive.bindAsEventListener(this, $('rdo01')));
      Event.observe($('rdo02'),'click',this.receive.bindAsEventListener(this, $('rdo02')));
    }
    
}
