//------------------------------------------------------------------------------
//  Men's Club デザイン用スクリプト by H_O
//------------------------------------------------------------------------------

// Namespace
if(typeof(MENSCLUBns)=='undefined'){var MENSCLUBns={};};

// ThumbNail MoueOver Action
MENSCLUBns.showThumbDetailTask = null;
MENSCLUBns.showThumbDetail = function(event){
 var a = Event.element(event);	// イベントオブジェクト
 var p = a.parentNode;		// 親オブジェクト
 // detailを含む親オブジェクトを判定
 if(p.tagName.toLowerCase() != 'li'){p = a.parentNode.parentNode;}
 // detailオブジェクトを確定
 var d = p.getElementsByClassName('column-ex-nextlatest-body')[0];
 // 表示コンテナの内容を切替
 $('nextlatest-text-body').innerHTML = d.innerHTML;
};

// Article Profile MouseOver Action
MENSCLUBns.showArticleDetailTask = [];
MENSCLUBns.hideArticleDetail = function(){
 $('article-detail-wrapper').style.display = 'none';
 $('article-detail1').style.display = 'none';
 $('article-detail2').style.display = 'none';
 $('article-detail3').style.display = 'none';
};
MENSCLUBns.showArticleDetail = function(o){
 MENSCLUBns.hideArticleDetail();
 var o = $(o);
 var container = $('article-detail-wrapper');
 container.style.display = 'block';
 container.style.height = (o.getHeight()+50)+'px';
 var closer = container.getElementsByClassName('close')[0];
 closer.style.marginTop = (container.getHeight()-20)+'px';
 closer.style.marginRight = '10px';
 var p = Position.cumulativeOffset($('article-detail-wrapper'));
 o.style.left = (p[0]+20)+'px';
 o.style.top = (p[1]+20)+'px';
 o.style.display = 'block';
};

// SlideShow
MENSCLUBns.slide = Class.create();
MENSCLUBns.slide.prototype = {
 c:0,		// Current Index
 v:5,		// Slide Interval(ms)
 s:[],		// Slide Stock
 h:100,		// Slide Height

 // 初期化：インターバルの設定
 // 引数：インターバル数
 initialize : function(interval){this.v=interval;},

 // スライドの追加
 // 引数：スライド画像を括るエレメント
 addSlide : function(obj){this.s.push(obj);},

 // 表示スライドの高さ設定
 // 引数：高さ数値
 setSlideHeight : function(height){this.h=height;},

 // 現在のスライドと次のスライドを移動する
 show:function(){
  // 現在のスライドをスライドの高さ分上に移動する
  var current = this.c;
  this.s[current].style.display = 'block';
  new Effect.Morph(this.s[current],{style:'top:'+(this.s[current].getHeight()*-1)+'px;'});

  // 次のスライドインデックスを調査
  this.c++;
  var next=this.c;
  if(next>=this.s.length){next=this.c=0;}

  // 次のスライドを表示して移動する
  this.s[next].style.display = 'block';
  new Effect.Morph(this.s[next],{style:'top:0px;'});

  // 待機中の他のスライドを隠して移動する
  for (var loop=0; loop<this.s.length; loop++){
   if ((loop!=current)&&(loop!=(next))) {
    this.s[loop].style.display='none';
    this.s[loop].style.top=this.h+'px';
   }
  }
 },

 // スライドの位置等の初期化と、PeriodicalExecuterのセット
 start:function(){
  for(var loop=0;loop<this.s.length;loop++){
   this.s[loop].style.display = 'none';
   this.s[loop].style.top = (this.h * loop) + 'px';
  }
  this.s[this.c].style.display = 'block';
  this.p = new PeriodicalExecuter(this.show.bind(this),this.v);
 }
};

// ブログ転載ボタン表示用JSONPコールバック
function blogButtons(btnpack){
 try{
  if (btnpack.buttons.length>0){
   var html = '';
   btnpack.buttons.each(function(btn){
    if (btn) {
     html += '<li><a target="_blank" href="';
     html += btn.link;
     html += '" title="';
     html += btn.provider;
     html += '"><span style="background-color:white;width:auto;display:block;text-align:center;"><img src="';
     html += btn.provider_logo_src;
     html += '" alt=\"';
     html += btn.provider;
     html += '" \/><\/span><\/a><\/li>\n';
    }
   });
   var be = $('blog-center').getElementsByClassName('entry')[0];
   be.innerHTML = html;
   $('blog-upperline').style.display = 'block';
   $('blog-center').style.display = 'block';
   $('blog-underline').style.display = 'block';
  }
 }catch(err){}
}

// 転載先ブログエントリ表示用JSONPコールバック
function blogEntries(entrypack){
 try{
  if (entrypack.entries.length>0){
   var html = '\n';
   entrypack.entries.each(function(entry){
    html += '<li class="clearfix">';
    html += '<a href="' + entry.link + '" title="' + entry.blog_full + '" target="_blank">';
    html += '<img src="' + entry.provider_logo_src + '" alt="' + entry.provider + '" \/>';
    html += '<span>' + entry.entry_full + '<\/span><\/a>';
    html += '<\/li>\n';
   });
   var bo = $('blog-center').getElementsByClassName('outer')[0];
   bo.innerHTML = html;
  }
 }catch(err){}
}

// ページロード時実行スクリプト
Event.observe(window,'load',function(e){
 // スライド設定
 try{
  var mcSlide = new MENSCLUBns.slide(3);
  mcSlide.setSlideHeight(Element.getHeight($('feature-photo')));
  mcSlide.addSlide($('feature1'));
  mcSlide.addSlide($('feature2'));
  mcSlide.addSlide($('feature3'));
  mcSlide.start();
 }catch(e){}

 // サムネイル設定
 try{
  var thumbs = $('column-ex-nextlatest').getElementsByTagName('a');
  $A(thumbs).each(function(a){
   if (a.parentNode.tagName.toLowerCase() =='li') {
     Event.observe(a,'mouseover',function(e){try{MENSCLUBns.showThumbDetailTask = MENSCLUBns.showThumbDetail.later(300)(e);}catch(err){}},false);
     Event.observe(a,'mouseout',function(e){try{MENSCLUBns.showThumbDetailTask.cancel();}catch(err){}},false);
   }
  });
 }catch(e){}

 // 記事属性表示設定
 try{
  // 表示コンテナ透過設定
  Element.setOpacity($('article-detail-wrapper'),0.7);
  // 駆動エレメント設定
  var o1 = document.getElementsByClassName('detail-author')[0];
  Event.observe(o1,'mouseover',function(e){MENSCLUBns.showArticleDetailTask[0] = MENSCLUBns.showArticleDetail.later(300)('article-detail1');},true);
  Event.observe(o1,'mouseout',function(e){try{MENSCLUBns.showArticleDetailTask[0].cancel();}catch(err){}},true);
  var o2 = document.getElementsByClassName('detail-column')[0];
  Event.observe(o2,'mouseover',function(e){MENSCLUBns.showArticleDetailTask[1] = MENSCLUBns.showArticleDetail.later(300)('article-detail2');},true);
  Event.observe(o2,'mouseout',function(e){try{MENSCLUBns.showArticleDetailTask[1].cancel();}catch(err){}},true);
  var o3 = document.getElementsByClassName('detail-backnumber')[0];
  Event.observe(o3,'mouseover',function(e){MENSCLUBns.showArticleDetailTask[2] = MENSCLUBns.showArticleDetail.later(300)('article-detail3');},true);
  Event.observe(o3,'mouseout',function(e){try{MENSCLUBns.showArticleDetailTask[2].cancel();}catch(err){}},true);
  // Closeオブジェクト
  var closer = $('article-detail-wrapper').getElementsByClassName('close')[0];
  Event.observe(closer,'click',function(e){MENSCLUBns.hideArticleDetail();Event.stop(e);},true);
 } catch(e){}
},false);
