//-------------------------------------------------------------------
// Article Flow
//-------------------------------------------------------------------
function ArticleFlow(_id,_i,_cc,_box){
 try{
  new MWProtoFlow($(_id),{
   startIndex: _i,
   captionColor: _cc,
   useBox: _box
  });
 }catch(e){}
}
//-------------------------------------------------------------------
// Bookmark
//-------------------------------------------------------------------
function BMdelicious(_url,_title){var w=window.open('http://delicious.com/save?v=5&noui&jump=close&url='+_url+'&title='+_title, 'delicious','toolbar=no,width=550,height=550');}
function BMdigg(_url,_title){var w=window.open('http://digg.com/submit?phase=2&url='+_url+'&title='+_title, 'DiggSubmit','');}
function BMhatena(_url,_title){var w=window.open('http://b.hatena.ne.jp/append?'+_url, 'HatenaBookmark','');}
function BMnewsing(_url,_title){var w=window.open('http://newsing.jp/add?url='+_url, 'newsingIt','');}
function BMyahoo(_url,_title){var w=window.open('http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?u='+_url+'&t='+_title+'&ei=UTF-8', 'YahooBookmark','width=550,height=480,left=100,top=50,scrollbars=1,resizable=1');}
function BMgoo(_url,_title){var w=window.open('http://bookmark.goo.ne.jp/add/detail?url='+_url, 'Gooブックマーク','');}
function BMlivedoor(_url,_title){var w=window.open('http://clip.livedoor.com/clip/add?link='+_url+'&title='+_title, 'livedoorClip','');}
function BMfurl(_url,_title){var w=window.open('http://www.furl.net/items/new?u='+_url+'&t='+_title, 'FurlThisPage','');}
function BMstumbleupon(_url,_title){var w=window.open('http://www.stumbleupon.com/submit?url='+_url+'&title='+_title, 'StumbleIt','');}
function BMgoogle(){var a=document,b=a.createElement('script'),w=window,g={};g.altWindow=w.open('','_blank','height=370px,width=720px,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');setTimeout(function(){g.altWindow.focus()},1000);function f(o){try{var d=new google.share.EmailWidget(g);d.display();}catch(e){if(o>20) return;setTimeout(function(){f(o+1)},o<10?1<<o:1000);}}b.src='http://www.google.com/s2/sharing/js?script=socialsharing&key=&hl=ja';a.body.appendChild(b);f(0);}
function BMgoogleR(){
var b=document.body;window.GR________bookmarklet_domain='http://www.google.co.jp';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.co.jp/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}
}
function BMfriendfeed(_url,_title){try{var a=document.createElement('script');a.setAttribute('type','text/javascript');a.setAttribute('src','http://friendfeed.com/share/bookmarklet/javascript?url='+_url+'&title='+_title);document.body.appendChild(a);}catch(e){}}

//-------------------------------------------------------------------
// popup.js
//-------------------------------------------------------------------
var PopupTask = '';
var PopupGoTime = 700;
var SearchTag = '';
var WikiTag = '';
var SearchWord = '';
var SearchWordObj = '';
function cbSearch(data) {
  var work = '<div id="popup-win-title">';
  work += '<img src="/common/images/v1/articlenav/closex.gif" alt="close" onclick="hideSearchResultOnBox(event)" /><\/div>\n';
  work += '<div id="popup-win-body-wrapper"><div id="popup-win-body">\n';
  work += '<h5><span class="searchword">';
  work += '[<a href="http://www.ismedia.jp/search/jbp?keyword[]=' + encodeURIComponent(SearchWord) + '" target="_blank">' + SearchWord +'<\/a>]<\/span>の関連記事<\/h5>\n<ul>'
  if (data.length != 0) {
    data.each(function(a){
      work += '\n<li><a href="' + a.url + '" target=\"_blank\">' + a.title + '　' + a.subtitle + '<\/a><\/li>';
    });
  } else {
    work += '\n<li>検索結果なし<\/li>';
  }
  work += '\n<\/ul>\n' + '<span class="more">';
  work += '<a href="http://www.ismedia.jp/search/jbp?keyword[]=' + encodeURIComponent(SearchWord) + '" target="_blank">&gt;&gt;More<\/a><\/span><br clear="all" />\n';
  work += '<div id="wiki"><\/div>'  + '<\/div><\/div>';
  $('popup-win').innerHTML = work;
  SearchTag.remove();
  var url = 'http://wikipedia.simpleapi.net/api?keyword=' + encodeURIComponent(SearchWord) + '&output=json&callback=cbWikiData';
  WikiTag = new OuterScript(url);
}
function cbWikiData(data) {
  var work = '';
  if ((data != null)&&(data.length != 0)) {
    work = '<p>ウィキペディア（Wikipedia）で<br />用語<strong>「' + SearchWord + '」<\/strong>を調べる<\/p>\n<ul>';
    data.each(function(a){
      work += '<li><a href="';
      work += a.url;
      work += '" title="' + a.body.stripTags();
      work += '" target="_blank">' + a.title;
      work += '<\/a><\/li>\n';
    });
    work += '<\/ul>';
  }
  if($('wiki') != undefined){$('wiki').innerHTML = work;}
  WikiTag.remove();
}
function showSearchResultOnBox(event) {
  SearchWordObj = Event.element(event);
  SearchWord = SearchWordObj.innerHTML;
  var offsetTop = SearchWordObj.offsetTop; if (navigator.appVersion.substr(0, 3) == '4.0' ){offsetTop = offsetTop + $('main-contents').offsetTop;}
  var offsetLeft = SearchWordObj.offsetLeft; if (navigator.appVersion.substr(0, 3) == '4.0' ){offsetLeft = SearchWordObj.offsetLeft + 50;}
  if(offsetLeft<450){
    offsetLeft = offsetLeft + 10;
  } else {
    offsetLeft = 450;
  }
  $('popup-win').style.top = offsetTop + 20 + 'px' ;
  $('popup-win').style.left = offsetLeft + 'px';
  $('popup-win').style.display = 'block';

  new Draggable('popup-win',{
    onStart : function(draggable,evt){Event.stopObserving(document,'click',hideSearchResultOnBox);},
    onEnd : function(draggable,evt){$('popup-win').style.display = 'block';}
    }
  );

  $('popup-win').innerHTML = 'loading ...';
  SearchTag = new MWjsonScript('keyword','cbSearch',SearchWord);
  Event.observe(document,'click',function(e){hideSearchResultOnBox(e);},true);
}
function hideSearchResultOnBox(event) {
  $('popup-win').style.display = 'none';
  Event.stopObserving(window,'click',hideSearchResultOnBox);
}
function createSearchMethod() {
  var wordlist = $A(document.getElementsByClassName('popup-word'));
  wordlist.each(function(word){
    Event.observe(word,'mouseover',function(e){PopupTask = showSearchResultOnBox.later(PopupGoTime)(e);},true);
    Event.observe(word,'mouseout',function(e){try{PopupTask.cancel(e);}catch(err){}},true);
    word.style.borderBottom = 'dotted 1px brown';
  });
}

//---------------------------------------------------------------------
//   styleswitcher.js
//---------------------------------------------------------------------
function setActiveStyleSheet(title) {
  var a;
  if ( $('altstylel') != undefined ) {
    a = $('altstylel');
    a.disabled = true;
    if(a.getAttribute('title') == title) a.disabled = false;
  }
  if ( $('altstyles') != undefined ) {
    a = $('altstyles');
    a.disabled = true;
    if(a.getAttribute('title') == title) a.disabled = false;
  }
  var expires = '';
  var domain = '; domain=' + location.hostname;
  var date = new Date();
  date.setTime(date.getTime()+(365*24*60*60*1000));
  expires = '; expires=' + date.toGMTString();
  document.cookie = 'jb-style=' + title + expires + domain + '; path=/';
}
function readCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function initStyleSwitch(){
  if ( $('altstylel') != undefined ) {
   var cookie = readCookie('jb-style');
   var styletype = cookie ? cookie : 'Small';
   setActiveStyleSheet(styletype);
  }
}

//-------------------------------------------------------------------
//    Print Window
//-------------------------------------------------------------------
function printWindow(url,w,h){
  var opt = 'width=' + w + ',height=' + h + 'location=yes,menubar=no,status=no,scrollbars=yes';
  var w = window.open(url,null,opt);
}

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

// -- Utility -----------------------------------------------------------
// FQDNからのメディア略称取得
JBPRESSns.util.getMediaName = function(_fqdn){
 try{
  // ドメイン削除
  var media = _fqdn.replace(/\.ismedia\.jp/,'');
  // 投稿系プレフィックス削除
  media = media.replace(/post\./,'').toUpperCase();
  return media;
 }catch(e){
  return '';
 }
}
// Header Open Close
JBPRESSns.util.toggleHeader = function(){
  $('header1').style.display = Element.getStyle($('header1'),'display')=='none'?'block':'none';
  $('header2').style.display = Element.getStyle($('header2'),'display')=='none'?'block':'none';
  $('column-wrapper').style.display = Element.getStyle($('column-wrapper'),'display')=='none'?'block':'none';
  if(Element.getStyle($('header1'),'display')=='block'){
    $('wrapper').style.backgroundImage = 'url(/common/images/v1/bg1.gif)' ;
  } else {
    $('wrapper').style.backgroundImage = 'url(/common/images/v1/bg2.gif)' ;
  }
}

// -- Class --------------------------------------------------------------
// BODY直下の吹き出し
JBPRESSns.cls.lastBalloon = Class.create({
 // 初期化(対象エレメント,{height:表示後の高さ,just:表示基準の百分率})
 initialize: function(element,options){
  this.options = options||{};	// 引数
  this.element = $(element);	// 吹き出しエレメント
  this.showHeight = this.options['height'];	// 表示後の高さ
  this.just = this.options['just'];	// 表示する基準
  this.posY = Position.cumulativeOffset(this.element)[1];	// 吹き出しエレメントの位置
  this.cover = document[('CSS1Compat' == document.compatMode) ? 'documentElement' : 'body']; //　座標取得の為のオブジェクト確認
  this.eventAppear = this.appear.bindAsEventListener(this);	// イベント
  Event.observe(window,'scroll',this.eventAppear);	// スクロールイベント
 },
 // スクロール位置
 scrollY: function(){return this.cover.scrollTop || window.pageYOffset;},
 // 現在表示領域の百分率
 scaler: function(){return ((this.posY - this.scrollY()) / this.cover.clientHeight) * 100;},
 // バルーン表示
 appear:function(event){
  if (this.scaler() < this.just) {
   this.fix();
   this.element.style.display = 'none';
   this.element.style.visibility='visible';
   this.element.style.height = this.showHeight;
   Effect.Appear(this.element,{delay:0,duration:3});
  }
 },
 // 表示後処理
 fix: function(){
  Event.stopObserving(window,'scroll',this.eventAppear);
  this.element.style.position='relative';	// Chrome対応
 },
 eom:null
});
// 記事中ポップアップボックス
JBPRESSns.cls.popupBalloon = Class.create({
 delay:700,	// マウス通過時の感知ms
 task:null,	// 実行タスク
 options:{},	// 引数
 box:$('popup-win'),	// ポップアップボックス
 // 初期化
 initialize: function(element,options){
  this.options = options||{};   // 引数
  this.element = element;    // wordエレメント
  this.word = this.element.innerHTML;
  this.element.style.borderBottom = 'dotted 1px brown';
  this.posX = Position.cumulativeOffset(this.element)[0];       // popupエレメントのX位置
  this.posY = Position.cumulativeOffset(this.element)[1];       // popupエレメントのY位置
  this.cover = document[('CSS1Compat' == document.compatMode) ? 'documentElement' : 'body']; //　座標取得の為のオブジェクト確認
  this.eventActive = this.active.bindAsEventListener(this);     // イベント
  this.eventInActive = this.inactive.bindAsEventListener(this);     // イベント
  this.eventClose = this.close.bindAsEventListener(this);     // イベント
  Event.observe(this.element,'mouseover',this.eventActive,true);      // スクロールイベント
  Event.observe(this.element,'mouseout',this.eventInActive,true);      // スクロールイベント
  Event.observe(document,'click',this.eventHide,true);      // スクロールイベント
 },
 active:function(event){
  this.task = this.activate().later(this.delay)();
 },
 activate:function(){
  var _e = this;
  return function(){
   var offsetTop = _e.element.offsetTop;
   if (navigator.appVersion.substr(0, 3) == '4.0' ){
    offsetTop = offsetTop + $('main-contents').offsetTop;
   }
   var offsetLeft = _e.element.offsetLeft;
   if (navigator.appVersion.substr(0, 3) == '4.0' ){
    offsetLeft = _e.elementj.offsetLeft + 50;
   }
   if(offsetLeft<450){
    offsetLeft = offsetLeft + 10;
   } else {
    offsetLeft = 450;
   }
   $('popup-win').style.top = offsetTop + 20 + 'px' ;
   $('popup-win').style.left = offsetLeft + 'px';
   $('popup-win').innerHTML = 'loading ...';
   $('popup-win').style.display = 'block';
   SearchTag = new MWjsonScript('keyword','cbSearch',_e.word);
  };
 },
 inactive:function(event){
  try{
   this.task.cancel();
  }catch(e){}
 },
 close:function(event){
 },
 eom:null
});
// タブグループ
JBPRESSns.cls.tabGroup = Class.create({
 delay:300,	// マウス通過時の感知ms
 task:null,	// 実行タスク
 options:{},	// 引数
 activeid:1,	// アクティブインデックス
 beforeid:1,	// アクティブ前インデックス
 // 初期化({tab:タブグループエレメントのIDプレフィックス,detail:同ディテールのIDプレフィックス,coun:タブ数})
 initialize: function(options){
  this.options = options||{};	// 引数
  this.tab = this.options['tab'];	// タブプレフィクス
  this.detail = this.options['detail'];	// ディテールプレフィックス
  this.count = this.options['count']; 	// タブ数
  // タブにイベントセット
  for(var i=1;i<=this.count;i++){
   this.eventActive = this.active.bindAsEventListener(this,i);	// イベント
   this.eventInActive = this.inactive.bindAsEventListener(this);	// イベント
   Event.observe($(this.tab + i),'mouseover',this.eventActive,true);	// マウスオーバイベント
   Event.observe($(this.tab + i),'mouseout',this.eventInActive,true);	// マウスアウトイベント
  }
 },
 // マウスオーバーイベント
 active: function(event){
  if (this.activeid != arguments[1]) {
   this.task = this.activate(arguments[1]).later(this.delay)();
  }
 },
 // アクティブタブに対応するディテールエレメントのBlock化
 activate: function(index){
  this.activeid = index;
  var _e = this; 
  return function(){
   for (var i=1; i<=_e.count; i++){
    $(_e.detail + i).style.display = (i==_e.activeid)?'block':'none';
   }
   _e.activating();
   _e.beforeid = _e.activeid;
  };
 },
 // Active処理のキャンセル
 inactive: function(){
  try{
   this.task.cancel();
   this.activeid = this.beforeid;
  }catch(e){}
 },
 // オーバライド用Active関数
 activating: function(){},
 eom:null
});
// アコーディオンタブグループ
JBPRESSns.cls.acTabGroup = Class.create(JBPRESSns.cls.tabGroup,{
 initialize: function($super,options){
  $super(options);
  this.activeid = this.options['activeid'];
 },
 activating: function(){
  for (var i=1; i<=this.count; i++){
   $(this.tab + i).style.backgroundColor = '';
   if(i==this.activeid) {
    new Effect.Highlight($(this.tab + i),{duration: 0.5});
    $(this.tab + i).className = 'ac-active';
   } else {
    $(this.tab + i).className = 'ac-inactive';
   }
  }
 },
 directactivate: function(index){
  this.activeid = index;
  for (var i=1; i<=this.count; i++){
   $(this.tab + i).style.backgroundColor = '';
   $(this.detail + i).style.display = (i==this.activeid)?'block':'none';
   if(i==this.activeid) {
    new Effect.Highlight($(this.tab + i),{duration: 0.5});
    $(this.tab + i).className = 'ac-active';
   } else {
    $(this.tab + i).className = 'ac-inactive';
   }
  }
  this.beforeid = this.activeid;
 },
 eom:null
});
// TOPフューチャータブグループ
JBPRESSns.cls.featureTabGroup = Class.create(JBPRESSns.cls.tabGroup,{
 initialize: function($super,options){
  $super(options);
  this.linkTab = this.options['linkTab'];
 },
 activating: function(){
  for (var i=1; i<=this.count; i++){
   if(i==this.activeid) {
    new Effect.Opacity($(this.detail + i),{from:0.0,to:1.0,duration:1.0});
    new Effect.Opacity($(this.tab + i),{from:1.0,to:0.4,delay:0.2,duration:0.3});
   } else if (i==this.beforeid){
    new Effect.Opacity($(this.detail + i),{from:0.1,to:0.0,duration:0.1});
    new Effect.Opacity($(this.tab + i),{from:0.4,to:1.0,delay:0.2,duration:0.3});
   }
  }
  var linkIndex = parseInt($('featureS'+this.activeid).className.match(/[0-9]+/i));
  this.linkTab.directactivate(linkIndex);
 },
 eom:null
});
// シンプルタブグループ
JBPRESSns.cls.simpleTabGroup = Class.create(JBPRESSns.cls.tabGroup,{
 initialize: function($super,options){
  $super(options);
  this.bgImagePathPrefix = this.options['bgImagePathPrefix'];
 },
 activating: function(){
  var path = '';
  for (var i=1; i<=this.count; i++){
   path = (i==this.activeid)?'url('+this.bgImagePathPrefix + i + '-b.gif)':'url(' + this.bgImagePathPrefix + i + '-a.gif)';
   // classに媒体プロフィール指定がある場合(1番目のタブだけを想定)
   if ((i==1)&&($(this.tab + i).className == 'prof-type-m')) {
    path = (i==this.activeid)?'url('+this.bgImagePathPrefix + 'M' + i + '-b.gif)':'url(' + this.bgImagePathPrefix + 'M' + i + '-a.gif)';
   }
   $(this.tab + i).style.backgroundImage = path;
  }
 },
 eom:null
});

// -- Callback -----------------------------------------------------------
// 関連記事取得Callback関数
JBPRESSns.cb.keyword = function(_data){
 var work='';           // 一時変数
 var html='';           // 表示用HTML
 var title='';          // タイトル
 var pubdate='';        // 日付
 var thismedia='';      // 閲覧記事メディア
 var media='';          // 関連記事メディア
 var titlelimit = 27;   // タイトル長
 // 返却記事数または最大3件の関連記事リストを作成
 for(var i=0;((i<_data.length)&&(i<=3));i++){
  var a = _data[i];     // 記事データ
  // Title整形
  work = a.title + '　' + a.subtitle;
  work = work.replace(/<\/?[^>]+>/gi,'');
  title = (work.length>titlelimit) ? work.substring(0,(titlelimit-1))+'&hellip;' : work;
  // Date整形
  work = a.publish_at.split(' ')[0];
  pubdate = work.split('/')[0] + '年' + work.split('/')[1] + '月' + work.split('/')[2] + '日';
  // List整形
  // 閲覧記事との同一判定
  if(a.url != location.href.split('?')[0]){
   // 閲覧ホストとの同一判定
   thismedia = JBPRESSns.util.getMediaName(location.host);
   media = JBPRESSns.util.getMediaName(a.url.split('/')[2]);
   if(thismedia != media){
    title = (title.length>(titlelimit-media.length)) ? title.substring(0,((titlelimit-media.length)-1)) + '&hellip;' : title;
    work = '<li><h5><a href="' + a.url + '" title="' + title + '" target="_blank">' + title + '<\/a>';
    work += '<span class="date">　[' + media + '][' + pubdate + ']<\/span><\/h5><\/li>\n';
   } else {
    work = '<li><h5><a href="' + a.url + '" title="' + title + '">' + title + '<\/a>';
    work += '<span class="date">　[' + pubdate + ']<\/span><\/h5><\/li>\n';
   }
  } else {
   work = '<li><h5>' + title + '<span class="date">　[' + pubdate + ']<\/span><\/h5><\/li>\n';
  }
  html += work;
 }
 // HTMLを返却
 return (html != '') ? html : '<li><\/li>';
};
// お薦め記事取得Callback関数(現時点では最新記事)
JBPRESSns.cb.recommend = function(_data){
 var dispspace = 200;	// 表示枠高さ
 var maxdisplay = 2;	// 表示記事件数
 var work='';           // 一時変数
 var html='';           // 表示用HTML
 var title='';          // タイトル
 var anchortitle='';	// アンカータイトル
 var titlelimit = 16;   // タイトル長
 var pubdate='';        // 日付
 var categoryurl='';	// カテゴリURL

 // 表示枠の高さ計算
 if( ($('body-end') != undefined)&&($('subc-end') != undefined) ){
  dispspace = Position.cumulativeOffset($('body-end'))[1] - Position.cumulativeOffset($('subc-end'))[1];
 }

 // 表示件数計算
 if (dispspace>600) {
  maxdisplay = 10;
 } else if (dispspace>500) {
  maxdisplay = 7;
 } else if (dispspace>400) {
  maxdisplay = 7;
 } else if (dispspace>250) {
  maxdisplay = 3;
 }

 // 返却記事数またはmaxdisplay件の記事リストを作成
 for(var i=0;((i<_data.length)&&(i<maxdisplay));i++){
  var a = _data[i];     // 記事データ
  // Title整形
  work = a.title + '　' + a.subtitle;
  work = work.replace(/<\/?[^>]+>/gi,'');
  anchortitle = work;
  title = (work.length>titlelimit) ? work.substring(0,(titlelimit-1))+'&hellip;' : work;
  // Date整形
  work = a.publish_at.split(' ')[0];
  pubdate = work.split('/')[0] + '年' + work.split('/')[1] + '月' + work.split('/')[2] + '日';
  categoryurl =  'http://' + a.url.split('/')[2] + '/category/' + a.category.code;
  // List整形
  html += '<li class="clearfix"><a href="' + categoryurl + '">';
  html += '<img src="' + a.category.img_icons +'" alt="" \/><\/a>';
  html += '<h5>【<a href="' + categoryurl + '">' + a.category.caption + '<\/a>】<br \/>';
  html += '<a href="'+ a.url + '" title="' + anchortitle + '">' + title + '<\/a><br \/>';
  html += '<span class="date"> [' + pubdate + ']<\/span><\/h5><\/li>\n';
 }
 // HTMLを返却
 return (html != '') ? html : '<li><\/li>';
};
// 最新記事リスト
JBPRESSns.cb.latest = function(_data){
 var maxdisplay = 5;    // 表示記事件数
 var work='';           // 一時変数
 var html='';           // 表示用HTML
 var title='';          // タイトル
 var titlelimit = 21;   // タイトル長
 var pubdate='';        // 日付
 var categoryurl='';    // カテゴリURL

 // 返却記事数またはmaxdisplay件の記事リストを作成
 for(var i=0;((i<_data.length)&&(i<maxdisplay));i++){
  var a = _data[i];     // 記事データ
  // Title整形
  work = a.title + '　' + a.subtitle;
  work = work.replace(/<\/?[^>]+>/gi,'');
  title = (work.length>titlelimit) ? work.substring(0,(titlelimit-1))+'&hellip;' : work;
  // Date整形
  work = a.publish_at.split(' ')[0];
  pubdate = work.split('/')[0] + '年' + work.split('/')[1] + '月' + work.split('/')[2] + '日';
  categoryurl =  'http://' + a.url.split('/')[2] + '/category/' + a.category.code;
  // List整形
  html += '<li><span class="rank">';
  html += '【<a href="' + categoryurl + '">' + a.category.caption + '<\/a>】' + '<\/span>';
  html += '<h5><a href="' + a.url + '">' + title  + '<\/a><br \/>';
  html += '<span class="date"> [' + pubdate + ']<\/span><\/h5><\/li>\n';
 }
 // HTMLを返却
 return (html != '') ? html : '<li><\/li>';
};
// 前日ランキング
JBPRESSns.cb.ranking = function(_data){
 var maxdisplay = 5;    // 表示記事件数
 var work='';           // 一時変数
 var html='';           // 表示用HTML
 var title='';          // タイトル
 var titlelimit = 21;   // タイトル長
 var pubdate='';        // 日付
 var categoryurl='';    // カテゴリURL
 var rank = 1;		// 順位

 // 返却記事数またはmaxdisplay件の記事リストを作成
 for(var i=0;((i<_data.length)&&(i<maxdisplay));i++){
  var a = _data[i];     // 記事データ
  rank = i + 1 ;
  // Title整形
  work = a.title + '　' + a.subtitle;
  work = work.replace(/<\/?[^>]+>/gi,'');
  title = (work.length>titlelimit) ? work.substring(0,(titlelimit-1))+'&hellip;' : work;
  // Date整形
  work = a.publish_at.split(' ')[0];
  pubdate = work.split('/')[0] + '年' + work.split('/')[1] + '月' + work.split('/')[2] + '日';
  categoryurl =  'http://' + a.url.split('/')[2] + '/category/' + a.category.code;
  // List整形
  html += '<li><span class="rank"><strong>' + rank + '位<\/strong>　';
  html += '【<a href="' + categoryurl + '">' + a.category.caption + '<\/a>】' + '<\/span>';
  html += '<h5><a href="' + a.url + '">' + title  + '<\/a><br />';
  html += '<span class="date"> [' + pubdate + ']<\/span><\/h5><\/li>\n';
 }
 // HTMLを返却
 return (html != '') ? html : '<li><\/li>';
};

// スキンオンコーディングの為のラッパー
function toggleHeader(){JBPRESSns.util.toggleHeader();}
function SubMenuDirectChange(index){}

// ページロード時処理
Event.observe(window,'load',function(e){
 (function(){
  // JBPRESSクラスネームスペース
  var ns = JBPRESSns.cls; 

  // 共通サイトナビアコーディオンメニュー切替
  var acTab = null;
  if ($('site-navi') != undefined){
   var activeid = 1;	// デフォルト表示メニュー
   // TOPページ featureS1エレメントがある場合の表示メニュー番号
   if ($('featureS1') != undefined){
    activeid = parseInt($('featureS1').className.match(/[0-9]+/i));
   }
   // featureエレメントがある場合の表示メニュー番号
   else if ($('feature') != undefined){
    activeid = parseInt($('feature').className.match(/[0-9]+/i));
   }
   // title-partsエレメントがある場合の表示メニュー番号
   else if ($('title-parts') != undefined){
    activeid = parseInt($('title-parts').className.match(/[0-9]+/i));
   }

   acTab = new ns.acTabGroup({
    tab:'ac',
    detail:'acsub',
    count:$('site-navi').getElementsByClassName('acsub').length,
    activeid:activeid
   });
  }

  // サブコンテンツのタブ切替
  if ($('SCtab1') != undefined){
   new ns.simpleTabGroup({
    tab:'SCtab',
    detail:'SC',
    count:3,
    bgImagePathPrefix:'http://jbpress.ismedia.jp/common/images/v1/SCtab'
   });
  }

  // サブコンテンツのリコメンド
  if ($('subc-end-list') != undefined){
   var recommend = JBPRESSns.cb.recommend;
   recommend['exe'] = function(data){
    $('subc-end-list').innerHTML = recommend(data);
    recommend['tag'].remove();
    delete recommend['tag'];
    delete recommend['exe'];
   };
   recommend['tag'] = new MWjsonScript('latest','JBPRESSns["cb"]["recommend"]["exe"]','');
  }

  // JBpressURL以外でのJSONPによる記事リスト作成
  if (!(location.href.match(/jbpress.ismedia.jp/))) {
   // ランキング
   if ($('SC2') != undefined) {
    var ranking = JBPRESSns.cb.ranking;
    ranking['exe'] = function(data){
     $('SC2').innerHTML = ranking(data);
     ranking['tag'].remove();
     delete ranking['tag'];
     delete ranking['exe'];
    };
    ranking['tag'] = new MWjsonScript('pv_ranking_recently','JBPRESSns["cb"]["ranking"]["exe"]','');
   }

   // 最新記事
   if ($('SC3') != undefined) {
    var latest = JBPRESSns.cb.latest;
    latest['exe'] = function(data){
     $('SC3').innerHTML = latest(data);
     latest['tag'].remove();
     delete latest['tag'];
     delete latest['exe'];
    };
    latest['tag'] = new MWjsonScript('latest','JBPRESSns["cb"]["latest"]["exe"]','');
   }
  }

  // 記事ページの場合
  if ( location.href.match(/articles/) ) {
   // スタイルスイッチ
   initStyleSwitch();

   // 記事プロフィールのタブ切替
   if ($('Dtab1') != undefined){
    new ns.simpleTabGroup({
     tab:'Dtab',
     detail:'cDetail',
     count:3,
     bgImagePathPrefix:'http://jbpress.ismedia.jp/common/images/v1/article/Dtab'
    });
   }

   // 記事中キーワードポップアップ表示
   if ($('popup-win') != undefined){
    createSearchMethod();
/*
    var wordlist = $A(document.getElementsByClassName('popup-word'));
    wordlist.each(function(o){
     new ns.popupBalloon(o);
    });
*/
   }

   // 記事末尾バルーン表示
   if ($('body-end') != undefined){
    new ns.lastBalloon('body-end',{height:'160px',just:80});
   }
  } else {
   // TOPページフューチャタブ切替
   if ($('featureS1') != undefined){
    var fTab = new ns.featureTabGroup({
     tab:'featureSimg',
     detail:'featureL',
     count:3,
     linkTab:acTab	// アコーディオンメニューとの連携
    });
    fTab.activating();
   }

   // TOPページ中央のラージタブ切替
   if ($('Ltab1') != undefined){
    new ns.simpleTabGroup({
     tab:'Ltab',
     detail:'Lindex',
     count:3,
     bgImagePathPrefix:'http://jbpress.ismedia.jp/common/images/v1/top/tab'
    });
   }

   // カテゴリートップ中央のラージタブ切替
   if ($('cLtab1') != undefined){
    new ns.simpleTabGroup({
     tab:'cLtab',
     detail:'cLindex',
     count:2,
     bgImagePathPrefix:'http://jbpress.ismedia.jp/common/images/v1/article/tab'
    });
   }
  }
 })();
},true);

