/*
	--------------------------------
	Created: 2007.07.11
	Last Modified: 2007.07.16
	--------------------------------
	- Table of Contents -

	1. Configuration

	2. MM_Behavior
		- MM_preloadImages()
			event handler : onload="MM_preloadImages('path'[,'path']*)"
		- MM_swapImgRestore()
		- MM_findObj()
		- MM_swapImage()
			event handler : onmouseover="MM_swapImage('id','','path'[,'id','','path']*,1)" onmouseout="MM_swapImgRestore()"
		- MM_swapThisImage()

	3. Functions
		- OnSearch()

	4. Classes
		- GlobalNav()
	--------------------------------
*/



/* --------------------------------
	1. Configuration
-------------------------------- */

var globalNav = new GlobalNav();
globalNav.preload();



/* --------------------------------
	2. MM_Behavior
-------------------------------- */

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapThisImage() {
  var i,j=0,x,a=MM_swapThisImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if (x=a[i]){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



/* --------------------------------
	3. Functions
-------------------------------- */

/* Cocoda検索設定 ---------------- */
function OnSearch() {
	 // 検索キーは必須
	 if ( document.frm.keyexpr.value == '' ) {
		alert( '条件を入力して下さい。' );
		return false;
	 }
         // Benesse教育研究開発センター内(CoCoDa)
         document.frm.action = 'http://kensaku.benesse.co.jp/cgi-bin/ccdmsrch.cgi?/usr/local/ccd7/visdb/public/L01';
         document.frm.kw.value = '';
         var nwnd = window.open( 'about:blank', 'NewSWnd', 'toolbar=yes,location=no,menubar=no,scrollbars=yes' );
	 document.frm.submit();
	 nwnd.focus();
	 return true;
}



/* --------------------------------
	4. Classes
-------------------------------- */

/* グローバルナビ ---------------- */
function GlobalNav() {
	// イメージ
	this.img = {
		dir: '/berd/common/img/',
		prefix: 'gnav_',
		name: [ 'home', 'library', 'report', 'focus', 'aboutus' ],
		suffix: {
			link: '_a',
			hover: '_b',
			current: '_c'
		},
		extension: '.jpg',
		cache: {}
	}

	// ドロップダウンメニュー
	this.dropdown = {
		 prefix: 'dropdown_'
	}

	// ディレイ
	this.delay = {
		id: null,
		time: 300
	}

	// 操作中の要素
	this.focus = {
		id: null,
		img: new Image()
	}

	// プレロード
	this.preload = function() {
		var img = this.img;
		var hover = img.suffix.hover;
		for ( var i = 0, l = img.name.length; i < l; i++ ) {
			var name = img.name[ i ];
			this.img.cache[ name + hover ] = new Image();
			this.img.cache[ name + hover ].src = img.dir + img.prefix + name + hover + img.extension;
		}
	}

	// トグル
	this.toggle = function( e, id ) {
		var type = e.type || window.event.type;
		if ( type == 'mouseover' ) {
			this.show( id );
		} else {
			var self = this;
			this.delay.id = setTimeout( function() { self.hide(); }, this.delay.time );
		}
	}

	// 表示
	this.show = function( id ) {
		if ( this.delay.id ) clearTimeout( this.delay.id );
		var $ = this.$;
		if ( id != this.focus.id ) {
			if ( this.focus.id ) this.hide();
			this.focus.id = id;
			this.focus.img.src = $( this.img.prefix + id ).src;
		}
		var img = this.img;
		if ( !$( img.prefix + id ).src.match( img.dir + img.prefix + id + img.suffix.current + img.extension + '$' ) ) {
			$( img.prefix + id ).src = img.cache[ id + img.suffix.hover ].src;
		}
		if ( $( this.dropdown.prefix + id ) ) $( this.dropdown.prefix + id ).style.display = 'block';
	}

	// 非表示
	this.hide = function() {
		this.delay.id = null;
		var $ = this.$;
		var id = this.focus.id;
		$( this.img.prefix + id ).src = this.focus.img.src;
		if ( $( this.dropdown.prefix + id ) ) $( this.dropdown.prefix + id ).style.display = 'none';
	}

	// [ getElementById ] のエイリアス
	this.$ = function( id ) {
		return ( typeof id == 'string' ) ? document.getElementById( id ) : id;
	}
}







