// -----------------------------------------------------------------------
// set_Height
// -----------------------------------------------------------------------

(function(A){A.fn.set_height=function(P){var G={items_per_row:false,one_height:false,delay:1000,group_by_parent:false};if(P){jQuery.extend(G,P)}if(A("#js_etalon").length){var N=A("#js_etalon").get(0)}else{var N=A("body").append('<span style="position:absolute;left:-9999px;top:0;" id="js_etalon">&nbsp;</span>').find("#js_etalon").get(0)}var E=function(S,R){for(var Q=0;Q<S.length;Q++){if(S[Q]==R){return }}S.push(R)};var B=this;var F=[];var L=[];var K=[];var J=function(){for(var S=0;S<F.length;S++){var R=0;var T=F[S][0].currentStyle?parseInt(F[S][0].currentStyle.paddingTop)+parseInt(F[S][0].currentStyle.paddingBottom):parseInt(document.defaultView.getComputedStyle(F[S][0],null).getPropertyValue("padding-top"))+parseInt(document.defaultView.getComputedStyle(F[S][0],null).getPropertyValue("padding-bottom"));for(var Q=0;Q<F[S].length;Q++){F[S][Q].style.height="auto";R=Math.max(F[S][Q].offsetHeight-T,R)}for(var Q=0;Q<F[S].length;Q++){F[S][Q].style.height=R+"px"}}};var M=function(){var Y=0;var W=0;var Q=null;var T=null;F[Y]=[];var Z=false;for(var U=0;U<B.length;U++){if(G.group_by_parent){Q=A(B[U]).parents(G.group_by_parent)[0];if(U>0&&Q!=T&&!Z){F[++Y]=[];W=0}T=Q}if(G.items_per_row){B[U].className+=" nb"+parseInt(W%G.items_per_row+1);if(!(W%G.items_per_row)&&W>0){F[++Y]=[];W=0;Z=true}}F[Y][W++]=B[U];Z=false}for(var U=0;U<F.length;U++){if(!F[U][0].offsetHeight){var X=F[U][0];while(X.style.display!="none"){X=X.parentNode}L.push(X)}for(var S=0;S<F[U].length;S++){var V=F[U][S].getElementsByTagName("img");for(var R=0;R<V.length;R++){E(K,V[R].src)}}}};if(B.length){M();var D=N.offsetHeight;var C=setInterval(function(){var S=N.offsetHeight;if(S!=D){D=S;J()}for(var R=0;R<L.length;R++){if(L[R].style.display!="none"){J();L=[];for(var Q=0;Q<F.length;Q++){if(!F[Q][0].offsetHeight){var T=F[Q][0];while(T.style.display!="none"){T=T.parentNode}L.push(T)}}}}},G.delay);J();if(K.length){var H=[];var O=0;for(var I=0;I<K.length;I++){H[I]=document.createElement("img");H[I].onload=function(){O++;if(O==K.length){J()}};H[I].src=K[I]}}}if(navigator.userAgent.match("MSIE 5.5")&&B.length){setTimeout(function(){main(B),0})}return this}})(jQuery);

// -----------------------------------------------------------------------
// set_rollovers
// -----------------------------------------------------------------------

(function(a){jQuery.fn.set_rollovers=function(b){var c={extension:"_o.",hover_extension:"_h.",menu:{}};if(b){jQuery.extend(c,b)}var e=document.location.pathname;var d=false;a.each(c.menu,function(f){if(e.match(new RegExp("^"+f))){d=c.menu[f]}});return this.filter(function(f){return a(this).attr("src").match(c.extension)}).each(function(){var f=new Image;f.src=this.src.replace(c.extension+".",c.hover_extension+".");if(this.src.match(/[^\/]+$/)[0]==d){this.src=this.src.replace(new RegExp(c.extension+"(.[a-z]+)$"),c.hover_extension+"$1")}else{if(this.parentNode.nodeName.match(/a/i)){a(this).parent().focus(function(){a(this).find(">img").trigger("mouseover")}).blur(function(){a(this).find(">img").trigger("mouseout")})}a(this).mouseover(function(){this.src=this.src.replace(new RegExp(c.extension+"(.[a-z]+)$"),c.hover_extension+"$1")}).mouseout(function(){this.src=this.src.replace(c.hover_extension,c.extension)})}})}})(jQuery);


// SSI 代用 include コンテンツロード
// -----------------------------------------------------------------------
$(function() {
    function setSync(uri, selector, method) {
        $.ajax({
            async    : false, 
            type     : 'get',
            url      : uri,
            dataType : 'html',
            success  : function(data) {
                $(selector)[method](data);
            }
        });
    }

    setSync('/shared/includes/footer_nav.html', '#footer', 'prepend');
});

// 画像置換（rollOver）
// -----------------------------------------------------------------------
$('img,input[type="image"]').set_rollovers();

// アイコン付与
// -----------------------------------------------------------------------
$('a[target$="blank"]').not('a[href$=".pdf"],:has(img),.no-icon').append('<img src="/shared/images/icon_blank.gif" alt="新規ウィンドウで開く" width="11" height="10" class="icon" />');
$('a[href$=pdf]').not(':has(img),.no-icon,.list-btn-01 > li > a').before('<img src="/shared/images/icon_pdf.gif" alt="PDF" width="18" height="18" class="icon-pdf" />');

// Set LastChild
// -----------------------------------------------------------------------
/*IE用にlast-child補助*/
$(document).ready(function(){
	if(!jQuery.support.opacity){
	$('.nav-utility > li:last-child , .nav-utility-02 > li:last-child , #subContent > .bnr-list-01 > li:last-child , #subContent > .list-btn-01 > li:last-child').addClass('last');
}
});

// IE6・7用　改行されるインライン要素に背景画像
// -----------------------------------------------------------------------
$.fn.extend({
  inlineBgFix: function() {
    if ($.browser.msie && $.browser.version < 8.0) {
      $(this)
        .append('<span class="link-arrow">&nbsp;</span>');
    }
  }
});

$(function() {
  $('.list-link-01 > li > a , .list-link-01 > li > strong > a').not('#localNav > li > .localNav-inner > .list-link-01 > li > a').inlineBgFix();
});

// 高さ制御（setHight）
// -----------------------------------------------------------------------
$('ul.col2 > li').set_height({ items_per_row:2, group_by_parent: 'ul.col2' });
$('ul.col3 > li').set_height({ items_per_row:3, group_by_parent: 'ul.col3' });
$('div.col2.box > .segment').set_height({ items_per_row:2, group_by_parent: 'div.col2' });
$('div.col3.box > .segment').set_height({ items_per_row:3, group_by_parent: 'div.col3' });
$('div.col2.nav > .segment').set_height({ items_per_row:2, group_by_parent: 'div.col2' });
$('div.col2 > .segment > .box-lay-01').set_height({ items_per_row:2, group_by_parent: 'div.col2' });
$('div.col2 > .segment > .box-universal-01').set_height({ items_per_row:2, group_by_parent: 'div.col2' });
$('div.col3 > .segment > .box-universal-01').set_height({ items_per_row:3, group_by_parent: 'div.col3' });
$('div.col3 > .segment > .hdg2-01 > span').set_height({ items_per_row:3, group_by_parent: 'div.col3' });
$('div#mainContent ul.list-btn-01 > li > a').set_height({ items_per_row:3, group_by_parent: 'ul.list-btn-01' });
$('table.tbl-description-01 > tbody > tr > *').set_height({ items_per_row:2, group_by_parent: 'table.tbl-description-01' });
$('div.laycol > div.segment > .box-universal-03 > .box-universal-03-inner').set_height({ items_per_row:2, group_by_parent: 'div.laycol' });
$('.box-step-01 > .box-universal-01 > .box-lay-01.lpos > *').set_height({ items_per_row:2, group_by_parent: '.box-step-01' });
$('div.col3 > .segment > .equalize').set_height({ items_per_row:3, group_by_parent: 'div.col3' });

// プレースホルダー
// -----------------------------------------------------------------------
function init_placeholder(){
    // 要素が存在しない場合は終了する
    if(!$('input.keyword').length) return;

    // 対象をキャッシュ
    var $query = $('input.keyword');

    $query.each(function(){
        // title属性を取得
        var $title = $(this).attr('title');

        // submitボタンをキャッシュ
        var $btn = $(this).siblings('input.search');

        // valueにtitle属性を代入して、文字色用classを付加
        $(this).val($title).addClass('notentered');

        $(this).focus(function(){
            $(this).removeClass('notentered');
            if(this.value === $title){
                $(this).val('');
            }
        }).blur(function(){
            if(this.value === ''){
                $(this).val($title).addClass('notentered');
            }
        });

        // 送信時にデータが無い場合は、プレースホルダーを空にする
        $btn.click(function(){
            if($(this).siblings('input.keyword').val() === $title){
                $(this).siblings('input.keyword').val('');
            }
        });
    });
}

$(function(){
    // プレースホルダーを実行
    init_placeholder();
});

// ナビゲーション
// -----------------------------------------------------------------------
(function() {
var gNav = $('#globalNav > div > ul');
var lNav = $('#localNav');


var condIndex = /\/index\.html?/;                     
var path = location.pathname.replace(condIndex, '/'); 
var path2 = location.pathname.replace(condIndex, '/'); 

var pathArr = [path];
while (path && '/' !== path) {
path = path.replace(/[^/]*\/?$/, '');
pathArr.push(path);
}

var gHrefs = $('a', gNav).map(function(){
return $(this).attr('href').replace(condIndex, '/');
});
var lHrefs = $('a', lNav).map(function(){
return $(this).attr('href').replace(condIndex, '/');
});

var j = 0;
while (j <= lHrefs.length) {
if (path2 === lHrefs[j]) {
$('a', lNav).eq(j).addClass('current'); break;
}
if(j == lHrefs.length){
var i = 0;
while(i<pathArr.length) {
var z = 0;
while (z<lHrefs.length) {
if (pathArr[i] === lHrefs[z]) {
$('a', lNav).eq(z).addClass('current'); break;
}z++;
}i++;
}
}j++;
}

if(pathArr[0] ==='/'){
$('a', gNav).eq(0).addClass('current');	
}else{
var i = 0;
while(i<pathArr.length) {
var k = 0;
while (k<gHrefs.length) {
if(pathArr[i] === '/'){
break;
}else if (pathArr[i] === gHrefs[k]) {
$('a', gNav).eq(k).addClass('current');	break;
}k++; 
}i++;
}
}

var gpath = location.pathname;
    if(gpath.match(/\/index.html/)){
        gpath = gpath.replace("/index.html", "/");
    }
$('a', lNav).each(function(){
        if($(this).attr("href").match(/\/index.html/) && !$(this).attr("href").match(/\/\/index.html/)){
            this.href = this.href.replace("/index.html", "/");
        }
    });
var folders = gpath.split("/");
var cur_folder = "";
var pathmatch = 0;
for(var i=folders.length; i>=2; i--){
	cur_folder = folders[i];
	var gpath2 = gpath.replace(folders[i], "").replace(/(\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)$/, "/");
	if(pathmatch==0){
		$('a[href$="'+gpath2+'"]', lNav).each(function(){
			$(this).addClass("current");
			pathmatch++;
		});
	}
}
//以下自動で判定できないページを追記
if(
(gpath == "/expsub/")||
(gpath == "/expsub/ex_signup_business.html")||
(gpath == "/expsub/ex_signup_individual.html")||
(gpath == "/expsub/familylink_business.html")||
(gpath == "/expsub/correspondence.html")||
(gpath == "/expsub/ex_charge.html")||
(gpath == "/expsub/ex_nps.html")||
(gpath == "/expsub/ex_np1.html")||
(gpath == "/expsub/ex_np2.html")||
(gpath == "/expsub/ex_np3.html")||
(gpath == "/expsub/ex_wm1.html")||
(gpath == "/expsub/ex_wm2.html")||
(gpath == "/expsub/ex_wm3.html")||
(gpath == "/expsub/ex_mm1.html")||
(gpath == "/expsub/ex_mm2.html")||
(gpath == "/expsub/ex_mm3.html")||
(gpath == "/expsub/ex_ed1.html")||
(gpath == "/expsub/ex_ed2.html")||
(gpath == "/expsub/ex_ed3.html")||
(gpath == "/expsub/ex_shinken1.html")||
(gpath == "/expsub/ex_shinken2.html")||
(gpath == "/expsub/ex_hanamaru.html")||
(gpath == "/expsub/ex_dorazemi.html")||
(gpath == "/expsub/ex_tariffbook.html")||
(gpath == "/expsub/contact.html")||
(gpath == "/impsub/")||
(gpath == "/impsub/im_charge.html")
){
	$('a[href$="/lifesupport/"]').addClass("current");
}

if(
(gpath == "/products/")||
(gpath == "/products/flow.html")||
(gpath == "/products/allex.html")||
(gpath == "/trackings/search.html")
){
	$('a[href$="/express/"]').addClass("current");
}

if(
(gpath == "/products/")||
(gpath == "/products/flow.html")
){
	$('a[href$="/products/allex.html"]').addClass("current");
}

$('a.current').parents('li').addClass('selected');
$('>li.selected > ul > li.selected > a.current', lNav).parent('li.selected').parent('ul').parent('li.selected').addClass('reload');

if(
(gpath == "/aboutocs/office_ajia-pacific.html")||
(gpath == "/aboutocs/office_america.html")||
(gpath == "/aboutocs/office_eu-africa.html")
){
	$('a[href$="/aboutocs/office_overseas.html"]').addClass("current").parents('li').addClass("selected").parents('ul').css('display', 'block');
}

if(
(gpath == "/trackings/search.html")||
(gpath == "/express/cl_service.html")||
(gpath == "/express/cl_agreement.html")||
(gpath == "/express/office.html")||
(gpath == "/express/co_cwb.html")||
(gpath == "/express/co_inv.html")||
(gpath == "/express/co_yakkan.html")||
(gpath == "/express/insurance.html")||
(gpath == "/express/fuelsurcharge-old.html")
){
	$('a.current').parents('li').removeClass('selected');
}

if(
(gpath == "/express/office.html")||
(gpath == "/express/co_cwb.html")||
(gpath == "/express/co_inv.html")||
(gpath == "/express/co_yakkan.html")||
(gpath == "/express/insurance.html")
){
	$('a[href$="/express/co_notice.html"]').parents('li').addClass("selected");
}

if(
(gpath == "/express/fuelsurcharge-old.html")
){
	$('a[href$="/express/fuelsurcharge.html"]').addClass("current").parents('li').addClass("selected");
}

})();

