﻿/* ------------------------------------------------------------ */
/*                                                              */
/*                         global param                         */
/*                                                              */
/* ------------------------------------------------------------ */

var _loc      = location.pathname;
var _host     = location.host;
var _pathName = _loc.substring(0,_loc.lastIndexOf('/')+1);
var _fileName = _loc.substring(_loc.lastIndexOf('/')+1);
var _swfAry   = new Array();
var _parental = (_host.indexOf('perfectchoice')>-1)?1:0;
var _parental = (_host.indexOf('perfectchoice')>-1)?1:1;





/* ------------------------------------------------------------ */
/*                                                              */
/*                       import libraries                       */
/*                                                              */
/* ------------------------------------------------------------ */

document.write('<script type="text/javascript" src="/_global/js/core/swfobject.js"></script>');
document.write('<script type="text/javascript" src="/_global/js/lib/iepngfix/iepngfix_tilebg.js"></script>');
document.write('<script type="text/javascript" src="/_global/js/lib/jquery.newsticker.js"></script>');
document.write('<script type="text/javascript" src="/_global/js/lib/jquery.cookie.js"></script>');
document.write('<script type="text/javascript" src="/_global/js/lib/thickbox/thickbox.js"></script>');
document.write('<link rel="stylesheet" type="text/css" href="/_global/js/lib/thickbox/thickbox.css" media="screen" />');

document.write('<script type="text/javascript" src="//t8.aqtracker.com/asp/aq_tag2.js"></script>');





/* ------------------------------------------------------------ */
/*                                                              */
/*                           RT send                            */
/*                                                              */
/* ------------------------------------------------------------ */

function RT_Send(category,id) {
  switch (_pathName.split('/').length) {
    case 2:  type = "top"; break;
    case 3:  type = "genre_top"; break;
    default: type = "detail"; break;
  }
  type = (_pathName.split('/')[1] == 'video') ? 'video_list' : type;
  aqtracker_event('flv.html?flv=' + id + '&type=' + type);
}





/* ------------------------------------------------------------ */
/*                                                              */
/*         legacy functions for backward compatibility          */
/*                                                              */
/* ------------------------------------------------------------ */

function openWin(url) {
  var nWin;
  nWin=window.open(url);
  nWin.window.focus();
}





/* ------------------------------------------------------------ */
/*                                                              */
/*                          initialize                          */
/*                                                              */
/* ------------------------------------------------------------ */

try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}  // ie6 background-image reload issue

var $j = jQuery.noConflict();

$j(function($){

  // nav_global : set current ------------------------------------------------------------
  if (_host.indexOf('sukachan')>-1)      $('li.suka a').addClass('current');
  if (_host.indexOf('perfectchoice')>-1) $('li.pcex a').addClass('current');
  if (_host.indexOf('sptvbroadcast')>-1) $('li.spbc a').addClass('current');
  if (_host.indexOf('nankan-tv')>-1) $('li.nktv a').addClass('current');

  // parental control message for ADULT / EROS / TOPLESS -------------------------------------------
  if (_parental) $.fn.parental();

  // program list for ADULT -------------------------------------------
  if ($('body#adult div#proglist').size()) $.fn.proglistAdvanced();
  
  // module : frame -------------------------------------------
  $('.module_head').before('<div class="frm_head_t"><div class="frm_head_tl"></div><div class="frm_head_tr"></div></div>').after('<div class="frm_head_b"><div class="frm_head_bl"></div><div class="frm_head_br"></div></div>').wrap('<div class="frm_head_l"><div class="frm_head_r"></div></div>');
  $('.module_body').before('<div class="frm_body_t"><div class="frm_body_tl"></div><div class="frm_body_tr"></div></div>').after('<div class="frm_body_b"><div class="frm_body_bl"></div><div class="frm_body_br"></div></div>').wrap('<div class="frm_body_l"><div class="frm_body_r"></div></div>');
  $('.mod_default > .frm_head_b + .frm_body_t, .mod_idol > .frm_head_b + .frm_body_t, .mod_pop > .frm_head_b + .frm_body_t, .mod_pop2 > .frm_head_b + .frm_body_t, .mod_red > .frm_head_b + .frm_body_t, .mod_blue > .frm_head_b + .frm_body_t, .mod_howto_skyp > .frm_head_b + .frm_body_t, .mod_howto_e2 > .frm_head_b + .frm_body_t').hide();

  // button : image -------------------------------------------
  $('a.button').append('<span>&nbsp;</span>').wrap('<div class="button centered"></div>');
  $('a.button_s').append('<span>&nbsp;</span>').wrap('<div class="button_s centered"></div>');

  // shadow : image -------------------------------------------
  $('.shadow').parent('a').wrap('<div class="shadowWrap"></div>').each(function(){
    $(this).parent('.shadowWrap').width($(this).width());
  });

  // anchor ------------------------------------------------------------
  $('a.more').append('<img src="/_global/css/img/arrow.png" width="13" height="13" alt="" />');

  // list -------------------------------------------
  $('.list li:last-child, dl.inline dt:first-child, dl.inline > dd:first, dl.staff > dd:first, dl.dt_platform > dd:first').addClass('last');
  $('ol.ranking li').each(function(j){
    $(this).children('a').before('<span style="float: left; width: 14px; margin-left: -14px; text-align: center; color: #fff; font-size: 10px; font-weight: normal;">'+(j+1)+'</span>');
  });

  // _blank window -----------------------------------------------------
  $('a.blank, area.blank').click(function(){ window.open(this.href, '_blank'); return false; });

  // Search Text Label -------------------------------------------
  swapValues = [];
  $('.swap_value').each(function(i){
    swapValues[i] = $(this).val();
    $(this).focus(function(){
      if ($(this).val() == swapValues[i]) $(this).val("");
    }).blur(function(){
      if ($.trim($(this).val()) == "") $(this).val(swapValues[i]);
    });
  });

  // current menu -------------------------------------------
  if(_pathName.split('/')[1]) {
    $('ul.nav_category li.' + _pathName.split('/')[1]+' a').addClass('current');
  } else {
    $('ul.nav_category li.home a').addClass('current');
  }
  if (_fileName.indexOf('sitemap')>-1)      $('ul.nav_category li.sitemap a').addClass('current');

  // centerd ------------------------------------------------------------
  $('.centered').each(function(j){
    var marginL = ($(this).parent().width() - $(this).width())/2;
    $(this).css({'margin-left':marginL+'px'});
  });

  // multi-column -------------------------------------------
  $.fn.setColumn();

  // flash player ------------------------------------------------------------
  $('.flvplayer, .flvplayer_280').click(function(){
    _swf({type:$(this).attr('class'),flv:this.rel});
    tb_show(null,'#TB_inline?height=380&width=620&inlineId=flvPlayerHolder',false);
    this.blur();
    return false;
  });
  $('.flvplayer_480').click(function(){
    _swf({type:'flvplayer_480',flv:this.rel});
    tb_show(null,'#TB_inline?height=430&width=620&inlineId=flvPlayerHolder',false);
    this.blur();
    return false;
  });

  // news ticker ------------------------------------------------------------
  $('.ticker').newsticker();

  // timetable (w/cookie) ------------------------------------------------------------
  if ($('body#time').size()) {
    $.each(document.cookie.split(';'), function(i, cookie) {
      var c = $.trim(cookie), name = c.split('=')[0], value = c.split('=')[1];
      if (String(name).length>3) {
        $(name).hide();
        $('#nav_ttch ul li input#cb_'+name.substr(1)).attr('checked',false);
      }
    });
    $.fn.timetableColumns();
    
    $('#nav_ttch ul li input:checkbox').click(function(){
      var targId = $(this).attr('value');
      if ($(this).attr('checked')) {
        $.cookie(targId,null,{path: '/'});
        $(targId).show();
      } else {
        $.cookie(targId,1,{expires: 365, path: '/'});
        $(targId).hide();
      }
      $.fn.timetableColumns();
    });
  }

});




/* ------------------------------------------------------------ */
/*                                                              */
/*                        multi column                          */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    setColumn: function() {
      $.each(['col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12','col13','col14','col15','col16','col17','col18','col19','col20','col21','col22','col23','col24','col25'], function(i, targ) {
        var targ  = '.' + targ;
        var N     = i+2;
        if ($(targ).size()) {
          $(targ).each(function(){
            var targW = $(this).width();
            $(this).children('li').width(Math.floor(targW/N));
            $(this).children('li:last').width(targW - (Math.floor(targW/N)*(N-1)));
            $(this).children('li.double').width(Math.floor(targW/N)*2);
          });
        }
      });
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*     parental control message for ADULT / EROS / TOPLESS      */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    parental: function() {
      var _dirAry = _pathName.split('/');
      if (_dirAry[1] == 'adult') {
        if ($.cookie('parental')>=20) { hideParentalMask(); return null; }
        $.fn.showParentalMsg(20,'adult');
      }
      if (_dirAry[1] == 'eros') {
        if ($.cookie('parental')>=18) { hideParentalMask(); return null; }
        $.fn.showParentalMsg(18,'eros');
      }
      if (_dirAry[1] == 'toplessfile') {
        if ($.cookie('parental')>=18) { hideParentalMask(); return null; }
        $.fn.showParentalMsg(18,'toplessfile');
      }
      if ((_dirAry[1] == 'video')&&(_parental)) {
        if ($.cookie('parental')>=18) { hideParentalMask(); return null; }
        $.fn.showParentalMsg(18,'videohd');
      }
      if ((_dirAry[1] == 'hd')&&(_parental)) {
        if ($.cookie('parental')>=18) { hideParentalMask(); return null; }
        $.fn.showParentalMsg(18,'videohd');
      }
      if ((_dirAry[1] == 'idol')&&(_parental)&&($('body.r15').size()<1)) { hideParentalMask(); }
      if ((_parental)&&$('body.r15').size()) {
        if ($.cookie('parental')>=15) { hideParentalMask(); return null; }
        $.fn.showParentalMsg(15,'videohd');
      }
    },
    showParentalMsg: function(type,mesType) {
      switch (mesType) {
        case 'adult':       modalTitle = '<img src="/adult/img/h1_age_limit.jpg" alt="パーフェクト チョイスの成人向けプログラム" width="281" height="87" />'; break;
        case 'eros':        modalTitle = '<img src="/eros/img/h1_age_limit.jpg" alt="視聴年齢制限付きオリジナルビデオ（R-18）エロスシネマ" width="390" height="92" />'; break;
        case 'toplessfile': modalTitle = '<img src="/toplessfile/img/h1_age_limit.jpg" alt="解禁！トップレス☆ファイル" width="510" height="70" />'; break;
        case 'videohd':     modalTitle = '<img src="/video/img/h1_age_limit.png" alt="これより先は、視聴年齢制限付きコンテンツです" width="390" height="34" />'; break;
      }
      var msg = '<div class="module mod_prompt" style="width: 620px; display: hidden; position: absolute;">' +
                '<div class="module_head"><h1>' + modalTitle + '</h1></div>' + 
                '<div class="module_body"><p><img src="/_global/img/icon_stop.png" alt="" class="left icon_stop" />ここから先は、'+type+'歳未満の方の閲覧はご遠慮いただいております。</p>' + 
                '<p><strong class="strong">あなたは'+type+'歳以上ですか？</strong></p>' + 
                '<ul class="col2"><li class="column"><a class="button_s modalYes">はい</a></li><li class="column"><a class="button_s modalNo">いいえ</a></li></ul></div></div>';
      $('#modalBox').append(msg);
      $('.modalYes').click(function(){setParantal(type)});
      $('.modalNo').click(function(){setParantal(0)});
      tb_show('modal','#TB_inline?height=320&width=640&inlineId=modalBox&modal=true',false);
    }
  });
})(jQuery);

function setParantal(flag) {
  if (flag>0) {
    tb_remove();
    hideParentalMask();
    $j.cookie('parental',flag,{expires: 1, path: '/'});
  } else {
    location.href = '/';
  }
}
function hideParentalMask() {
  $j('#parentalMask').css({'display':'none'});
}






/* ------------------------------------------------------------ */
/*                                                              */
/*                      Flash  -  SWFObject                     */
/*                                                              */
/* ------------------------------------------------------------ */
// <div id="swf1Holder"></div>
// <script type="text/javascript">_swf({type:'nba'});</script>

function _swf(obj) {
  if (typeof obj == 'undefined') return null;

  switch (obj.type) {
    case 'countdown':
      prm = {w:172,h:97,id:"swf2",swf:"/swf/countdown_std_"+obj.pid+".swf",param:"_pid="+obj.pid+"&_path=/api/onair.php"}; break;
    case 'flvplayer':
      prm = {w:575,h:332,id:"flvPlayer",swf:"/swf/fp.swf",param:"_v=Fp&_flv="+obj.flv, wmode:"transparent"}; break;
    case 'flvplayer_280':
      prm = {w:575,h:332,id:"flvPlayer",swf:"/swf/fp_280.swf",param:"_v=Fp&_flv="+obj.flv, wmode:"transparent"}; break;
    case 'flvplayer_480':
      prm = {w:575,h:425,id:"flvPlayer",swf:"/swf/fp_480.swf",param:"_v=Fp&_flv="+obj.flv, wmode:"transparent"}; break;
    case 'simpleplayer':
      prm = {w:obj.w, h:obj.h, id:"flvPlayer",swf:"/swf/sfp.swf",param:"_v=Fp&_flv="+obj.flv+"&_loop="+obj.loop, wmode:"transparent"}; break;
  }

  /* --- case of undefined --- */
  if (!prm.v)      prm.v      = 8;
  if (!prm.bg)     prm.bg     = '#ffffff';
  if (!prm.scale)  prm.scale  = 'noscale';
  if (!prm.salign) prm.salign = 'TL';

  var so = new SWFObject(prm.swf, prm.id, prm.w, prm.h, prm.v, prm.bg);

  /* --- add param --- */
  so.addParam('scale',  prm.scale);
  so.addParam('salign', prm.salign);
  if (prm.wmode == 'transparent') {
    so.addParam('wmode', prm.wmode);  // Japanese IME & Scroll Wheel issue
  }

  /* --- add variable --- */
  if (prm.param) { var pAry=prm.param.split('&'); for (var i=0;i<pAry.length;i++) {var a=pAry[i].split('='); so.addVariable(a[0],a[1]);} };
  if (location.search) { var sAry=location.search.substr(1).split('&'); for (var i=0;i<sAry.length;i++) {var a=sAry[i].split('='); so.addVariable(a[0],a[1]);} };
  so.addVariable('_pathName', _pathName);
  so.addVariable('_id', prm.id);

  /* --- marginFix & write --- */
  so.setAttribute('style', ';');
  so.write(prm.id+'Holder');
}


// swf sizer ------------------------------------------------------------
var _size = function(id,w,h) {
  $j('#'+id).width(w).height(h);;
}




/* ------------------------------------------------------------ */
/*                                                              */
/*                              MISC                            */
/*                                                              */
/* ------------------------------------------------------------ */

// Thickbox Window Close ------------------------------------------------------------
function close() {
  tb_remove();
}
