
/*========== 目次 ==========

	1.新規ウィンドウ設定（_blank）
	2.新規ウィンドウ設定（指定）
	3.BOXの高さを揃える設定
	4.エレベータメニュー設定

============================*/





/*==================================================================

	■1.新規ウィンドウ設定（_blank）

====================================================================*/

function externalLinks() {
	if (!document.getElementsByTagName) {
		return;
	} else {
		var aTags = document.getElementsByTagName("a");
		for (var i=0; i<aTags.length; i++) {
			var aTag = aTags[i];
			if (aTag.getAttribute("href") && aTag.getAttribute("rel") == "blank") {
				aTag.target = "_blank";
			}
		}
	}
}

window.onload=externalLinks;





/*==================================================================

	■2.新規ウィンドウ設定（指定）

====================================================================*/

function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}





/*==================================================================

	■3. BOXの高さを揃える指定

====================================================================*/

new function(){
	
	function HeightLine(){
	
		this.className="HeightLine";
		this.parentClassName="HeightLineParent"
		reg = new RegExp(this.className+"([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/¥s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",HeightLine);
}







/*============================
	■4.エレベータメニュー設定
============================*/


window.$e = function( id, s, e ) {
	var eo = new $e.prototype.init( id, s, e );
	eo.setSP(s);
	eo.setEP(e);
	eo.$( id );
	eo.element.method = eo;
	return eo;
}

window.$e.method = $e.prototype = {
	version: '1.0',
	element: '',
	eas: 0,
	frames: 50,
	unit: new Array(),
	
	init: function( id, s, e ) {
		var _curFrame =  0 ; // 現在のフレーム
		
		this.$( id );
		if( !this.element.easingMethod ) this.element.easingMethod = new Object();
		
		this.START = function( id ){
			if( !id ) return false;
			this.element.easingMethod[id] = {
				fn: this.LOOP( id, this ),
				cb: this.CALLBACK
			}
			this.element.easingMethod[id].fn( id, this );
		}
		
		this.LOOP = function( id, self, t ) {
			var _sp = this.sp;
			var _ep = this.ep;
			var _unit = this.unit;
			var _easing = this.eas;
			var _frames = this.frames;
			
			return function ( id, self ) {
				if( _curFrame++ < _frames ){
					var c = _curFrame / _frames ;
					var e = new Array();
					for( var i=0; i<_sp.length; i++ ) {
						e.push( ( parseInt( _ep[i] ) - parseInt( _sp[i] ) ) * ( c + _easing / ( 100 * Math.PI ) * Math.sin( Math.PI * c ) ) + parseInt( _sp[i] ) + _unit[i] );
					}
					if( typeof( self.MAIN ) == 'function' ) self.MAIN( e );
					var _self = self;
					setTimeout( function() {
						_self.element.easingMethod[id].fn( id, _self );
					}, 20 );
				} else {
					if( typeof( self.element.easingMethod[id].cb ) == 'function' ) {
						self.element.easingMethod[id].cb();
						self.element.easingMethod[id].cb = new Function();
					}
				}
			}
		}
	},
	
	setMethod: function( funcName, func ) {
		if( typeof( func ) == 'function' ) this.MAIN = func;
	},
	
	setCallBack: function( func ) {
		if ( typeof( func ) == 'function' ) this.CALLBACK = func;
	},
	
	$: function( obj ) {
		if( !obj ) {
			this.element = window;
		} else {
			var d = ( typeof( obj ) == 'string' ) ? document.getElementById( obj ) : obj;
			var date = new Date();
			date = 'easing' + date.getTime();
			if( !d.easingID ) d.easingID = date;
			this.element = d;
		}
	},
	
	setSP: function( s ) {
		if( typeof( s ) == 'undefined' ) return this;
		if( !( s instanceof Array ) ) this.sp = [ s ];
		else this.sp = s;		// 始点
		this.unit = new Array();
		for( var i=0; i<this.sp.length; i++ ) {
			String(this.sp[i]).match( /([0-9]+)(.*)/ );
			this.unit.push( RegExp.$2 );	//単位の取得
			this.sp[i] = parseInt( this.sp[i] );
		}
		
		return this;
	},
	
	setEP: function( e ) {
		if( typeof( e ) == 'undefined' ) return this;
		if( !( e instanceof Array ) ) this.ep = [ e ];
		else this.ep = e;	// 終点
		
		for( var i=0; i<this.ep.length; i++ ) {
			this.ep[i] = parseInt( this.ep[i] );
		}
		
		return this;
	},
	
	time: function( t ) {
		if( t == 'slow' ) this.frames = 80;
		else if( t == 'normal' ) this.frames = 50;
		else if( t == 'fast' ) this.frames = 20;
		else if( !!t && typeof( parseInt( t ) ) == 'number' ) this.frames = parseInt( t ) / 20;
		return this;
	},
	
	easing: function( e ) {
		if( parseInt( e ) > 100 ) {
			this.eas = 100;
		} else if( parseInt( e ) < -100 ) {
			this.eas = 100;
		} else {
			this.eas = parseInt( e );
		}
		
		return this;
	},
	
	defaultEasing: function( e ) {
		if( parseInt( e ) <= 100 && parseInt( e ) >= -100 ) {
			window.$e.prototype.eas = parseInt( e );
		}
		return this;
	},
	
	STOP: function( id ) {
		if( id && this.element.easingMethod[id] ) this.element.easingMethod[id].fn = function(){}
	},
	
	allSTOP: function() {
		if( this.element.easingMethod ) {
			for( var i in this.element.easingMethod ) {
				this.element.easingMethod[i].fn = new Function();
			}
		}
	}
}

window.$e.prototype.init.prototype = $e.prototype;

$e.method.fade = function( func ) {
	this.setMethod( 'fade', function( val ) {
		this.element.style.opacity = val;
		this.element.style.filter = 'alpha(opacity=' + ( val * 100 ) + ')';
	});
	
	this.setCallBack( func );
	this.START( 'fade' );
	return this;
}

$e.method.move = function( func ) {
	this.setMethod( 'move', function( val ) {
		this.element.style.left = val[0];
		this.element.style.top = val[1];
	});
	
	this.setCallBack( func );
	this.START( 'move' );
	return this;
}

$e.method.zoom = function( func ) {
	this.setMethod( 'zoom', function( val ) {
		this.element.style.width = val[0];
		this.element.style.height = val[1];
	});
	
	this.setCallBack( func );
	this.START( 'zoom' );
	return this;
}

$e.method.smoothScroll = function( func ) {
	this.setMethod( 'smoothScroll', function( val ) {
		val[0] = val[0] || 0;
		val[1] = val[1] || 0;
		this.element.scrollTo( val[0], val[1] );
	});
	
	this.setCallBack( func );
	this.START( 'smoothScroll' );
	return this;
}

function elevator() {
	if( typeof( m ) != 'undefined' ) {
		clearTimeout( m );
	}

	var targetObj = document.getElementById( 'ScrollNavi' ); //対象エレメント
	var parentPbj = document.getElementById( 'Contents' ); //対象親エレメント
	var scrollNum = document.documentElement.scrollTop || document.body.scrollTop;
	scrollNum = scrollNum - 300;
	var targetObjY = targetObj.offsetTop;
	var parentObjH = parentPbj.offsetHeight;
	var targetObjH = targetObj.offsetHeight;	
	var maxY = parentObjH - targetObjH;

	if( scrollNum < 0) {
		scrollNum = 0;
		var o = $e( targetObj, ['16px',targetObjY+'px'], ['16px',(scrollNum+0)+'px'] );
		window.m = setTimeout( function() { o.easing(100).move();}, 100 );
	}
	if(( scrollNum >= 0 ) && ( scrollNum <= maxY )) {
		var o = $e( targetObj, ['16px',targetObjY+'px'], ['16px',(scrollNum+0)+'px'] );
		window.m = setTimeout( function() { o.easing(100).move();}, 100 );
	}
	if( scrollNum > maxY) {
		scrollNum = maxY;
		var o = $e( targetObj, ['16px',targetObjY+'px'], ['16px',(scrollNum+0)+'px'] );
		window.m = setTimeout( function() { o.easing(100).move();}, 100 );
	}
}

window.onscroll = elevator;



