// Common JS.  Build 20080626.
//
// 全ページ共通JSコード
//

// --------------------------------
// Image override (required Prototype.js)
//
//  The define : ioo = {  'IMGID':[ 'MouseoverSrc', 'MouseoutSrc' ], .... }
//
//  Fig) ioo = { 'Btn1':['over.img', 'out.img'] };
//       <img src="out.img" class="iover" id="Btn1" />
//
var ioo = {'Btn1':['over1.img', 'out1.img']};

if(window['Prototype'])
{
	var cImageOverride = Class.create({
		initialize: function(oImg)
		{
			Event.observe(oImg, 'mouseover', function(){ oImg.src = ioo[oImg.id][1]; }, false);
			Event.observe(oImg, 'mouseout', function(){ oImg.src = ioo[oImg.id][0]; }, false);
		}
	});
	Event.observe(window, 'load', function(){
	// onload Event function

		// image override init.
		if(window['ioo']){ var iOvers = $$('img.iover'); for(var i=0;i<=iOvers.length-1; i++) if(ioo[iOvers[i].id]) new cImageOverride(iOvers[i]); }

		// search init.
		var idSearchText = 'home-search-text', blankKeyword = ' ここから検索できます';
		if($(idSearchText))
		{
			if($(idSearchText).value==''||$(idSearchText).value==blankKeyword) $(idSearchText).value=blankKeyword; else Element.addClassName( $(idSearchText), 'home-search-intext' );
			
			// event handlers
			Event.observe($(idSearchText), 'focus', function(){
				if(this.value==blankKeyword)
				{
					$(idSearchText).value='';
					Element.removeClassName( $(idSearchText), 'home-search-notext' ); Element.addClassName( $(idSearchText), 'home-search-intext' );
				}
			}, false);
			Event.observe($(idSearchText), 'blur', function(){
				if(this.value==''||this.value==blankKeyword)
				{
					$(idSearchText).value=blankKeyword; Element.removeClassName( $(idSearchText), 'home-search-intext' ); Element.addClassName( $(idSearchText), 'home-search-notext' );
				}
			}, false);
		}

	}, false);
	
};

// --------------------------
// ｳｨﾝﾄﾞｳｵｰﾌﾟﾝ
// 
function openWindow(url, winname, x,y,w,h)
{
	var param = ""
			  + " left="        +x
			  + ",screenX="     +x
			  + ",top="         +y
			  + ",screenY="     +y
			  + ",toolbar="     +0	// ツールバーの表示
			  + ",location="    +0	// 場所ツールバーの表示
			  + ",directories=" +0	// ユーザ設定ツールバーの表示
			  + ",status="      +0	// ステータスバーの表示
			  + ",menubar="     +0	// メニューバーの表示
			  + ",scrollbars="  +1	// スクロールバーの表示
			  + ",resizable="   +1	// リサイズを可能にするか
			  + ",innerWidth="  +w
			  + ",innerHeight=" +h
			  + ",width="       +w
			  + ",height="      +h
			  ;
	
	var win = window.open(url, winname, param);
	win.focus();
}

// --------------------------
// ｺﾝﾃﾝﾂｷﾞｬﾗﾘｰ　ｳｨﾝﾄﾞｳｵｰﾌﾟﾝ
// 
function openContentsGallery()
{
	var scrollw = 18;	// スクロール幅
	var menubarw = 100;	// メニューバーの高さ
	
	var w = 1024 + scrollw;
	var h = 768 + scrollw;
	var x = (screen.width - w)/2;
	var y = (screen.height - (h + menubarw))/2;
	
	openWindow('/cg/', '_blank', x,y,w,h);
	return false;
}
