﻿
  ////////////////////////////////
  // タイムテーブル用スクリプト //
  ////////////////////////////////
  var xmlUrlBasePath = "timeTable_KAB_";	// ＸＭＬファイルのベースパス

  var today  = 0;							// 本日
  var curYmd = 0;							// 現在の表示日

  function moveDay(nDir)
  {
    if (today == 0){
	  today = zGetToday();
	  var hhmm  = zGetNowHhmm();
	  if (hhmm < 400)
	    today = zYmdOpe(today, -1);
	}
	// ｎ日変更
 	curYmd = zYmdOpe(today, nDir);


 	var fixArea = document.getElementById("divTimeTableFixHeaderArea");
	if (fixArea){
		fixArea.innerHTML = "";
	}

    // その週のＸＭＬ（月曜日のファイル名）を生成
	xmlFile = xmlUrlBasePath + zGetMonday(curYmd) + ".xml";

    var loaded = function ( )
    {
	    var yobiEng= new Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
		for (i = 1; i <= 7; i++){
			tthHeader = document.getElementById("tthHeader" + yobiEng[i-1]);
			if (tthHeader){
				tthHeader.innerHTML = "<a href='ttday.html?date=" + zYmdOpe(zGetMonday(curYmd), i-1) + "'>" + tthHeader.innerHTML + "</a>";
			}
		}
    }

	// 週間タイムテーブルの生成
	setTimeTableLoadedFunc(loaded);
    getTimeTableWeek('divTimeTable', xmlFile, false);
    
  }

  function moveKon() { moveDay(0); document.getElementById("kon").src = "files/b-bkonsyu.gif"; document.getElementById("rai").src = "files/b-bjisyu.gif";  }
  function moveRai() { moveDay(7); document.getElementById("kon").src = "files/b-bkonsyu.gif"; document.getElementById("rai").src = "files/b-bjisyu.gif";  }

  var scroll_ｙ_save = 0;

  function func_scroll_check()
  {
	var scroll_ｙ = (document.body.scrollTop || document.documentElement.scrollTop);
	if (scroll_ｙ_save != scroll_ｙ){
		on_scroll_for_timetable();
	}
  }

  var headerAlphaTimer = null;
  var headerOpacity    = 0;

  function func_appha()
  {
    headerOpacity += 1;
	headerFix.style.filter     = 'alpha(opacity=' + (headerOpacity * 10) + ')';
	headerFix.style.MozOpacity = headerOpacity / 10;
	headerFix.style.opacity    = headerOpacity / 10;
	if (headerOpacity >= 100){
		clearInterval(headerAlphaTimer);
		headerAlphaTimer = null;
		headerOpacity    = 0;
	}
  }
  
  

  ////////////////////////////////////////////////////////////////

  function on_load_for_timetable()
  {
		moveKon();	// 今週タイムテーブル

		setInterval("func_scroll_check()", 250);
  }

  function on_scroll_for_timetable()
  {
    if (headerAlphaTimer != null){
		clearInterval(headerAlphaTimer);
		headerAlphaTimer = null;
		headerOpacity    = 0;
	}

    timetable = document.getElementById("divTimeTable");
 	headerDiv = document.getElementById("ttdivHeader");
 	headerFix = document.getElementById("ttdivHeaderFix");
 	fixArea   = document.getElementById("divTimeTableFixHeaderArea");

	if (!timetable || !headerDiv)
		return;

	var scroll_ｙ = (document.body.scrollTop || document.documentElement.scrollTop);
	scroll_ｙ_save = scroll_ｙ;

	if (! headerFix){
		var html = "<div class='ttdivHeader' id='ttdivHeaderFix'>" + headerDiv.innerHTML + "</div>";
		fixArea.innerHTML = html;
		headerDiv = document.getElementById("ttdivHeader");
		headerFix = document.getElementById("ttdivHeaderFix");
	}

	if (headerFix){
		var headerPos = getElementPosition(headerDiv);
		if (headerPos.y < scroll_ｙ){
			headerFix.style.top = scroll_ｙ + "px";
			headerFix.style.filter     = 'alpha(opacity=' + (0 * 10) + ')';
			headerFix.style.MozOpacity = 0 / 10;
			headerFix.style.opacity    = 0 / 10;
			headerFix.style.display = "block";
			headerAlphaTimer = setInterval("func_appha()", 100);
		}
		else{
			headerFix.style.display = "none";
			headerFix.style.top = "0px";
		}
	}	
  }

