addLoadEvent(function(){
	preloadImg();
	tinyScrolling.init();
	subWin;
	window.focus();
});



/*
	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/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();



/*
	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;
}

/*
	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();
		}
	}

/* 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;
}


/*****************************************************
	select Image
*****************************************************/
var srcAry=[];
function preloadImg(){
	var thumbnailList = getElementsByClass("thumbnailList",$("main"),"ul");
	if(thumbnailList.length==0) return false;
	for(var k=0; k<thumbnailList.length; k++){
		thumbs = thumbnailList[k].getElementsByTagName("a");
		for(var i=0,len=thumbs.length; i<len; i++){
			var c = thumbs[i].getAttributeNode("href").nodeValue;
			srcAry.push(c.slice(c.indexOf(",")+2,c.lastIndexOf("'")));
		}
	}
	srcAry.loadImg();
}
function selectImage(OBJ,IMG){
	$(OBJ).src = IMG;
}


/*****************************************************
	emptiness
*****************************************************/
function emptiness(){
}




/*****************************************************
	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;
}