/**
 * イベントを追加
 */
function addEvent( obj, evType, fn )
{
	if ( obj.addEventListener )
	{
		obj.addEventListener( evType, fn, false );
		return true;
	}
	else if ( obj.attachEvent )
	{
		var r = obj.attachEvent( "on" + evType, fn );
		return r;
	}
	else
	{
		window.onload = fn;
		return false;
	}
}

/**
 * Fancybox
 */

$(document).ready(function() {
	$("a.fancy01").fancybox({
	'opacity'			: true,
	'transitionIn'		: 'elastic',
	'transitionOut'		: 'none',
	'overlayColor'		: '#000',
	'overlayOpacity'	: 0.8
	});
});

/**
 * マウスオーバーでフェード
 */
jQuery(document).ready(function(){
	var fadetime = 150;	// 1000 = 1秒
	var alpha = 0.6;	// 1 = 100%
	
//	$("img[src*=_off\.],input[type=image][src*=_off\.]").hover( function() {
	jQuery(".fade").hover( function() {
		jQuery(this).fadeTo(fadetime,alpha);
	},function(){
		jQuery(this).fadeTo(fadetime,1);
	});

});

/**
 * ナビゲーションハイライト
 */
jQuery(document).ready(function(){
	// ページIDを取得
	var pageId = document.body.id.replace( "page","" );
	var naviId = "navi" + pageId;
	// ハイライトターゲットを取得
	var targetElm;
	if ( targetElm = document.getElementById( naviId ) )
	{
		var linkObj = targetElm.firstChild;
		var imegeObj = linkObj.firstChild;
		var imegePath = imegeObj.src;
		var imegeAlt = imegeObj.alt;
		
		// ハイライト用エレメントを作成
		var imgObj = document.createElement( "img" );
		imgObj.src = imegePath.replace( "_off","_active" );
		imgObj.src = imgObj.src.replace( "_on","_active" );
		imgObj.alt = imegeAlt;
		
		// ノードを削除
		linkObj.removeChild( linkObj.lastChild );
		
		// ハイライトイメージを追加
		linkObj.appendChild( imgObj );
	}
});
/**
 * メニューハイライト
 */
jQuery(document).ready(function(){
	// メニューIDを取得
	var menuSec;
	if( menuSec = document.getElementById( "memuSec" ) )
	{
		var menuId = menuSec.firstChild.id.replace( "menuBox","" );
		var menuId = "menu" + menuId;
		// ハイライトターゲットを取得
		var targetElm;
		if ( targetElm = document.getElementById( menuId ) )
		{
			var imegeObj = targetElm.firstChild.firstChild;
			var imegePath = imegeObj.src;
			var imegeAlt = imegeObj.alt;
			
			// ハイライト用エレメントを作成
			var imgObj = document.createElement( "img" );
			imgObj.src = imegePath.replace( "_off","_on" );
			imgObj.alt = imegeAlt;
			
			// ノードを削除
			targetElm.removeChild( targetElm.firstChild );
			
			// ハイライトイメージを追加
			targetElm.appendChild( imgObj );
		}
	}
});


/**
 * ポップアップ
 */
function popupWindow( size, url, height )
{
	switch( size )
	{
		case "S":
			windowWidth = 620;
			break;
		case "M":
			windowWidth = 500;
			break;
		case "L":
			windowWidth = 780;
			break;
		default:
			windowWidth = size;
			break;
	}
	
	var windowHeight = 550;
	if( height )
	{
		windowHeight = height;
	}
	
	window.open( url.href, size, 'width=' + windowWidth + ',height=' + windowHeight + ',menubar=no,toolbar=no,resizable=yes,scrollbars=yes' );
	
	return false;
}

/**
 * 別ウインドウリンク
 */
function location_blank( obj )
{
	var url = obj.getAttribute( 'href' );
	window.open( url );
}

/**
 * フェードロールオーバー
 */

(function(){
//------------------- 設定項目 -------------------

var $usrParam1 = '_off.';    //通常表示画像名
var $usrParam2 = '_on.';     //オンマウス表示画像名
var $usrParam3 = 20;         //フェイドの時間設定

//------------------------------------------------
   var fadeImg = [];
   function set01FadeOver(){
     var insert = [];
     var elem = document.getElementsByTagName("img");
     var elemTotal = elem.length;
     if(elemTotal == 0){return;}
     for(var i=0; i<elemTotal; i++){
       var splitBox = elem[i].src.split($usrParam1);
       if(splitBox[1]){
         var imgTag = document.createElement('img');
         fadeImg.push(imgTag);
        // imgTag.type = "image";
         imgTag.src = splitBox[0]+$usrParam2+splitBox[1];
         imgTag.alt = elem[i].alt;
         var effect = 0;
         imgTag.currentEffect = effect;
         imgTag.style.opacity = effect/100;
         imgTag.style.filter = 'alpha(opacity='+effect+')';
         imgTag.style.position = 'absolute';
         addEvent(imgTag,'mouseover',function(){setFader(this,100);});
         addEvent(imgTag,'mouseout',function(){setFader(this,0);});
         insert[insert.length] = {position:elem[i],element:imgTag};
       }
     }
     for(i=0,len=insert.length; i<len ;i++){
       var parent = insert[i].position.parentNode;
       parent.insertBefore(insert[i].element,insert[i].position);
     }
     addEvent(window,'beforeunload', clearFade);
   }


   function setFader(targetAbc,targetEffect){
     targetAbc.targetEffect = targetEffect;
     if(targetAbc.currentEffect==undefined){
       targetAbc.currentEffect = 100;
     }
     if(targetAbc.currentEffect==targetAbc.targetEffect){
       return;
     }
     if(!targetAbc.fading){
       if(!targetAbc.fader){
         targetAbc.fader = fader;
       }
       targetAbc.fading = true;
       targetAbc.fader();
     }
   }


   function fader(){
     this.currentEffect += (this.targetEffect - this.currentEffect)*0.2;
     if(Math.abs(this.currentEffect-this.targetEffect)<1){
       this.currentEffect = this.targetEffect;
       this.fading = false;
     }
     var effect = parseInt(this.currentEffect);
     this.style.opacity = effect/100;
     this.style.filter = 'alpha(opacity='+effect+')';
     if(this.fading){
       var scope = this;
       setTimeout(function(){fader.apply(scope)},$usrParam3);
     }
   }


   function clearFade(){
     for(var i=0,len=fadeImg.length; i<len; i++){
       var imgAmax = fadeImg[i];
       imgAmax.style.opacity = 0;
       imgAmax.style.filter = 'alpha(opacity=0)';
     }
   }


   function addEvent(sysParam01, sysParam02, sysParam03){
     if(sysParam01.addEventListener){
       sysParam01.addEventListener(sysParam02, sysParam03, false);
     }else if(window.attachEvent){
       sysParam01.attachEvent('on'+sysParam02, function(){sysParam03.apply(sysParam01);});
     }
   }

   addEvent(window,'load',set01FadeOver);

 })();

(function(){
//------------------- 設定項目 -------------------

var $usrParam1 = '_off.';    //通常表示画像名
var $usrParam2 = '_on.';     //オンマウス表示画像名
var $usrParam3 = 20;         //フェイドの時間設定

//------------------------------------------------
   var fadeImg = [];
   function set01FadeOverInput(){
     var insert = [];
     var elem = document.getElementsByTagName("input");
     var elemTotal = elem.length;
     if(elemTotal == 0){return;}
     for(var i=0; i<elemTotal; i++){
       var splitBox = elem[i].src.split($usrParam1);
       if(splitBox[1]){
         var imgTag = document.createElement('input');
         fadeImg.push(imgTag);
         imgTag.type = "image";
         imgTag.src = splitBox[0]+$usrParam2+splitBox[1];
         var effect = 0;
         imgTag.currentEffect = effect;
         imgTag.style.opacity = effect/100;
         imgTag.style.filter = 'alpha(opacity='+effect+')';
         imgTag.style.position = 'absolute';
         addEvent(imgTag,'mouseover',function(){setFader(this,100);});
         addEvent(imgTag,'mouseout',function(){setFader(this,0);});
         insert[insert.length] = {position:elem[i],element:imgTag};
       }
     }
     for(i=0,len=insert.length; i<len ;i++){
       var parent = insert[i].position.parentNode;
       parent.insertBefore(insert[i].element,insert[i].position);
     }
     addEvent(window,'beforeunload', clearFade);
   }


   function setFader(targetAbc,targetEffect){
     targetAbc.targetEffect = targetEffect;
     if(targetAbc.currentEffect==undefined){
       targetAbc.currentEffect = 100;
     }
     if(targetAbc.currentEffect==targetAbc.targetEffect){
       return;
     }
     if(!targetAbc.fading){
       if(!targetAbc.fader){
         targetAbc.fader = fader;
       }
       targetAbc.fading = true;
       targetAbc.fader();
     }
   }


   function fader(){
     this.currentEffect += (this.targetEffect - this.currentEffect)*0.2;
     if(Math.abs(this.currentEffect-this.targetEffect)<1){
       this.currentEffect = this.targetEffect;
       this.fading = false;
     }
     var effect = parseInt(this.currentEffect);
     this.style.opacity = effect/100;
     this.style.filter = 'alpha(opacity='+effect+')';
     if(this.fading){
       var scope = this;
       setTimeout(function(){fader.apply(scope)},$usrParam3);
     }
   }


   function clearFade(){
     for(var i=0,len=fadeImg.length; i<len; i++){
       var imgAmax = fadeImg[i];
       imgAmax.style.opacity = 0;
       imgAmax.style.filter = 'alpha(opacity=0)';
     }
   }


   function addEvent(sysParam01, sysParam02, sysParam03){
     if(sysParam01.addEventListener){
       sysParam01.addEventListener(sysParam02, sysParam03, false);
     }else if(window.attachEvent){
       sysParam01.attachEvent('on'+sysParam02, function(){sysParam03.apply(sysParam01);});
     }
   }

   addEvent(window,'load',set01FadeOverInput);

 })();


/**
 * ロールオーバー
 */
/*
function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")){
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
		var inputs = document.getElementsByTagName("input");
		for(var i=0; i < inputs.length; i++) {
			if( inputs[i].getAttribute("type")=="image" ) {
				if(inputs[i].getAttribute("src").match("_off.")){
					inputs[i].onmouseover = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
					}
					inputs[i].onmouseout = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
					}
				}
			}
		}
	}
}
if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}
*/

/**
 * ドゥィーン
 */
function getScrollLeft() { 
 if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {

  /*WinIE6標準モード稼動オブジェクト差異対応
    WinIE6標準モードとそれ以外で、それぞれ稼動しているオブジェクトを取り出す*/
  docele=(document.compatMode=="CSS1Compat")?document.documentElement:document.body;

  return docele.scrollLeft;

 } else if (window.pageXOffset) {
  return window.pageXOffset;
 } else {
  return 0;
 }
}

function getScrollTop() { 
 if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {

  /*WinIE6標準モード稼動オブジェクト差異対応
    WinIE6標準モードとそれ以外で、それぞれ稼動しているオブジェクトを取り出す*/
  docele=(document.compatMode=="CSS1Compat")?document.documentElement:document.body;
  
  return docele.scrollTop;

 } else if (window.pageYOffset) {
  return window.pageYOffset;
 } else {
  return 0;
 }
}

var pageScrollTimer;

function pageScroll(toX,toY,frms,cuX,cuY) { 
 if (pageScrollTimer) clearTimeout(pageScrollTimer);
 if (!toX || toX < 0) toX = 0;
 if (!toY || toY < 0) toY = 0;
 if (!cuX) cuX = 0 + getScrollLeft();
 if (!cuY) cuY = 0 + getScrollTop();
 if (!frms) frms = 6;

 if (toY > cuY && toY > (getAnchorPosObj('end','enddiv').y) - getInnerSize().height) toY = (getAnchorPosObj('end','enddiv').y - getInnerSize().height) + 1;
 cuX += (toX - getScrollLeft()) / frms; if (cuX < 0) cuX = 0;
 cuY += (toY - getScrollTop()) / frms;  if (cuY < 0) cuY = 0;
 var posX = Math.floor(cuX);
 var posY = Math.floor(cuY);
 window.scrollTo(posX, posY);

 if (posX != toX || posY != toY) {
  pageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+cuX+","+cuY+")",16);
 }
}

function jumpToPageTop() { 
  pageScroll(0,0,3);
}



