/*******************************
 *         フッター定義
 *******************************/


var tkLib = {
	startY : 2009
	,nowDate:new Date()
	,copyRight:function(){
  	yearstr="";
		if(this.nowDate.getFullYear() == this.startY){
			yearstr += this.startY;
		}else{
			yearstr = "2008-" + this.nowDate.getFullYear();
		}
		document.write("Copyright&copy;　" + yearstr + " TAKEDA ENGLISH SCHOOL Corporation. All rights tglerved.");
  }
	
}

/*******************************
 *         ロールオーバー定義
 *******************************/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}




/*******************************
 *     アンカー移動定義
 *******************************/

/*
var pageScrolling = {
	speed : 20,      //set here the scroll speed: when this value increase, the speed decrease. 
	maxStep: 200,	 //set here the "uniform motion" step for long distances
	brakeK: 3,		 //set here the coefficient of slowing down
	hash:null,		
	currentBlock:null,
	requestedY:0,
	init: function() {
			var lnks = document.getElementsByTagName('a');   
			for(var i = 0, lnk; lnk = lnks[i]; i++) {   
				if ((lnk.href && lnk.href.indexOf('#') != -1) &&  ( (lnk.pathname == location.pathname) ||
				('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {  
				lnk.onclick = pageScrolling.initScroll;   		
				}   
			}
			
	},
	getElementYpos: function(el){
			var y = 0;
			while(el.offsetParent){  
				y += el.offsetTop    
				el = el.offsetParent;
			}	return y;
	},		
	getScrollTop: function(){
			if(document.all) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			else return window.pageYOffset;   
	},	
	getWindowHeight: function(){
			if (window.innerHeight)	return window.innerHeight;
			if(document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	},
	getDocumentHeight: function(){
			if (document.height) return document.height;
			if(document.body.offsetHeight) return document.body.offsetHeight;
	},
	initScroll: function(e){
			var targ;  
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;
			
			//alert("TG : " + e.target + " SRC : " + e.srcElement + " FROM : " + e.fromElement );
			var targlink;
			var str = "";
			if(targ.nodeName == "A" || targ.nodeName == "a"){ 
			
				targlink = new String(targ.href);
			
			}else{
				//alert("OBJECT !! LEN : " + targlink.length);
				for (var i in targ) {
					//alert(i);       // ループカウンタにメンバ名が入る。
					//alert(targ[i]);  // 括弧記法でメンバを参照できる。
					str += "KEY : " + i + " VALUE : " + targ[i] + "<br />\n";
				}
				//document.write(str);
				// String型にすることで文字列の長さを取得する
				if(targ.parentNode != null){
					targlink = new String(targ.parentNode);
				} else if(targ.parentElement !=null){
					targlink = new String(targ.parentElement);
				} else if(targ.baseURI !=null){
					targlink = new String(targ.baseURI);
				}
				//alert("TARGETLINK : " + targlink + " TARGET LEN : " + targ.parentNode.length);
			}
			// アンカー情報の取得
			pageScrolling.hash = targlink.substr(targlink.indexOf('#')+1,targlink.length);
			//pageScrolling.hash = targ.href.substr(targ.href.indexOf('#')+1,targ.href.length);
			//alert("HASH : " + pageScrolling.hash);
			pageScrolling.currentBlock = document.getElementById(pageScrolling.hash);   
			if(!pageScrolling.currentBlock) return;
			pageScrolling.requestedY = pageScrolling.getElementYpos(pageScrolling.currentBlock); 
			pageScrolling.scroll();  
			return false;
	},
	scroll: function(){
			var top  = pageScrolling.getScrollTop();
			if(pageScrolling.requestedY > top) {  
				var endDistance = Math.round((pageScrolling.getDocumentHeight() - (top + pageScrolling.getWindowHeight())) / pageScrolling.brakeK);
				endDistance = Math.min(Math.round((pageScrolling.requestedY-top)/ pageScrolling.brakeK), endDistance);
				var offset = Math.max(2, Math.min(endDistance, pageScrolling.maxStep));
			} else { var offset = - Math.min(Math.abs(Math.round((pageScrolling.requestedY-top)/ pageScrolling.brakeK)), pageScrolling.maxStep);
			} window.scrollTo(0, top + offset);  
			if(Math.abs(top-pageScrolling.requestedY) <= 1 || pageScrolling.getScrollTop() == top) {
				window.scrollTo(0, pageScrolling.requestedY);
				//if(!document.all || window.opera) location.hash = pageScrolling.hash;
				pageScrolling.hash = null;
				floatScrolling.flg = true;
			} else 	{
				floatScrolling.flg = false;
				setTimeout(pageScrolling.scroll,pageScrolling.speed);
			}
	}		
}
*/



/*******************************
 *     フロート移動定義
 *******************************/


var floatScrolling = {
	flg: true,
	brName : "",
	
	flayer : "subnavi",		// <DIV>のID名
	baseX : 0,
	baseY : 20,
	
	boxWidth: 0,		//フローティング領域の幅
	//dY=84;
	chN6 : document.getElementById,			// N6のチェック用
	chIE : document.all,								// IEのチェック用
	chN4 : document.layers,							// N4のチェック用
	
	currentX : 0,
	currentY : 0,  
         
	lastScrollX : 0,
	lastScrollY : 0,
	
	lastWidth : 0,
	
	diffY : 0,
	diffX : 0,
	
	px_tani : "",
	
	init: function(){
		if(floatScrolling.chIE) {
			fObj = document.all[floatScrolling.flayer].style;
			
			//alert("Width : " + document.all[floatScrolling.flayer].clientWidth );
			
			var CANVAS = document[ 'CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];	// IE6用処理
			
			px_tani = "";
			floatScrolling.boxWidth = document.all[floatScrolling.flayer].clientWidth;
		}else if(floatScrolling.chN6){
			fObj = document.getElementById(floatScrolling.flayer).style;
			//alert("Width : " + document.getElementById(floatScrolling.flayer).clientWidth );
			px_tani = "px";
			floatScrolling.boxWidth = document.getElementById(floatScrolling.flayer).clientWidth;
		}else if(floatScrolling.chN4){
			fObj = document[flayer];
			//alert("Width : " + document[flayer].clientWidth );
			px_tani = "";
			floatScrolling.boxWidth = document[flayer].clientWidth;
		}
		
		if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
                //IE8　FF
				floatScrolling.baseX = document.documentElement.clientWidth - floatScrolling.boxWidth - 20;
				 
				//alert("1widht: "+ floatScrolling.baseX + "  clientWidth : " + document.documentElement.clientWidth + "  boxWidth : " + floatScrolling.boxWidth);
        }
        else if ( document.body ) {
                floatScrolling.baseX = document.body.clientWidth - floatScrolling.boxWidth - 20;
				//alert("2widht: "+ floatScrolling.baseX + "  clientWidth : " + document.documentElement.clientWidth + "  boxWidth : " + floatScrolling.boxWidth);
        }
		else if ( window.innerWidth ) {
				//Safari
                floatScrolling.baseX = window.innerWidth - floatScrolling.boxWidth - 20;
				//alert("3widht: "+ floatScrolling.baseX + "  innerWidth : " + window.innerWidth + "  boxWidth : " + floatScrolling.boxWidth);
        }
		
       
		
		setInterval("floatScrolling.scroll()",3);
		floatScrolling.brName =navigator.appName.charAt(0);
		
		
		fObj.top = floatScrolling.baseY+px_tani;
		fObj.left = floatScrolling.baseX+px_tani;
		
		 
	},
	
	scroll: function(){
		if(floatScrolling.flg){
			if(floatScrolling.chIE) {
				fObj = document.all[floatScrolling.flayer].style;
				var CANVAS = document[ 'CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];	// IE6用処理
				floatScrolling.diffY = CANVAS.scrollTop; 
				floatScrolling.diffX = CANVAS.scrollLeft;
				px_tani = "";
			}else if(floatScrolling.chN6){
				fObj = document.getElementById(floatScrolling.flayer).style;
				floatScrolling.diffY = pageYOffset;
				floatScrolling.diffX = pageXOffset;
				px_tani = "px";
			}else if(floatScrolling.chN4){
				fObj = document[flayer];
				floatScrolling.diffY = pageYOffset;
				floatScrolling.diffX = pageXOffset;
				px_tani = "";
			}
			if(floatScrolling.diffY != floatScrolling.lastScrollY) {
				percent = 0.1 * (floatScrolling.diffY - floatScrolling.lastScrollY);
				if(percent > 0){
					percent = Math.ceil(percent);
				}else {
					percent = Math.floor(percent);
				}
				
				floatScrolling.lastScrollY = floatScrolling.lastScrollY + percent;
				
				fObj.top = floatScrolling.lastScrollY+floatScrolling.baseY+px_tani;
				//fObj.top = lastScrollY+px_tani;
			}
			if(floatScrolling.diffX != floatScrolling.lastScrollX) {
				percent = 0.1 * (floatScrolling.diffX - floatScrolling.lastScrollX);
				if(percent > 0){
					percent = Math.ceil(percent);
				}else {
					percent = Math.floor(percent);
				}
				
				floatScrolling.lastScrollX = floatScrolling.lastScrollX + percent;
				
				fObj.left = floatScrolling.lastScrollX+floatScrolling.baseX+px_tani;
				//alert("left: "+fObj.left);
				//fObj.left = lastScrollX+px_tani;
			}
		}
	}
}


/*******************************
 *     ページ遷移後移動定義
 *******************************/
　
var nextScrolling = {
	speed : 20, 
	hash:null,	
	requestedY:0,
	
	prep: function() {
		
		if(window.location.hash !=""){
		var query =window.location.hash;
		//alert("QUERY1: " + query + " QUERY LENGTH : " + query.length);
		if(query){
		nextScrolling.hash = query.substr(query.indexOf('#')+1,query.length);
		//alert("KEY : " + nextScrolling.hash);
		window.location.hash = "top";
		}else{
		nextScrolling.hash ="ss";
		}
		
		
		
		}
		
	},
	init: function(){
		nextScrolling.scroll();
	},
	scroll: function() {
			//alert("KEY : " + nextScrolling.hash);		// ← メンバー変数のhashの値が向かう取得できません･･･。
			pageScrolling.hash = nextScrolling.hash;
			pageScrolling.currentBlock = document.getElementById(nextScrolling.hash);   
			if(!pageScrolling.currentBlock) return;
			pageScrolling.requestedY = pageScrolling.getElementYpos(pageScrolling.currentBlock); 
			pageScrolling.scroll();
	}
}

//nextScrolling.prep();



/*******************************
*ポップアップ
*******************************/

function openPage(pageLink,pageWidth,pageHeight)
{
	window.open( pageLink,"new","width=" + pageWidth + ",height=" + pageHeight + ",toolbar=no,status=no,menubar=no,scrollbars=yes,tglizable=no");
}

/*******************************
*ポップアップ
*******************************/
function externalLinks() {
	
	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
		
	}
}

/*******************************
*ポップアップ
*******************************/
function goURL(url){
	//alert(url);
	//alert(location.href);
	//window.location.href = url;
	document.location.href = url;
	//alert(location.href);
}


/*******************************
*ポップアップ
*******************************/
function openWin(wUrl,wWidth,wHeight){
	scWidthCenter=screen.availWidth/2;
	scHeightCenter=screen.availHeight/2;
	wOption = 
	"scrollbars=yes,resizable=no,width="+wWidth+",height="+wHeight+",left="+(scWidthCenter-(wWidth/2))+",top="+(scHeightCenter-(wHeight/2));
	newwindow = window.open(wUrl,'window3',wOption);
	newwindow.focus();
}
function closeWin(){
	newwindow = window.close();
}


/*******************************
*クルーチップ
*******************************/
function cluetipinit(){
	$('a.jt').cluetip({
		cluetipClass: 'marines', 
		arrows: true, 
		dropShadow: false,
		hoverIntent: false,
		sticky: true,
		activation: 'mouseover',
		mouseOutClose: false,
		closePosition: 'title',
		closeText: '<img src="js/cross.png" alt="close" />',
		ajaxCache: false,
		width: 225,
		topOffset: 0,
		leftOffset: 10
	});
}

/*
 * ブラウザー読み込み完了時の処理
 */
window.onload = function() {
	pageScrolling.init();
	
	//nextScrolling.init();
	initRollovers();
	//externalLinks();
	//cluetipinit();
	$('table tr:even').addClass('off');
	$('table tr:even').mouseover(function(ev){
		//this.className='on';
		$(this).removeClass('off');
		$(this).addClass('on');
	});
	$('table tr:even').mouseout(function(ev){
		//this.className='off';
		$(this).removeClass('on');
		$(this).addClass('off');
	});
	$('table tr:odd').addClass('offo');
	$('table tr:odd').mouseover(function(ev){
		//this.className='on';
		$(this).removeClass('offo');
		$(this).addClass('on');
	});
	$('table tr:odd').mouseout(function(ev){
		//this.className='offo';
		$(this).removeClass('on');
		$(this).addClass('offo');
	});
	//フローティングメニュー処理
	//floatScrolling.init();
}

/**
 * ブラウザーウィンドウサイズ変更時の処理
 */
window.onresize = function() {
	//フローティングメニュー位置変更
	//floatScrolling.init();
	
}
