MJL.event.add(window, "load", function() {
// MJL に関係するコードはこの中に記述
	MJL.enable.rollover("roll", {disable : "unroll", active : "active"});
	MJL.enable.tab("tabs");
	MJL.enable.window("popup01", {width: 755, height: 640, menubar: "no", toolbar: "no", location: "no"});
	MJL.enable.window("popup02", {width: 650, height: 500, menubar: "no", toolbar: "no", location: "no"});
	MJL.enable.heightEqualizer("equalize");
	MJL.enable.heightEqualizer("lay-col2-01",{
		groupBy:2,
		collect:function(parent) {
			return MJL.getElementsByClassName(parent, "parallel");
		}
	});
	MJL.enable.heightEqualizer("lay-col2-01",{
		groupBy:2,
		collect:function(parent) {
			return MJL.getElementsByClassName(parent, "haeding");
		}
	});
	MJL.enable.heightEqualizer("lay-col3-01",{
		groupBy:3,
		collect:function(parent) {
			return MJL.getElementsByClassName(parent, "parallel");
		}
	});
	MJL.enable.heightEqualizer("lay-col3-01",{
		groupBy:3,
		collect:function(parent) {
			return MJL.getElementsByClassName(parent, "haeding");
		}
	});
	MJL.enable.heightEqualizer("list-step-02",{
		groupBy:3,
		collect:function(parent) {
			return MJL.getElementsByClassName(parent, "box-content-01");
		}
	});
	MJL.enable.heightEqualizer("box-col4-01",{
		groupBy:4,
		collect:function(parent) {
			return parent.getElementsByTagName("div");
		}
	});
	MJL.enable.heightEqualizer("box-col3-01",{
		groupBy:3,
		collect:function(parent) {
			return parent.getElementsByTagName("div");
		}
	});
	MJL.enable.heightEqualizer("box-mylife-01",{
		groupBy:3,
		collect:function(parent) {
			return MJL.getElementsByClassName(parent, "col");
		}
	});
});
// MJL.enable.window で area 要素も対象に含める
if("MJL" in window){
	MJL.Window.prototype._TYPES.area = MJL.Window.prototype._TYPES.a;
};



// MJL と無関係なコードはこの先に記述

/**
 * jQuery setGlobalMenuActive plugin
 * グローバルナビゲーション現在地表示の自動化処理
 */
(function($){
	var name_space = 'setGlobalMenuActive';
	$.fn[name_space] = function(){
	var bodyId = $(document.body).attr('id');
	$('#nav-global li').each(function(){
		var gnavClass = $(this).attr('class');
		if (bodyId == gnavClass) {
			$(this).children().addClass("current");
		};
	});
	return this;
	};
})(jQuery);

/**
 * jQuery setLocalMenuActive plugin
 * ローカルナビゲーションの現在地表示
 */
(function($){
	var name_space = 'setLocalMenuActive';
	$.fn[name_space] = function(){
			$('#nav-local dl dd ul li ul').hide();
		var elements = $(this);
		var pagePath = location.pathname.replace('index.html','').split('#')[0];
			/* 例外処理 */
			if(pagePath.match("/(annai/news_release|information|english/news_release)/[0-9]+\.html")){ //ニュース系
				pagePath=pagePath.replace(/\/([0-9]{4}).+\.html/,"/$1.html")
			}else if(pagePath.match("/service/support/(bill_c-store|bill_b-transfer|bill_a-transfer)\.html")){ //料金の請求について詳細ページ
				pagePath='/service/support/view_bill.html';
			};
		function get(){
			return function(){
				var href = $(this).attr('href').replace('index.html','');
				if(pagePath == href){
					if($(this).parent().is('li')){
						$(this).parent('li').addClass('current');
						$(this).parent('li').children('ul').show();
						$(this).parent('li').parent('ul').show();
						$(this).parent('li').parent('ul').parent('li').addClass('active');
					};
				};
			};
		};
		elements.each(get());
		return this;
	};
})(jQuery);

/**
 * jQuery setImgParallelStyler plugin
 * 画像下のキャプションの横幅自動調整
 */
(function(b){var a="setImgAndCaptionStyler";b.fn[a]=function(c){var d=b(this);function e(){return function(){var h=b(this);var f=b("img",h);function g(){var j=f.width();var i=b(">span.caption",h);if(j){i.css("width",j)}}g();f.load(function(){g()})}}d.each(e());return this}})(jQuery);


/**
 * jQuery setImgFocusChenge plugin
 * 商品画像のフォーカス切り替え
 */
(function($){
	var name_space = 'setImgFocusChenge';
	$.fn[name_space] = function(){
	$(function () {
		//拡大するボタンとのリンクの連携
		$("ul","#gallery").children().each(function (i) {
			$('a',this).attr('rel','gallery');
			function setchenge() {
				if ( Number(i) < 4 ) var num = (i+1);
				else num = i+1;
				
				var linkHref = $(this).attr('href'),
				    imgTag = $(this).parent().parent().siblings("p").children("img"),
				    expansionTag = $(this).parent().parent().siblings("p").children(".expansion").children("a");
				imgTag.attr("src",linkHref);
				expansionTag.attr("href",linkHref);
				
				$(this).parent().siblings().removeClass('active');
				$(this).parent().addClass('active');
			};
			$('a',this).hover(setchenge);
			$('a',this).focus(setchenge);
		});
		
		//拡大するボタンとのギャラリーの連携
		$('.expansion a').attr('rel','gallery');
		$('.expansion a').hover(function () {
			$("#gallery ul .active a").attr('rel','');
		},function(){
			$("#gallery ul .active a").attr('rel','gallery');
		});
		$("#gallery ul li a").hover(function () {
			$('.expansion a').attr('rel','');
		},function(){
			$('.expansion a').attr('rel','gallery');
		});
		return this;
	});
	};
})(jQuery);

/**
 * jQuery setToggleMenu plugin
 * 通常トグルメニュー
 */
(function($){
	var name_space = 'setToggleMenu';
	$.fn[name_space] = function(){

		$('.target',this).hide();
		$('.switch',this).wrapInner('<a href="#"></a>');
		$('.switch',this).click(function () {
			var target = $(this).parent().children('.target');
			if( $(this).hasClass("active") ){
				$(this).removeClass('active');
				target.hide();
			}else{
				$(this).addClass('active');
				target.show();
			};
			return false;
		});
		return this;
	};
})(jQuery);

/**
 * jQuery setToggleAllMenu plugin
 * トグルメニューの全開閉操作
 */
(function($){
	var name_space = 'setToggleAllMenu';
	$.fn[name_space] = function(){
		$(this).show();
		$(this).wrapInner('<a href="#"></a>');

		var opentext = '全て開く',
		    closetext = '全て閉じる';

		$(this).click(function () {
			var section = $(this).parent(),
			    alltarget = $('.target',section),
			    allswitch = $('.switch',section);

			if( $(this).hasClass("active") ){
				$(this).removeClass('active').text(opentext).wrapInner('<a href="#"></a>');
				alltarget.hide();
				allswitch.removeClass('active');
			}else{
				$(this).addClass('active').text(closetext).wrapInner('<a href="#"></a>');
				alltarget.show();
				allswitch.addClass('active');
			};
			return false;
		});
		return this;
	};
})(jQuery);

/**
 * jQuery setProductImageRandom plugin
 * 商品画像のランダム切り替え
 */
(function($){
	var name_space = 'setProductImageRandom';
	$.fn[name_space] = function(options){

		var settings = $.extend({
			maxnum: false
		}, options);
		
		var maxnum = settings.maxnum,
		    random1 = getRandom(),
		    random2 = getRandom();
		
		while ( random1 == random2 ){
			random2 = getRandom();
		};
		function getRandom(){
			return Math.floor( Math.random() * maxnum + 1);
		};
		
		function get1(){
			var srcRandom = $('img',this).attr('src').replace(/_0[0-9]\./,"_0"+random1+".");
			$('img',this).attr('src',srcRandom);
		}
		function get2(){
			var srcRandom = $('img',this).attr('src').replace(/_0[0-9]\./,"_0"+random2+".");
			$('img',this).attr('src',srcRandom);
		};
		$('li:first',this).each(get1);
		$('li:last',this).each(get2);
	};
})(jQuery);

$(function(){
	//フッター切り替え
	$('#kirikae .smartphone').hover(function(){
		$(this).siblings(".pc").addClass('off');
	},function(){
		$(this).siblings(".pc").removeClass('off');
	});
	
	//閉じるボタン
	$('#close a').click(function(){
		window.close();
		return false;
	});
});

$(function(){
	$('#nav-global li').setGlobalMenuActive();
	$('#nav-local dd a').setLocalMenuActive();
	$('.imageL , .imageR').setImgAndCaptionStyler();
	$('.img-col1-01 , .img-col2-01 li , .img-col3-01 li').setImgAndCaptionStyler();
	$('.box-toggle-01').setToggleMenu({ setter:'switch', target:'target', speed:0 });
	$('.allswitch').setToggleAllMenu();
	$('#gallery').setImgFocusChenge();
	$('#theme #pc').setProductImageRandom({ maxnum:6 });
	$('#theme #speed_wi-fi').setProductImageRandom({ maxnum:8 });
	$('#theme #tabletdata-card').setProductImageRandom({ maxnum:2 });
	$('#theme #data-card').setProductImageRandom({ maxnum:3 });
});
