/*
JavaScript: com.js

last updated on 2011.04.27
(c) 2011 INUI YOSUKE Design Office (http://www.inuiyosuke.jp/)
*/


// ------------------------------- Over Write CSS -------------------------------
doc.open();
doc.write('<style type="text/css">');
if (!ENV.IP) { doc.write('div#PAGE { overflow:hidden; }'); }
doc.write('div#JSS { ; } div#JSS div.OBJ { top:3000px; } a#NEXT { visibility:hidden; } div.OBJ div.IMAGES { height:400px; } div.OBJ div.IMAGES img { position:absolute; display:none; }');
doc.write('div#HEADER ol li.PHOTO a img { position:absolute; display:none; }');
doc.write('</style>');
doc.close();

// ------------------------------- SHORT-CUT KEYS -------------------------------
doc.onkeydown = function () {
	if (macFF || winFF) { event = arguments[0]; }
	if (event.altKey || event.ctrlKey || event.shiftKey) { return true; }
	if	(event.keyCode == 27 && !INITIAL.flag)	{ }	// ESC
	else if	(event.keyCode == 39 && !INITIAL.flag)	{ if (script_JSS.flag) { if (JSS.end || !script_JSS.objdrag) { NEXT.go(); } else { script_JSS.slide(-3/4); return false; }} else if (NEXT.flag) { NEXT.go(); }}	// →
	else if	(event.keyCode == 37 && !INITIAL.flag)	{ if (script_JSS.flag) { if (JSS.top || !script_JSS.objdrag) { history.go(-1); } else { script_JSS.slide(3/4); return false; }} else if (NEXT.flag) { history.go(-1) }}	// ←
	else if	(event.keyCode == 38 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(1); return false; }	}	// ↑
	else if	(event.keyCode == 40 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(-1); return false; }	}	// ↓
	else if	(event.keyCode == 33 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(1); return false; }	}	// PAGE UP
	else if	(event.keyCode == 34 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(-1); return false; }	}	// PAGE DOWN
	else if	(event.keyCode == 35 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(-99999); return false; }	}	// END
	else if	(event.keyCode == 36 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(99999); return false; }	}	// HOME
	else if	(event.keyCode == 32 && !INITIAL.flag)	{ if (script_JSS.flag) { script_JSS.slide(-1); return false; }	}	// Space Bar
	else if	(event.keyCode == 13 && !INITIAL.flag)	{ }		// Return
	else if	(event.keyCode == 82 || event.keyCode == 116)		{ set_COOKIE('INTRO', '0', 1*1); }		// R + F5
//	alert(event.keyCode);
}

// -- INITIAL / JSS (JavaScript Scroll) --
wheel.Set("script_JSS.wheel();"); msup.Set("script_JSS.off();");
load.Set('INITIAL.set();');
var INITIAL = { timer:undefined, flag:false, obj:new Object(), jss:new Object(), jss_obj:new Object(), sheet:new Object(), bg:new Object(), tW:0,
set:function () {
	INITIAL.jss	= new OBJ('JSS');
if (INITIAL.jss.flag) {
// -- JSS (JavaScript Scroll) --
	// script_JSS.objdrag = true;
	// -- get JSS width --
	INITIAL.jss_obj	= new OBJ(INITIAL.jss.path.firstChild);
	// for (i = 1; i <= INITIAL.jss_obj.path.childNodes.length; i ++) { if (parseInt(INITIAL.jss_obj.path.childNodes[(i-1)].offsetWidth) > 0) { INITIAL.tW += parseInt(INITIAL.jss_obj.path.childNodes[(i-1)].offsetWidth + 1); }}
										/* IE Bug-fix */ if (ENV.IE) { INITIAL.jss_obj.setV(1).setX(0).setY(0); } else {
	INITIAL.jss_obj.setV(1).setA(0).setX(0).setY(0);
	trans.Set(INITIAL.jss_obj, 100, 3);
										/* IE Bug-fix */ }
	INITIAL.jss_obj.setV(1).setC(0,0,212,0);
	INITIAL.obj	= new JSS('JSS', 612, (400), 600, 0, 0, 0, 4);
//	INITIAL.timer	= setTimeout('INITIAL.check_sweep();', 500);
}
// -- to fadeBG --
	fadeBG.set();
}, check_sweep:function () {
	if (INITIAL.jss_obj.C[1] >= ENV.W)	{ INITIAL.jss_obj.setC(0,INITIAL.tW,212,0); }
	else				{ INITIAL.timer	= setTimeout('INITIAL.check_sweep();', 16); }
}
}

function JSS_ANC () {
var tmp = new OBJ(arguments[0]);
script_JSS.move(-tmp.Y + 75 + 1);
return false;
}

// -- fadeBG --
mouse.Set("fadeBG.trans();");
var fadeBG = { timer:undefined, flag:false, obj:new Object(), flag:false, ps:new Object(), pos:new Array(-450,150),
set:function () { if (!ENV.IP) {
fadeBG.obj	= new OBJ('BG'); if (!fadeBG.obj.flag) { fadeBG.obj = ADD('div','id=BG'); }
fadeBG.ps		= new OBJ('PS'); 
if (fadeBG.obj.flag && !macIP) {
	fadeBG.obj.setA(0).setD(1);
	trans.Set(fadeBG.obj, 0);
	fadeBG.set2();
}}},
set2:function () { if (fadeBG.timer) { clearTimeout(fadeBG.timer); }
	if (fadeBG.obj.A <= 0)	{ fadeBG.timer = setTimeout('fadeBG.flag = true;', 0); }
	else			{ fadeBG.timer = setTimeout('fadeBG.set2();', 100); }
},
trans:function () { if (fadeBG.flag && !ENV.IP) {
	if	(MX < (ENV.W / 2) + fadeBG.pos[0] )	{ trans.Set(fadeBG.obj,0);	if (fadeBG.ps.flag) { trans.Set(fadeBG.ps,100); PS.onfloag = true; }}
	else if	(MX > (ENV.W / 2) + fadeBG.pos[1] )	{ trans.Set(fadeBG.obj,100);	if (fadeBG.ps.flag) { trans.Set(fadeBG.ps,20); PS.onfloag = false; }}
	else					{ 
		var tmp	= parseInt(((MX - (ENV.W / 2 + fadeBG.pos[0])) / (fadeBG.pos[1] - fadeBG.pos[0])) * 100);
		trans.Set(fadeBG.obj, tmp);
		if (fadeBG.ps.flag) { 
			trans.Set(fadeBG.ps, (parseInt((100-tmp)/100*80) + 20));
			PS.onfloag = true;
		}
	}
	script_JSS.drag();
}}
}

// ----- IMAGES SLIDESHOW -----
load.Set('IMAGES.set();');
var IMAGES	= { timer:undefined, flag:false, next:new Array(), objs:new Array(), imgs:new Array(), dock:new Array(), inds:new Array(), inds_txt:new Array(), loc:new Array(),
set:function () {
IMAGES.objs = new CLASS('IMAGES');
for (i = 0; i < IMAGES.objs.length; i ++) {
	IMAGES.imgs[i] = new Array();
	for (j = 0; j < IMAGES.objs[i].path.childNodes.length; j ++) { 
		IMAGES.imgs[i][j] = new OBJ(IMAGES.objs[i].path.childNodes[j]);
		if (j == 0) { IMAGES.imgs[i][0].setD(1); IMAGES.loc[i] = 0; }
		else if (j == 1) { 
			IMAGES.dock[i]	= IMAGES.objs[i].ADD('div').setCN('INDS');
			IMAGES.inds[i]	= new Array();
			IMAGES.inds[i][0]	= IMAGES.dock[i].ADD('a');
			IMAGES.inds[i][0].jss.backgroundPosition = '0px -100px';
			IMAGES.inds[i][0].path.onmouseover	= function () { this.style.backgroundPosition = '0px -50px'; }
			eval ('IMAGES.inds[' + i + '][' + 0 + '].path.onmouseout	= function () { this.style.backgroundPosition = (IMAGES.loc[' + i + '] == ' + 0 + ') ? "0px -100px" : "0px 0px"; }');
			eval ('IMAGES.inds[' + i + '][' + 0 + '].path.onclick	= function() { IMAGES.on(' + i + ',' + 0 + '); return false; }');
			eval ('IMAGES.imgs[' + i + '][' + 0 + '].path.onclick	= function() { IMAGES.on(' + i + '); }');
			eval ('IMAGES.imgs[' + i + '][' + 0 + '].path.onmouseover	= function() { IMAGES.over(' + i + ');}');
			eval ('IMAGES.imgs[' + i + '][' + 0 + '].jss.cursor	= "pointer";');
		}
		if (j >= 1)  {
			IMAGES.inds[i][j]			= IMAGES.dock[i].ADD('a');
			IMAGES.inds[i][j].path.onmouseover	= function () { this.style.backgroundPosition = '0px -50px'; }
			eval ('IMAGES.inds[' + i + '][' + j + '].path.onmouseout	= function () { this.style.backgroundPosition = (IMAGES.loc[' + i + '] == ' + j + ') ? "0px -100px" : "0px 0px"; }');
			eval ('IMAGES.inds[' + i + '][' + j + '].path.onclick	= function() { IMAGES.on(' + i + ',' + j + '); return false; }');
			eval ('IMAGES.imgs[' + i + '][' + j + '].path.onclick	= function() { IMAGES.on(' + i + '); }');
			eval ('IMAGES.imgs[' + i + '][' + j + '].path.onmouseover	= function() { IMAGES.over(' + i + ');}');
			eval ('IMAGES.imgs[' + i + '][' + j + '].jss.cursor	= "pointer";');
			if (j >= (IMAGES.objs[i].path.childNodes.length - 2)) { break; }
		}
	}
	// NEXTIMAGE
	if (IMAGES.objs[i].path.childNodes.length > 1) {
		IMAGES.next[i]	= IMAGES.objs[i].ADD('a').setCN('NEXTIMAGE').setI('NEXT IMAGE').setC(0,100,21,100);
		eval ('IMAGES.next[' + ( i ) + '].path.onclick		= function() { IMAGES.on(' + i + '); return false; }');
		eval ('IMAGES.next[' + ( i ) + '].path.onmouseover	= function() { IMAGES.over(' + i + ');}');
		eval ('IMAGES.objs[' + ( i ) + '].path.onmouseout		= function() { IMAGES.out(' + i + ');}');

	// -- TEXT (ADD for Kuribayashi)  --
		IMAGES.inds_txt[i] = IMAGES.dock[i].ADD('a').setCN('JSS_TXT').setI('TEXT');
		eval ('IMAGES.inds_txt[' + ( i ) + '].path.onclick	= function() { script_JSS.move(-450); return false; }');
	}
}
	// SLIDSHOW
	if (IMAGES.objs.length == 1 && IMAGES.imgs[0].length > 1)	{ IMAGES.timer	= setTimeout('IMAGES.slideshow();', 4000); }
}, slideshow:function () {
	IMAGES.on(0); clearTimeout(IMAGES.timer);
	IMAGES.timer = setTimeout('IMAGES.slideshow();', 4000);
}, on:function () {
	if (IMAGES.timer)				{ clearTimeout(IMAGES.timer); }
	if (IMAGES.loc[(arguments[0])] == arguments[1])	{ return; }
	// IMAGES.loc
	if	(IMAGES.loc[(arguments[0])] >= 99999)					{ IMAGES.loc[(arguments[0])] = 0; }
	else if	(arguments[1] >= 0)							{ IMAGES.loc[(arguments[0])] = arguments[1]; }
	else if	(IMAGES.loc[(arguments[0])] >= (IMAGES.imgs[(arguments[0])].length -1))	{ IMAGES.loc[(arguments[0])] = 0; }
	else									{ IMAGES.loc[(arguments[0])] += (arguments[1] < 0) ? -1 : 1; }

	IMAGES.imgs[(arguments[0])][(IMAGES.loc[(arguments[0])])].setA(0).setD(1);
	for (i = 0; i < IMAGES.imgs[(arguments[0])].length; i ++) { 
		if (i == IMAGES.loc[(arguments[0])]) { IMAGES.imgs[(arguments[0])][i].setZ(10); }
		else  { IMAGES.imgs[(arguments[0])][i].setZ((IMAGES.imgs[(arguments[0])][i].Z -1)); }
		if (IMAGES.imgs[(arguments[0])][i].Z == 9) { trans.Set(IMAGES.imgs[(arguments[0])][i], 0, 5); }
		else if (IMAGES.imgs[(arguments[0])][i].Z < 9) { IMAGES.imgs[(arguments[0])][i].setD(0); }
	}
	trans.Set(IMAGES.imgs[(arguments[0])][(IMAGES.loc[(arguments[0])])],100,12);		// 透過処理

	for (i = 0; i < IMAGES.inds[(arguments[0])].length; i ++) { IMAGES.inds[(arguments[0])][i].jss.backgroundPosition = (IMAGES.loc[(arguments[0])] == i) ? "0px -100px" : "0px 0px"; }

	// SLIDSHOW
	IMAGES.timer = setTimeout('IMAGES.slideshow();', 8000);
}, over:function () { if (IMAGES.next[(arguments[0])].flag) {
	sweep.Set(IMAGES.next[(arguments[0])], 0,100,21,0);
}}, out:function () { if (IMAGES.next[(arguments[0])].flag) {
	sweep.Set(IMAGES.next[(arguments[0])], 0,100,21,100);
}}}

// -- NEXT --
load.Set('NEXT.set();');
window.onscroll = function () { if (NEXT.obj.flag) { NEXT.obj.setX(-100); clearTimeout(NEXT.timer); NEXT.timer = setTimeout('NEXT.move();',512); }}
var NEXT = { timer:undefined, flag:false, obj:new Object(), url:undefined, bflag:false, baloon:new Object(), btimer:undefined,
set:function () { if (!NEXT.obj.flag) { NEXT.obj = new OBJ('NEXT'); } if (NEXT.obj.flag && !INITIAL.flag) { 
	NEXT.url = NEXT.obj.path.href;
	NEXT.obj.path.onmouseover	= function () { AUDIO.play(); NEXT.on; }
	NEXT.obj.path.onmousemove	= NEXT.on;
	NEXT.obj.path.onmouseout	= NEXT.out;
	NEXT.flag = true;
	NEXT.move();
	// NEXT.BALLOON
	if (NEXT.bflag) { 
		NEXT.baloon = ADD('div','id=TOP_BALLOON');
		NEXT.baloon.setD(0).setA(0).setI('<span><strong>便利な閲覧方法のご案内</strong>当サイトではキーボードの十字キー「→」で次のページに進みます。</span>');
	}
} else { NEXT.timer = setTimeout('NEXT.set();',1000); }},
on:function () { 
sweep.Set(NEXT.obj, 0,100,25,0, 1,6);
if (NEXT.bflag && NEXT.baloon.flag) { 
	clearTimeout(NEXT.btimer);
	if (NEXT.baloon.A != 100) { NEXT.baloon.setD(1); trans.Set(NEXT.baloon, 100, 5); }
}},
out:function () { 
sweep.Set(NEXT.obj, 0,100,25,75, 1,6);
if (NEXT.bflag && NEXT.baloon.flag) {
	clearTimeout(NEXT.btimer);
	trans.Set(NEXT.baloon, 0, 3);
	NEXT.btimer = setTimeout( 'NEXT.baloon.setD(0);',500); 
}},
go:function () { if (NEXT.obj.flag && NEXT.url) { AUDIO.play(); location.href = NEXT.url; }},
move:function () { if (!scroll.flag) { 
	ENV.Set();
	NEXT.obj.setD(1).setC(0,100,25,75).setV(1);
}}
}

// ----- PHOTO STREAM : IMAGES SLIDESHOW -----
load.Set('PS.set();');
var PS	= { timer:undefined, flag:false, onfloag:true, obj:new Object(), imgs:new Array(),loc:99999,
set:function () { 
	PS.obj	= new OBJ('PS');
	if (this.obj.flag) { 
		for (i = 0; i < this.obj.path.childNodes.length; i ++) { this.imgs[i]	= new OBJ(this.obj.path.childNodes[i]); }
		PS.flag = true;
		PS.timer = setTimeout('PS.on(0);', 250);
	}
}, on:function () { if (PS.onfloag && (PS.loc == 99999 || PS.imgs[(PS.loc)].A >= 100)) {
	if (this.timer)		{ clearTimeout(this.timer); }
	if (this.loc == arguments[0])	{ return; }
	// PS.loc
	if	(this.loc >= 99999)			{ this.loc = 0; }
	else if	(arguments[0] >= 0)			{ this.loc = arguments[0]; }
	else if	(this.loc >= (this.imgs.length -1))	{ this.loc = 0; }
	else					{ this.loc += (arguments[1] < 0) ? -1 : 1; }

	this.imgs[(this.loc)].setA(0).setD(1);
	for (i = 0; i < this.imgs.length; i ++) { 
		if (i == PS.loc)		{ PS.imgs[i].setZ(10); }
		else			{ PS.imgs[i].setZ((PS.imgs[i].Z -1)); }
		if (PS.imgs[i].Z < 9)	{ PS.imgs[i].setD(0); }
	}
	trans.Set(PS.imgs[(PS.loc)],100,20);		// 透過処理

	// SLIDSHOW
	if (this.obj.path.childNodes.length > 1) { PS.timer = setTimeout('PS.on();', 4000); }
} else { PS.timer = setTimeout('PS.on();', 100); }
}, over:function () { if (PS.next.flag) {
	sweep.Set(PS.next, 0,100,21,0);
}}, out:function () { if (PS.next.flag) {
	sweep.Set(PS.next, 0,100,21,100);
}}
}

// -- Email --
function Email () {
var Email_Addr	= 'quri' + '.kuribayashi' + '\@' + 'nifty' + '.com';
if (arguments[0] && arguments[1]) { Email_Addr = arguments[0] + '\@' + arguments[1]; }
var string	= '<a href="' + 'mail' + 'to:' + Email_Addr + '">' + Email_Addr + '</a>';
document.open();
document.write(string);
document.close();
}

// -- AUDIO: TEST Script...working on Safari & Opera --
load.Set('AUDIO.set();');
var AUDIO = { timers:new Array, obj:new Object(), flag:false, keys:new Array(), play:function () { if (AUDIO.flag) { AUDIO.obj.play(); }},
set:function () {
	AUDIO.obj = new Audio('/com/aiff/sbap.aiff');
	AUDIO.flag = true;
	for(i = 0; i < doc.links.length; i++) { 
		AUDIO.keys[i] = false;
		if (!doc.links[i].onmouseover) { 
			eval ('doc.links[' + (i) + '].onmouseover	= function () { if (!AUDIO.keys[' + (i) + ']) { AUDIO.play(); } clearTimeout( AUDIO.timers[' + (i) + ']); AUDIO.keys[' + (i) + '] = true; }');
			eval ('doc.links[' + (i) + '].onmousemove	= function () { clearTimeout( AUDIO.timers[' + (i) + ']); AUDIO.keys[' + (i) + '] = true; }');
			eval ('doc.links[' + (i) + '].onmouseout	= function () { clearTimeout( AUDIO.timers[' + (i) + ']); AUDIO.timers[' + (i) + '] = setTimeout("AUDIO.keys[' + (i) + '] = false;",144); }');
		}
	}
}
}
