// Namespace
if(typeof(BESTORYns)=='undefined'){
 var BESTORYns={
  util:{},      // Other Utility Function
  cls:{},       // Class
  show:{},      // Element show Function
  mv:{},        // Element move Function
  cb:{},        // Callback Function
  eom:null      // End Mark
 };
}

// シンプルタブグループ
BESTORYns.cls.simpleTabGroup = Class.create(ISMEDIAns.cls.tabGroup,{
 initialize: function($super,options){
  $super(options);
  this.activeClass = this.options['activeClass'] || 'active';
  this.inactiveClass = this.options['inactiveClass'] || 'inactive';
  // ナビゲーション背景情報
  this.naviContainer = this.options['naviContainer'] || 'navi-menu';
  this.naviMenuBackgroundImage = this.options['naviMenuBackgroundImage'];
  this.activating = function(){
   for (var i=1; i<=this.count; i++){
    if (i==this.activeid) {
     $(this.tab + i ).className = this.activeClass;
    } else {
     $(this.tab + i ).className = this.inactiveClass;
    }
   }
   $(this.naviContainer).style.backgroundImage = 'url(' + this.naviMenuBackgroundImage[this.activeid].src + ')';
  };
 },
 eom:null
});

// TOPフューチャータブグループ
BESTORYns.cls.featureTabGroup = Class.create(ISMEDIAns.cls.tabGroup,{
 initialize: function($super,options){
  $super(options);
  this.beforeid = this.options['beforeid']||1;
  this.beforeid = this.options['beforeid']||1;
  this.duration = this.options['duration']||0.5;       //エフェクト効果のduration
  this.appearEffecting = false;
  this.fadeEffecting = false;
  // タブ切替後のアクション
  this.activating = function(){
   // アクティブタブが切り替わっていなければ何もしない
   if (this.activeid == this.beforeid) {
    return;
   }
   var _e = this;
   // 念の為全タブ走査
   for (var i=1; i<=this.count; i++){
    // 新アクティブタブの効果設定
    if(i==this.activeid) {
     // タブのクラス切替
     $(this.tab + i).className = 'active';
     // 詳細エレメントの表出効果設定
     if (!this.fadeEffecting) {
     new Effect.Appear($(this.tab + i + this.detailsuffix),{
      from:0.0,
      to:1.0,
      duration:this.duration,
      // 効果前の事前設定
      beforeStartInternal: function(effect) {
       effect.element.setOpacity(0.0);
       effect.element.style.visibility = 'visible';
      },
      afterFinishInternal: function(effect){
       effect.element.setOpacity(1.0);
       effect.element.style.visibility = 'visible';
       _e.appearEffecting = false;
      }
     });
     }
    // 旧アクティブタブの効果設定
    } else if (i==this.beforeid){
     // タブのクラス切替
     $(this.tab + i).className = 'no-active';
     // 詳細エレメントの消失効果設定
     if (!this.fadeEffecting) {
     new Effect.Fade($(this.tab + i + this.detailsuffix),{
      from:1.0,
      to:0.0,
      duration:this.duration,
      // 効果前の事前設定
      beforeStartInternal: function(effect) {
       effect.element.setOpacity(1.0);
       effect.element.style.visibility = 'visible';
      },
      afterFinishInternal: function(effect){
       effect.element.setOpacity(0.0);
       effect.element.style.visibility = 'hidden';
       _e.fadeEffecting = false;
      }
     });
     }
    } else {
     $(this.tab + i).className = 'no-active';
    }
   }
  };
 },
 eom:null
});

// TOPフューチャータブグループオートプレイヤー
BESTORYns.cls.featureTabGroup.autoPlayer = Class.create({
 task:null,    // プレイヤータスク
 initialize: function(options){
  this.tabs = options['tabs']; // タブグループオブジェクトエイリアス
  this.interval = options['interval']||3;      // 切替インターバル
  this.button = $(options['button']);  // プレイヤーのstart/stop切替操作用エレメントID
  this.starticonsrc = options['starticonsrc']; // 切替STARTボタン
  this.stopiconsrc = options['stopiconsrc'];   // 切替STOPボタン
  this.eventPlay = this.play.bindAsEventListener(this);  // start/stop切替イベント
  this.eventPlayHover = this.playHover.bindAsEventListener(this);  // 切替ボタンマウス効果イベント
  Event.observe(this.button,'click',this.eventPlay,true);
  Event.observe(this.button,'mouseover',this.eventPlayHover,true);
  Event.observe(this.button,'mouseout',this.eventPlayHover,true);
 },
 // タブの移動処理
 move: function(_this){
  var _e = _this;
  return function(){
   var next = _e.tabs.activeid;
   // ランダムではなく順序で移動 最後の次は先頭に戻る
   next = (next==_e.tabs.count) ? 1: next+1;
    _e.tabs.activate(next)();
  };
 },
 // タブの移動処理のループスタート
 start: function(){
  this.task = new PeriodicalExecuter(this.move(this),this.interval);
  // 手動切替ボタンの画像変更
  this.button.src = this.stopiconsrc;
 },
 // 移動処理ループの停止とタスクの後処理
 stop: function(){
  try{
   this.task.stop();
   this.task = null;
   // 手動切替ボタンの画像変更
   this.button.src = this.starticonsrc;
  } catch(e){}
 },
 // 自動切替処理
 play: function(event){
  // タスクが存在しなければ、自動切替スタート、そうでなければストップ
  (this.task == null ) ? this.start() : this.stop();
 },
 // 切替ボタンの画像変更
 playHover: function(event){
  var iconsrc = this.button.src;
  if (event.type == 'mouseout') {
   this.button.src = iconsrc.replace(/(.*)2\.gif/,'$11\.gif');
  }
  if (event.type == 'mouseover') {
   this.button.src = iconsrc.replace(/(.*)1\.gif/,'$12\.gif');
  }
 },
 eom:null
});

function setActiveStyleSheet(title){ISMEDIAns.util.setFontStyleSheet(title);}
function printWindow(url,w,h){ISMEDIAns.util.openWindow(url,w,h);}

Event.observe(window,'load',function(e){
 (function(){
  ISMEDIAns.util.initFontStyle();

  // 記事用サイトナビゲーションタブ切替
  if ($('sitenavi-menu1') != undefined){
   if(typeof(BESTORYns.util.sitenavi)=='undefined'){
    BESTORYns.util.sitenavi = {};
   }
   var Sns = BESTORYns.util.sitenavi;

   // ナビゲーション背景画像先読み
   Sns.backgroundImage = new Array();
   Sns.backgroundImage[0] = new Image();
   Sns.backgroundImage[0].src = '/common/images/v1/navi/navi_bg.gif';
   Sns.backgroundImage[1] = new Image();
   Sns.backgroundImage[1].src = '/common/images/v1/navi/bg_navi1.jpg';
   Sns.backgroundImage[2] = new Image();
   Sns.backgroundImage[2].src = '/common/images/v1/navi/bg_navi2.jpg';
   Sns.backgroundImage[3] = new Image();
   Sns.backgroundImage[3].src = '/common/images/v1/navi/bg_navi3.jpg';

   Sns.menu = new BESTORYns.cls.simpleTabGroup({
    tab:'sitenavi-menu',
    detailsuffix:'-box',
    count:3,
    activeClass:'reverse',
    inactiveClass:'normal',
    naviContainer:'navi-menu',
    naviMenuBackgroundImage:Sns.backgroundImage,
    useContinue:false
   });


   // サイトナビゲーションデフォルト値
   Sns.defaultMenuIndex = 0;
   if ($('sitenavi-menu1').className == 'reverse') {
    Sns.defaultMenuIndex = 1;
   }
   if ($('sitenavi-menu2').className == 'reverse') {
    Sns.defaultMenuIndex = 2;
   }
   if ($('sitenavi-menu3').className == 'reverse') {
    Sns.defaultMenuIndex = 3;
   }

   // サイトナビゲーションデフォルトリバース
   Sns.setDefaultMenu = function(event){
    var checkINmenu = function(n,navi){
     var node = n;
     while(node&&node!=navi) node = node.parentNode;
     return Boolean(node);
    }
    var navi = $('navi-menu');
    try{
     var r = event.relatedTarget || event.toElement;
     if (!checkINmenu(r,navi)) {
      if (Sns.defaultMenuIndex != 0) {
       Sns.menu.activate(Sns.defaultMenuIndex)();
      } else {
       Sns.menu.activate(1)();
       navi.style.backgroundImage = 'url(' + Sns.backgroundImage[0].src + ')';
       $('sitenavi-menu1').className = 'normal';
      }
     }
    }catch(err){
     if (Sns.defaultMenuIndex != 0) {
      Sns.menu.activate(Sns.defaultMenuIndex)();
     } else {
      Sns.menu.activate(1)();
      navi.style.backgroundImage = 'url(' + Sns.backgroundImage[0].src + ')';
      $('sitenavi-menu1').className = 'normal';
     }
    }
   }
   Sns.menuTask = null;
   Sns.sensitivity = 100;
   Event.observe('navi-menu','mouseout',function(e){Sns.menuTask = Sns.setDefaultMenu.later(Sns.sensitivity)(e);},true);
   Event.observe('navi-menu','mouseover',function(e){try{Sns.menuTask.cancel();}catch(err){}},true);
  }

  if(typeof(BESTORYns.util.topSpace)=='undefined'){
   BESTORYns.util.topSpace = {};    // BESTORY用トップ画面変数定義場所
  }
  var Stop = BESTORYns.util.topSpace; // 名前空間参照エイリアス

  // featureタブの先頭エレメント有無によるfeature動作処理実施判定
  if ($('feature-item1') != undefined) {
   // タブ対象エレメントを取得
   Stop.fTabList = $$('#icon-ground ul li');

   // フューチャータブ操作クラス作成
   Stop.fTab = new BESTORYns.cls.featureTabGroup({
    activeid:7,
    beforeid:7,
    tab:'feature-item',		// タブエレメントのプレフィックス
    detailsuffix:'-detail',	// ディテールエレメントのサフィックス
    count:Stop.fTabList.length,	// タブ数
    duration:2.0,		// 切替効果のduration
    useVisible:true		// displayではなくvisibilityを利用する
   });

   // フューチャータブ操作のオートプレイヤークラス作成
   Stop.fPlayer = new BESTORYns.cls.featureTabGroup.autoPlayer({
    tabs:Stop.fTab,	// 連携タブグループオブジェクト
    interval:4.5,		// 切替インターバル(秒数)
    button:'slideplayerbutton',	// 切替ボタンエレメントID
    starticonsrc:'/common/files/dev/images/v1/feature/start1.gif',	// 切替ボタンスタートイメージ
    stopiconsrc:'/common/files/dev/images/v1/feature/stop1.gif'	// 切替ボタンストップイメージ
   });

   // 画面表示時点での自動切替スタート
   Stop.fPlayer.start();

   // 追加動作として、タブエレメントにマウスオーバされた場合には自動切替をストップさせる
   // また、自動切替ストップ時にマウスアウトした場合には指定のデフォルトのタブをActiveにする
   Stop.featureAutoTask = null;	// 自動切替ストップ用タスク
   Stop.featureDefaultTask = null;	// デフォルト表示用タスク
   Stop.featureDefaultTabID = 7;	// デフォルト表示タブID
   Stop.featureSensitivity = 300;	// 追加動作稼働感度(ms)
   for(var i=0;i<Stop.fTabList.length;i++){
    Event.observe(Stop.fTabList[i],'mouseover',function(e){
     try{Stop.featureDefaultTask.cancel();}catch(e){}
     Stop.featureAutoTask = (function(){Stop.fPlayer.stop();}).later(Stop.featureSensitivity)();
    },true);

    Event.observe(Stop.fTabList[i],'mouseout',function(e){
     try{Stop.featureAutoTask.cancel();}catch(err){}
     var r = e.relatedTarget || e.toElement;
     Stop.featureDefaultTask = (function(){Stop.fTab.activate(Stop.featureDefaultTabID)()}).later(Stop.featureSensitivity)();
    },true);
   }
   Event.observe($('feature-items'),'mouseover',function(e){
    try{Stop.featureDefaultTask.cancel();}catch(e){}
   },true);
   Event.observe($('feature-items'),'mouseout',function(e){
    Stop.featureDefaultTask = (function(){Stop.fTab.activate(Stop.featureDefaultTabID)()}).later(Stop.featureSensitivity)();
   },true);
  }

  if ($('column-lists') != undefined) {
   // リスト初期設定
   Stop.coverContainer = $('column-lists-container');
   Stop.coverContainerWidth = 0; // コンテナサイズ初期化
   Stop.coverShowListCount = 3;  // 同時表示数
   Stop.coverListMargin = 5;     // カバーマージン
   Stop.coverList = Stop.coverContainer.getElementsByTagName('div'); // カバーリスト取得
   Stop.coverListCount = Stop.coverList.length;       // カバー定義数
   Stop.coverCurrentIndex = 0;  // 先頭インデックス

   // コンテナ幅の設定
   for(var i=0;i<Stop.coverListCount;i++){
    Stop.coverContainerWidth += Element.getDimensions(Stop.coverList[i]).width + Stop.coverListMargin * 2;
   }
   Stop.coverContainer.style.width = Stop.coverContainerWidth + Stop.coverListMargin + 'px';

   Stop.coverAutoPlayer = null;
   Stop.coverAutoPlayTime = 2;
   Stop.coverAutoPlay = function(){
    if (Stop.coverCurrentIndex < (Stop.coverListCount - Stop.coverShowListCount )) {
     Stop.coverCurrentIndex++;
    }
    // コンテナ位置設定
    var lpos = 0;
    for(var i=0;i<Stop.coverCurrentIndex;i++){
     lpos += (Element.getDimensions(Stop.coverList[i]).width + Stop.coverListMargin * 2) * -1;
    }
    var autoDelay = 0.3;
    if (Stop.coverCurrentIndex==1){
     var autoDelay = 1.0;
    }
    new Effect.Morph(Stop.coverContainer,{
     queue:{position:'end',scope:'columnlist',limit:1},
     style:'left:' + lpos + 'px',
     delay:autoDelay,
     duration:1.5,
     afterFinish:function(effect){
      if (Stop.coverCurrentIndex == (Stop.coverListCount - Stop.coverShowListCount )) {
       new Effect.Morph(Stop.coverContainer,{
        queue:{position:'end',scope:'columnlist',limit:1},
        style:'left:10px',
        delay:1.0,
        duration:3.0,
        afterFinish:function(effect){
         Stop.coverCurrentIndex = 0;
        } 
       });
      }
     }
    });
   };

   // 移動操作
   Stop.coverNext = function(){
    if (Stop.coverCurrentIndex < (Stop.coverListCount - Stop.coverShowListCount )) {
     try{Stop.coverAutoPlayer.stop();Stop.coverAutoPlayer=null;}catch(err){Stop.coverAutoPlayer=null;}
     Stop.coverCurrentIndex++;
    } else {
     return;
    }
    // コンテナ位置設定
    var lpos = 0;
    for(var i=0;i<Stop.coverCurrentIndex;i++){
     lpos += (Element.getDimensions(Stop.coverList[i]).width + Stop.coverListMargin * 2) * -1;
    }
    var q = Effect.Queues.get('columnlist');
    q.each(function(e){e.cancel();});
    new Effect.Morph(Stop.coverContainer,{
     queue:{position:'front',scope:'columnlist',limit:2},
     style:'left:' + lpos + 'px',
     duration:0.3,
     afterFinish:function(effect){
      Stop.coverAutoPlayer = new PeriodicalExecuter(Stop.coverAutoPlay,Stop.coverAutoPlayTime); 
     }
    });
   };

   Stop.coverPrev = function(){
    if (Stop.coverCurrentIndex>0) {
     try{Stop.coverAutoPlayer.stop();Stop.coverAutoPlayer=null;}catch(err){Stop.coverAutoPlayer=null;}
     Stop.coverCurrentIndex--;
    } else {
     return;
    }
    // コンテナ位置設定
    var lpos = 0;
    for(var i=0;i<Stop.coverCurrentIndex;i++){
     lpos += (Element.getDimensions(Stop.coverList[i]).width + Stop.coverListMargin * 2) * -1;
    }
    var q = Effect.Queues.get('columnlist');
    q.each(function(e){e.cancel();});
    new Effect.Morph(Stop.coverContainer,{
     queue:{position:'front',scope:'columnlist',limit:2},
     style:'left:' + lpos + 'px',
     duration:0.3,
     afterFinish:function(effect){
      Stop.coverAutoPlayer = new PeriodicalExecuter(Stop.coverAutoPlay,Stop.coverAutoPlayTime); 
     }
    });
   };

   // 移動ボタン動作設定
   // Nextボタン
   Event.observe('column-block-next-id','click',function(e){Stop.coverNext();},true);
   // Prevボタン
   Event.observe('column-block-prev-id','click',function(e){Stop.coverPrev();},true);

   // Auto Stop
   Event.observe('column-list','mouseover',function(e){
    try{Stop.coverAutoPlayer.stop();Stop.coverAutoPlayer=null;}catch(err){Stop.coverAutoPlayer=null;}
    var q = Effect.Queues.get('columnlist');
    q.each(function(e){e.cancel();});
    Event.stop(e);
   },true);
   // Auto Start
   Event.observe('column-list','mouseout',function(e){
    try{Stop.coverAutoPlayer.stop();Stop.coverAutoPlayer=null;}catch(err){Stop.coverAutoPlayer=null;}
    var q = Effect.Queues.get('columnlist');
    q.each(function(e){e.cancel();});
    Stop.coverAutoPlayer = new PeriodicalExecuter(Stop.coverAutoPlay,Stop.coverAutoPlayTime); 
    Event.stop(e);
   },true);
   // Auto
   Stop.coverAutoPlayer = new PeriodicalExecuter(Stop.coverAutoPlay,Stop.coverAutoPlayTime); 

  }

 })(); 
},true);

