addLoadEvent(function(){
	tinyScrolling.init();
	fontsizeChg.init();
	setWindowName();
	preloadImg();
	if(getElementsByClass("prev",$("beforeFooter"))[0] && getHistory()){
		getElementsByClass("prev",$("beforeFooter"))[0].getElementsByTagName("a")[0].style.display = "block";
	}

	if(opener && opener.name=="company") opener.blur();
	window.focus();
});

addUnLoadEvent(function(){
});



function getHistory(){
	if(browserDetect.isIE) return (history.length!=0)? true : false;
	return (history.length!=1)? true : false;
}

/*
	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 : ["/jp/ja/common_product/js/scroll.js","/jp/ja/common_product/js/styleswitcher.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();
}




/*****************************************************
	setWindowName
*****************************************************/
function setWindowName(){
	window.name = (document.body.className=="popup")? "kose_popup" : "kose_base";
}



/*
	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;
}

/*****************************************************
	select Image
*****************************************************/
var srcAry=[];
function preloadImg(){
	if(!$("thumbnail")) return false;
	var thumbnailList = $("thumbnail").getElementsByTagName("li");
	for(var i=0; i<thumbnailList.length; i++){
		var c = thumbnailList[i].getAttributeNode("onclick").nodeValue;
		srcAry.push(c.slice(c.indexOf("'")+1,c.lastIndexOf("'")));
	}
	srcAry.loadImg();
}
function selectImage(IMG,obj){
	$("mainPhoto").src = IMG;
	var thumbnailList = $("thumbnail").getElementsByTagName("li");
	for(var i=0; i<thumbnailList.length; i++){
		thumbnailList[i].className = "";
	}
	obj.className = "select";
}


/*****************************************************
	emptiness
*****************************************************/
function emptiness(){
}


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, 780, 600, "11001111");
}


function popSubWinPost(url, target) {
	openWin('', target, 780, 600, "11001111");
    document.inqForm.target = target;
    document.inqForm.method = 'post';
    document.inqForm.action = url;
    document.inqForm.submit();
}

/* 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;
}





/*
	IE6 Adjustment margin
*****************************************************/
if(browserDetect.isIE6 && $("main") && $("main").getElementsByTagName("*")[0].className=="heading-lv2")
	$("main").getElementsByTagName("*")[0].style.marginTop = "0";
if(browserDetect.isIE6 && $("sidebar") && $("sidebar").getElementsByTagName("*")[0].className=="heading-lv2")
	$("sidebar").getElementsByTagName("*")[0].style.marginTop = "0";


/*
	cancel select
*****************************************************/
addLoadEvent(function(){
	var bodyClassName = document.body.className;

	if(bodyClassName && bodyClassName.indexOf("js_dontstealtext")>-1){
		function noright(){
			return false;
		}
		document.oncontextmenu = noright;
	}

});

