﻿
addLoadEvent(function(){
	tinyScrolling.init();
	
	if(getElementsByClass("prev",$("beforeFooter"),"li")[0]){
		getElementsByClass("prev",$("beforeFooter"),"li")[0].style.display = "block";
	}
	if( DetectFlashVer(8,0,0) && getElementsByClass("btn",$("footerNav-A"),"td")[0] ){
		getElementsByClass("btn",$("footerNav-A"),"td")[0].getElementsByTagName("a")[0].style.display = "block";
	}

//	loadPosition();

});

addUnLoadEvent(function(){
	if(watchOpenFlg) recordPosition();
});

/*
	IE bg flicker problem fix
*****************************************************/

	try {
	document.execCommand("BackgroundImageCache",false,true);
	}catch(e){}
	
	
/*
	browserDetect
*****************************************************/

	var browserDetect = {
		isSafari : (navigator.userAgent.indexOf("Safari") != -1)? true : false,
		isFF : (navigator.userAgent.indexOf("Firefox") != -1)? true : false,
		isIE : (navigator.userAgent.indexOf("MSIE") != -1)? true : false,
		isIE4 : (navigator.userAgent.indexOf("MSIE 4") != -1)? true : false,
		isIE5 : (navigator.userAgent.indexOf("MSIE 5") != -1)? true : false,
		isIE6 : (navigator.userAgent.indexOf("MSIE 6") != -1)? true : false,
		isMacIE : (document.all && !window.clipboardData)? true : false,
		isNN4 : (document.layers)? true : false,
		isNN6 : (navigator.userAgent.indexOf("Netscape/6") != -1)? true : false,
		isNN7 : (navigator.userAgent.indexOf("Netscape/7") != -1)? true : false
	}


/*
	load javascript
	- load() should be loaded in head
*****************************************************/

	var javascriptLoader = {
		files : ["/ja/common/js/scroll.js"],
		load : function(){
			if(javascriptLoader.files.length<1) return;
			for(var i=0, file; file=javascriptLoader.files[i] ;i++){
				document.open();
				document.write('<script type="text/javascript" src="'+ file + '"><\/script>');
				document.close();
			}
		}
	}
	javascriptLoader.load();


/*
	onload event control
*****************************************************/

	function addLoadEvent(func) {
		if(document.addEventListener && navigator.userAgent.indexOf('Gecko/') != -1){
			document.addEventListener("DOMContentLoaded", function(){func()}, false);
		}
		else{
			var oldonload = window.onload;
			window.onload = function() {
				func();
				if(typeof oldonload == 'function') oldonload();
			}
		}
	}
	function addUnLoadEvent(func) {
		var oldonunload = window.onunload;
		window.onunload = function() {
			if(typeof window.onunload != 'function') oldonunload();
			func();
		}
	}



/*****************************************************
	history back button write
*****************************************************/
function writeHisBackButton(){
	document.open();
	document.write("<a href=\"javascript:history.back()\">前のページに戻る</a>");
	document.close();
}




/*
	DOM Relation
*******************************************/

function $() {
	for (var i=0, elements=new Array(); i<arguments.length; i++){
		var element=arguments[i];
		element =
		(typeof(element)=="object") ? element :
		document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}
function getElementsByClass(searchClass,node,tag){
	if (node==null) node = document;
	if (tag == null) tag = '*';
	var els = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for(var i=0,x=0,Element= new Array(); i<els.length; i++){
		if (pattern.test(els[i].className)) Element[x++]=els[i];
	}
	return Element;
}
function getSpecificParent(obj,parentObj){//parentObj : class or tagname or id
	var pattern = new RegExp("(^|\\s)"+parentObj+"(\\s|$)");
	do{obj = obj.parentNode;}
	while(!pattern.test(obj.className) && obj.tagName!=parentObj.toUpperCase() && obj.tagName!="BODY" && obj.id!=parentObj)
	return obj;
}

/* Array Enhancing
*****************************************************
	Array.prototype.loadImg
*****************************************************/
Array.prototype.loadImg = function(){
	for(var i=0,preimg = [],len=this.length; i<len ; i++){
		preimg[i]=new Image();
		preimg[i].src = this[i];
	}
	return preimg;
}


/*****************************************************
	history back button write
*****************************************************/
function writeHisBackButton(){
	document.open();
	document.write("<a href=\"javascript:history.back()\">前のページに戻る</a>");
	document.close();
}


/*****************************************************
	select language
*****************************************************/
function changeLanguage(URL){
	location.href = URL;
}




/*****************************************************
	emptiness
*****************************************************/
function emptiness(){
}

/*****************************************************
	drag
*****************************************************/
var cflg = false;
var recY = 150;
function swfTarget(str) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[str];
	} else {
		return document[str];
	}
}
function dragLay(){
	var obj = $('clockArea');
	swfTarget("world_clock").onMoveClock();

	offsetX = getPageX() - obj.offsetLeft;
	offsetY = getPageY() - obj.offsetTop;

	document.onmousemove = function(){
		var moveX = (getPageX() - offsetX);
		var moveY = (getPageY() - offsetY);

		obj.style.left = moveX+"px";
		obj.style.right = "";
		obj.style.top = moveY+"px";
		return false;
	}
	document.onmouseup = function(){
		document.onmousemove = "";
		offsetX = 0;
		offsetY = 0;

		if(obj.offsetLeft < 0) obj.style.left = "0px";
		if(obj.offsetLeft > getinnerWinSize()[0]-obj.offsetWidth) obj.style.left = getinnerWinSize()[0]-obj.offsetWidth + "px";
		if(obj.offsetTop < 0) obj.style.top = "0px";
		if(browserDetect.isIE6){
			if(obj.offsetTop > getinnerWinSize()[1]+getScrollTop()-obj.offsetHeight) obj.style.top = getinnerWinSize()[1]+getScrollTop()-obj.offsetHeight + "px";
		}else{
			if(obj.offsetTop > getinnerWinSize()[1]-obj.offsetHeight) obj.style.top = getinnerWinSize()[1]-obj.offsetHeight + "px";
		}

		swfTarget("world_clock").onStopClock();
		recY = $('clockArea').offsetTop - getScrollTop();
	}
}

var watchOpenFlg = false;

function clockOpen(){
	cflg = true;
	watchOpenFlg = true;
	var obj = $("clockArea");

	obj.style.height = "213px";
	obj.style.width = "453px";

	$("clockGrip").style.display="block";
	$("clockClose").style.display="block";

	if(browserDetect.isSafari){
		swfTarget("world_clock").openWorldClock();
//		setTimeout('swfTarget("world_clock").openWorldClock();' , 0);
	}if(browserDetect.isIE6){
		setTimeout('swfTarget("world_clock").openWorldClock();' , 0);
	}else{
		swfTarget("world_clock").openWorldClock();
	}
	if(browserDetect.isIE6){
		obj.style.top =  recY + getScrollTop() +"px";
		 ie6posi();
	 }
}
function clockOpen_top(){
	watchOpenFlg = true;
	var nameAry = window.name.split(":");
	(nameAry[0]!="tyo")? setTimeout('clockOpen();' , 800) : 
	(nameAry[1] != "false")? setTimeout('clockOpen();' , 800) : false;
	
	$("clockArea").style.left = $("clockArea").offsetLeft-453 + "px";
}

function clockClose(){
	cflg = false;
	swfTarget("world_clock").onCloseClock();
	$("clockGrip").style.display="none";
	$("clockClose").style.display="none";
}
function closeWorldClock(flg){

	$("clockArea").style.height = "1px";
	$("clockArea").style.width = "1px";

}

function recordPosition(){
	window.name = "tyo:" + cflg + ":" + $('clockArea').offsetLeft + ":" + $('clockArea').offsetTop;
}
function loadPosition(){
	var nameAry = window.name.split(":");
	if(nameAry[0] == "tyo"){
		$('clockArea').style.left = nameAry[2]+"px";
		$('clockArea').style.top = nameAry[3]+"px";
		if(nameAry[1] == "true") clockOpen();
	}
}
function ie6posi(){
	document.body.onscroll = function(){
		$('clockArea').style.top =  recY + getScrollTop() +"px";
	}
}




function getinnerWinSize(){
	W=(!browserDetect.isIE)? window.innerWidth:(document.compatMode=="CSS1Compat")? document.documentElement.clientWidth:document.body.clientWidth;
	H=(!browserDetect.isIE)? window.innerHeight:(document.compatMode=="CSS1Compat")? document.documentElement.clientHeight:document.body.clientHeight;
	return [W, H];
}

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

function getDefStyle(obj){
	style = obj.currentStyle || document.defaultView.getComputedStyle(obj, '');
	return style;
}
function $E(){
	if(window.event) return window.event;
	var caller = arguments.callee.caller;
	while(caller){
		var obj = caller.arguments[0];
		if(obj && obj.constructor == MouseEvent) return obj;
		caller = caller.caller;
	}
	return null;
}


function getScrollTop(){
	return (document.compatMode == 'CSS1Compat')? document.documentElement.scrollTop : document.body.scrollTop;
}
function getScrollLeft(){
	return (document.compatMode == 'CSS1Compat')? document.documentElement.scrollLeft : document.body.scrollLeft;
}

function getPageX(){
	var nowX = (document.compatMode == 'CSS1Compat')? document.documentElement.scrollLeft : document.body.scrollLeft;
	return $E().clientX + nowX;
}
function getPageY(){
	var nowY = (document.compatMode == 'CSS1Compat')? document.documentElement.scrollTop : document.body.scrollTop;
	return $E().clientY + nowY;
}
function getWinInWidth(){
	return (window.innerWidth)? window.innerWidth : (document.compatMode == 'CSS1Compat')? document.documentElement.clientWidth : document.body.clientWidth;
}
function getWinInHeight(){
	return (window.innerHeight)? window.innerHeight : (document.compatMode == 'CSS1Compat')? document.documentElement.clientHeight : document.body.clientHeight;
}
function $XY(obj){
	var X = Y = 0;
	do{
		X += obj.offsetLeft;
		Y += obj.offsetTop;
		obj = obj.offsetParent;
	}while(obj.offsetParent);
	return [X, Y];
}


/*****************************************************
	subWin
*****************************************************/
function subWin() {
	var subWins = getElementsByClass("subWin",$("main"),"a");
	for (var i=0,len=subWins.length; i<len; i++) {
		subWins[i].onclick = function() {
			//window.open(this.href);
			openWin(this.href, this.target, 680, 680, "01010110");
			return false;
		}
	}
}

//window.onload = subWin;


function popSubWin(url,target) {
	openWin(url, target, 680, 680, "00010110");
}






/* Popup Window
*******************************************/
appVer = navigator.appVersion;
uAgent = navigator.userAgent;
//OS
var mac = (navigator.appVersion.indexOf("Mac") != -1)? true : false;
var win = (navigator.appVersion.indexOf("Win") != -1)? true : false;
var nn = (uAgent.indexOf("Netscape") != -1)? true : false;
var nn4 = (document.layers)? true : false;
var nn6 = (uAgent.indexOf("Netscape6") != -1)? true : false;
var opera = (uAgent.indexOf("Opera") != -1)? true : false;
var opera6 = (uAgent.indexOf("Opera/6") != -1)? true : false;
var opera5 = (uAgent.indexOf("Opera/5") != -1)? true : false;
var icab = (uAgent.indexOf("iCab") != -1)? true : false;
var ie = (uAgent.indexOf("MSIE") != -1)? true : false;
var ie5 = (uAgent.indexOf("MSIE 5") != -1)? true : false;
var safari = (uAgent.indexOf("Safari") != -1)? true : false;




var gAgent = navigator.userAgent;
var gAppVer = navigator.appVersion;

var gVersion = null;


if (gAgent.indexOf('MSIE') != -1) {
	gVersion = gAgent.substring((gAgent.indexOf('MSIE') + 5), (gAgent.indexOf('MSIE') + 9));

} else if (gAgent.indexOf('MSIE') == -1) {
	gVersion = gAppVer.substring(0,4);
	if (gAgent.indexOf('Gecko') != -1) {
		if (gAgent.indexOf('Netscape') != -1) {
			gVersion = gAgent.substring((gAgent.indexOf('Netscape') + 9), (gAgent.indexOf('Netscape') + 12));
		}
	}
}

if (gVersion.indexOf(';') != -1) {
	gVersion = gVersion.substring(0, gVersion.indexOf(';'));
}
if (gVersion.indexOf(' ') != -1) {
	gVersion = gVersion.substring(0, gVersion.indexOf(' '));
}

if (!gNewWindow) {
	var gNewWindow = null;
}

function openWin(url, n, w, h, st){
	var width = parseInt(w);
	var height = parseInt(h);
	var toolbar;
	var location;
	var directories;
	var status;
	var menubar;
	var resizable;
	var scrollbars;
	var dependent;

	st.charAt(0) == '1'	?  toolbar = 'yes' 		: toolbar = 'no';
	st.charAt(1) == '1'	?  location = 'yes' 	: location = 'no';
	st.charAt(2) == '1'	?  directories = 'yes' 	: directories = 'no';
	st.charAt(3) == '1'	?  status = 'yes' 		: status = 'no';
	st.charAt(4) == '1'	?  menubar = 'yes' 		: menubar = 'no';
	st.charAt(5) == '1'	?  resizable = 'yes' 	: resizable = 'no';
	st.charAt(6) == '1'	?  scrollbars = 'yes' 	: scrollbars = 'no';
	st.charAt(7) == '1'	?  dependent = 'yes' 	: dependent = 'no';

	if (location == 'yes') {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 0;
			height += 0;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width += 15;
			height += 15;

		// NN4(for Win)

		} else if (nn && gVersion >= 4) {
			width += 0;
			height += 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width += 0;
			height += 19;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width += 2;
			height += 6;

		// IE6(for Win)
		} else if (ie && gVersion >= 6) {
			width += 0;
			height -= 19;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 0;
			height -= 19;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 0;
			height -= 19;

		// safari for Mac
		} else if (mac && safari && gVersion >= 0) {
			width += -2;
			height += 50;

		// other
		} else {
			width += 0;
			height += 0;
		}
	}

	if (scrollbars == 'yes') {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 15;
			height += 1;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width += 15;
			height -= 0;

		// NN4(for Win)
		} else if (nn && gVersion >= 4) {
			width += 16;
			height -= 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width -= 0;
			height -= 16;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width -= 0;
			height -= 14;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 16;
			height += 0;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 16;
			height += 0;

		// other
		} else {
			width += 15;
			height += 3;
		}
	} else {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 1;
			height += 1;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width -= 0;
			height -= 0;

		// NN4(for Win)
		} else if (nn && gVersion >= 4) {
			width -= 0;
			height -= 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width -= 0;
			height -= 0;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width -= 0;
			height += 2;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 0;
			height += 0;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 0;
			height += 0;

		// other
		} else {
			width += 0;
			height += 0;
		}
	}


	if (status == 'yes') {
		// NN4 for Mac
		if (mac && nn && gVersion >= 4 && gVersion < 5) {
			width -= 15;
			height -= 15;

		// IE4 for Mac
		}else if(mac && ie && gVersion >= 4 && gVersion < 5){
			width -= 0;
			height += 16;

		}
	}


	if (status == 'no') {
		// NN4
		if (nn && gVersion >= 4 && gVersion < 5) {
			width -= 0;
			height -= 0;

		// NN5 over
		}else if (mac && nn) {
			width += 0;
			height += 80;

		// NN5 over
		}else if (win && nn) {
			width += 0;
			height += 20;

		// safari for Mac
		} else if (mac && safari && gVersion >= 0) {
			width += 0;
			height += 20;

		}
	}


	var win_size = 'width=' + width + ',height=' + height;
	var win_attr = 'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',dependent=' + dependent;

	var w = window.open(url, n, win_attr + ',' + win_size);
	w.focus();
	return false;
}
