// JavaScript Document

var playWin;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function liveWindow(theURL) { //v2.0
  if(playWin) {
    try {
      if(playWin.closed) {
        playWin = window.open(theURL,'live','status=yes,scrollbars=no,resizable=no,width=450,height=420');
      } else if(playWin.name == 'live') {
        // Existed Live Player
      } else if(playWin.name == 'demand'){ 
        playWin.close();
        playWin = window.open(theURL,'live','status=yes,scrollbars=no,resizable=no,width=450,height=420');
      }
    } catch(e) {}
  } else {
    playWin = window.open(theURL,'live','status=yes,scrollbars=no,resizable=no,width=450,height=420');
  }
}

function demandWindow(theURL) { //v2.0
  if(playWin) {
    try {
      if(playWin.closed) {
        playWin = window.open(theURL,'demand','status=yes,scrollbars=no,resizable=no,width=450,height=360');
      } else if(playWin.name == 'demand') {
        //Existed Demand Player
        playWin = window.open(theURL,'demand','status=yes,scrollbars=no,resizable=no,width=450,height=360');
      } else if(playWin.name == 'live'){ 
        playWin.close();
        playWin = window.open(theURL,'demand','status=yes,scrollbars=no,resizable=no,width=450,height=360');
      }
    } catch(e) {}
  } else {
    playWin = window.open(theURL,'demand','status=yes,scrollbars=no,resizable=no,width=450,height=360');
  }
}
function moreWindow(theURL) { //v2.0
  window.open(theURL,'more','status=yes,scrollbars=no,resizable=no,width=645,height=320');
}
function newsWindow(theURL) { //v2.0
  window.open(theURL,'news','status=yes,scrollbars=yes,resizable=yes,width=630,height=600');
}
function enterWindow(theURL) { //v2.0
  window.open(theURL,'enter','status=yes,scrollbars=yes,resizable=yes,width=600,height=600');
}
function sponsorWindow(theURL) { //v2.0
  window.open(theURL,'sponsor','status=yes,scrollbars=yes,resizable=yes,width=630,height=600');
}
function do_show() { 
    Element.show('timetable'); 
    // Element.show('sample', 'sample2'); のようにして2個同時に表示することも可能 
} 
function do_hide() { 
    Element.hide('timetable'); 
}



function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop()", 25);
  }
	//<a href="#" onclick="backToTop(); return false" class="jumpto">このページの先頭へ</a>
}

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(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)CCN[j].style.height = max_height + "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++){
						objCN[key][i].style.height = max_height + "px";
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",heightLine);
}

