var win = (navigator.userAgent.indexOf("Windows") != -1) || false;
var mac = (navigator.userAgent.indexOf("PPC Mac") != -1 || navigator.userAgent.indexOf("PowerPC") != -1 ) || false;
var intelMac = (navigator.userAgent.indexOf("Intel Mac") != -1) || false;
var ie = (document.all && win) || false;
var ie7 =(navigator.userAgent.indexOf("MSIE 7") != -1) || false;
var macIE = (navigator.userAgent.indexOf("MSIE") != -1 && mac) || false;
var firefox = (navigator.userAgent.indexOf("Firefox") != -1) || false;
var opera = (navigator.userAgent.indexOf("Opera") != -1) || false;
var opera9 = (navigator.userAgent.indexOf("Opera/9") != -1) || false;
var safari = (navigator.userAgent.indexOf("Safari") != -1) || false;
var camino = (navigator.userAgent.indexOf("Camino") != -1) || false;
var omniweb = (navigator.userAgent.indexOf("OmniWeb") != -1) || false;

function ctrlFont() {
if (document.getElementById){
	if(ie7 || opera9) {
		var body = document.getElementsByTagName("BODY");
		body.item(0).style.fontFamily = "Meiryo";
	} else {
		return;
	}
}
}

function ctrlH1() {
if (document.getElementById){
	if(opera) {
		var h1 = document.getElementsByTagName("H1");
		h1.item(0).style.zIndex = -1;
	} else {
		return;
	}
}
}

function ctrlEmbed() {
if (document.getElementById){
	if(opera) {
		var obj = document.getElementsByTagName("EMBED");
		obj.item(0).style.zIndex = -1;
	} else {
		return;
	}
}
}

function drawH1(page) {
if (document.getElementById){
	if(macIE) {
		document.write('<h1 class="' + page + '">中ノ森BAND</h1>\n');
	} else {
		if((win && (safari || firefox || opera)) || ((intelMac || mac) && ((safari && !omniweb) || firefox || camino)) || ie) {
			document.write('<h1>中ノ森BAND</h1>\n');
		} else {
			document.write('<h1 class="' + page + '">中ノ森BAND</h1>\n');
		}
	}
}
}

function drawTopicsInfo() {
if (document.getElementById){
		document.write('<p class="note">各トピックタイトル左のアイコンをクリックすると情報の開閉ができます。</p>');
}
}

//##################//
//## 更新チェック ##//
//##################//

function checkModify() {
if (document.getElementById){
	//何日間を新着期間とするか
	var day = 3; //日
	
	var d1 = new Date();
	var d2 = new Date(document.lastModified);
	var div = document.getElementById("modify");
	var h2 = div.firstChild;
	while (h2.nodeName != "H2") {
			h2 = h2.nextSibling;
	}		
	if(d1.getTime() - d2.getTime() < 1000 * 60 * 60 * 24 * day) {
		if(win || firefox) {
			div.style.backgroundImage = "url(./img/back_modify_move.gif)";
		}
		h2.style.backgroundImage = "url(./img/h2_modify.gif)";
	} else {
		if(win || firefox) {
			div.style.backgroundImage = "url(./img/back_modify_stop.gif)";
		}
	}
}
}
	

//############################//
//## トピックスコントロール ##//
//############################//

function ddClose() {
if (document.getElementById){
	var dd = document.getElementsByTagName("DD");
	var temp = 0;
	while(dd.item(temp) !== null) {
		if( dd.item(temp).firstChild.nodeName == "EM") {
			var  y = dd.item(temp);
			while (y.nodeName != "DT") {
				y = y.previousSibling;
			}
			y.style.fontWeight = "bold";
			y.title="タイトル左のアイコンをクリックすると情報の開閉ができます。";
			var img = y.firstChild;
			while (img.nodeName != "IMG") {
				img = img.firstChild;
			}
			img.alt = "詳細を閉じる（javascript使用）";
			img.title = "詳細を閉じる（javascript使用）";
			img.src = "./img/icon_minus.gif";
			while (y != null) {
				if (y.nodeName == "DD") {
					y.style.display = "block";
					temp++;
				}
				y = y.nextSibling;
			}
			temp--;
		} else if(dd.item(temp).className != "date" && dd.item(temp).parentNode.parentNode.id == "topics") {
			dd.item(temp).style.display = "none";
			var  z= dd.item(temp);
			while (z.nodeName != "DT") {
				z = z.previousSibling;
			}
			z.style.fontWeight = "normal";
            z.title="タイトル左のアイコンをクリックすると情報の開閉ができます。";
			
			var img = z.firstChild;
			while (img.nodeName != "IMG") {
				img = img.firstChild;
			}
			img.alt = "詳細を開く（javascript使用）";
			img.title = "詳細を開く（javascript使用）";
			img.src = "./img/icon_plus.gif";
		}
		temp++;
	}
}
}

function openCloseDD(obj) {
if (document.getElementById){
	while (obj.nodeName != "IMG") {
		obj = obj.firstChild;
	}
	var target = obj.parentNode;
	while (target.nodeName != "DT") {
		target = target.parentNode;
	}
	
	while(target != null) {
		if (target.nodeName == "DT") {
			var s1 = target.style.fontWeight;
			if (navigator.userAgent.indexOf("Opera") != -1) {
				if (s1 != 700) {
					target.style.fontWeight = "bold";
				} else {
					target.style.fontWeight = "normal";
				}
			} else {
				if (s1 != "bold") {
					target.style.fontWeight = "bold";
				} else {
					target.style.fontWeight = "normal";
				}
			}
		} 
		if (target.nodeName == "DD" && target.className != "date") {
			var s2 = target.style.display;
			if (s2 != "block") {
				target.style.display = "block";
				obj.alt = "詳細を閉じる（javascript使用）";
				obj.title = "詳細を閉じる（javascript使用）";
				obj.src = "./img/icon_minus.gif";
			} else {
				target.style.display = "none";
				obj.alt = "詳細を開く（javascript使用）";
				obj.title = "詳細を開く（javascript使用）";
				obj.src = "./img/icon_plus.gif";
			}
			target = target.nextSibling;
		} else {
			target = target.nextSibling;
		}
	}
}
}

//####################################//
//## ディスコグラフィーアイテム選択 ##//
//####################################//

function openCloseDiscography(target) {
if (document.getElementById){
    var dl = document.getElementsByTagName("DL");
    var temp = 0;
        
    while(dl.item(temp) !== null) {
        
        if(dl.item(temp).className == target || dl.item(temp).className == target + "-high" || target == "all") {
            dl.item(temp).style.display = "block";
        } else {
            dl.item(temp).style.display = "none"
        }
        temp++;
    }
}
}

//##############################//
//## スケジュールアイテム選択 ##//
//##############################//

function openCloseTABLE(target) {
if (document.getElementById){
    var table = document.getElementsByTagName("TABLE");
    var temp = 0;
    
    while(table.item(temp) !== null) {
        
        if(table.item(temp).id == target || target == "all") {
            table.item(temp).style.display = "block";
        } else {
            table.item(temp).style.display = "none"
        }
        temp++;
    }
}
}
//########################################//
//## 指定したアイテムをウインドウに固定 ##//
//########################################//

// body の margin-top プロパティの値
bodyMarginTop = 60;

// #ctrl の margin-top プロパティの値
ctrlMarginTop  = 350; 

// #release-info の margin-top プロパティの値
releaseInfoMarginTop = 400;

// #jacket の top プロパティの値
initJacket = 0;

function fixedItem(flag, limit) {
if (document.getElementById){
	
	temp_flag = flag;
	temp_limit = limit;

	getScroll();
	
	switch(flag) {
		case "J":
			fixedJacket(temp_limit);
			break;
		case "C":
			fixedCtrl(temp_limit);
			break;
		default:
			break;
	}
	
	setTimeout("fixedItem(temp_flag, temp_limit)", 20)
}
}

function fixedCtrl(limit) {
    obj = document.getElementById("ctrl");

	if(!macIE) {
		if(pageY < limit) {
			if(bodyMarginTop + ctrlMarginTop - pageY < 0) {
				obj.style.top = pageY - bodyMarginTop - ctrlMarginTop + "px";
			} else {
				obj.style.top = 0 + "px";
			}
		}
	}
}

function fixedJacket(limit) {
    obj = document.getElementById("jacket");
	
	if(pageY < limit) {
		if(bodyMarginTop + releaseInfoMarginTop + initJacket - pageY < 0) {
			if(opera) {
				obj.style.marginTop = pageY - bodyMarginTop - releaseInfoMarginTop + "px";
			} else {
				obj.style.top = pageY - bodyMarginTop - releaseInfoMarginTop + "px";
			}
 		} else {
			if(opera) {
				obj.style.marginTop = initJacket + "px";
			} else {
				obj.style.top = initJacket + "px";
			}
		}
	}
}

//##########################//
//## スクロール幅取得関数 ##//
//##########################//
function getScroll() {
	if(ie7) {
		pageY = document.documentElement.scrollTop;
	} else if(macIE) {
		pageY = document.body.scrollTop;
	} else if(ie) {
		pageY = document.body.scrollTop;
	} else if(navigator.userAgent.indexOf("Netscape") != -1) {
		pageY = document.body.scrollTop;
	} else if(safari) {
		pageY = window.pageYOffset;
	} else if(firefox || omniweb) {
		pageY = window.pageYOffset;
	} else if(opera) {
		pageY = window.pageYOffset;
	} else {
		pageY = 0;
	}
}

//##########################//
//## ウインドウスクロール ##//
//##########################//

function pageScroll() {
	var scroll = 1;
	getScroll();
	if(scroll < 50 && pageY && pageY != null) {
		pageY = (pageY > 3) ? Math.ceil(pageY * 0.2) : 1;
		scroll++;
		scrollBy(0,-pageY);
		setTimeout("pageScroll()", 20);
	} else {
		scrollTo(0, 0);
		scroll = 1;
	}
}

//##############################################//
//## ディスコグラフィーのコントローラ表示関数 ##//
//##############################################//

function drawCtrl(page) {
	if(page == 'discography') {
		document.write('<div id="ctrl">');
		document.write('<h2>表示コントロール</h2>');
		document.write('<ul>');
		document.write('<li><a href="#all" onkeypress="document.focus(); openCloseDiscography(\'all\'); return false;" onclick="openCloseDiscography(\'all\'); return false;">ALL</a></li>');
		document.write('<li><a href="#album" onkeypress="document.focus(); openCloseDiscography(\'album\'); return false;" onclick="openCloseDiscography(\'album\'); return false;">Album</a></li>');
		document.write('<li><a href="#single" onkeypress="document.focus(); openCloseDiscography(\'single\'); return false;" onclick="openCloseDiscography(\'single\'); return false;">Single</a></li>');
		document.write('</ul>');
		document.write('</div>');
		document.write('<hr />');
	} else if(page == 'schedule'){
		document.write('<div id="ctrl">');
		document.write('<h2>表示コントロール</h2>');
		document.write('<ul>');
		document.write('<li><a href="#all" onkeypress="document.focus(); openCloseTABLE(\'all\'); return false;" onclick="openCloseTABLE(\'all\'); return false;">ALL</a></li>');
		document.write('<li><a href="#regular" onkeypress="document.focus(); openCloseTABLE(\'regular\'); return false;" onclick="openCloseTABLE(\'regular\'); return false;">Regular</a></li>');
		document.write('<li><a href="#web" onkeypress="document.focus(); openCloseTABLE(\'web\'); return false;" onclick="openCloseTABLE(\'web\'); return false;">Web</a></li>');
		document.write('<li><a href="#tv" onkeypress="document.focus(); openCloseTABLE(\'tv\'); return false;" onclick="openCloseTABLE(\'tv\'); return false;">TV</a></li>');
		document.write('<li><a href="#radio" onkeypress="document.focus(); openCloseTABLE(\'radio\'); return false;" onclick="openCloseTABLE(\'radio\'); return false;">Radio</a></li>');
		document.write('<li><a href="#magazine" onkeypress="document.focus(); openCloseTABLE(\'magazine\'); return false;" onclick="openCloseTABLE(\'magazine\'); return false;">Magazine</a></li>');
		document.write('<li><a href="#etc" onkeypress="document.focus(); openCloseTABLE(\'etc\'); return false;" onclick="openCloseTABLE(\'etc\'); return false;">etc</a></li>');
		document.write('<li><a href="#event" onkeypress="document.focus(); openCloseTABLE(\'event\'); return false;" onclick="openCloseTABLE(\'event\'); return false;">Live / Event</a></li>');
		document.write('</ul>');
		document.write('</div>');
		document.write('<hr />');
	}
}

function autoClick() {
	if(macIE) {
		openCloseTABLE('all');
	}
}

//################################//
//## 閲覧人数カウントプログラム ##//
//################################//
var WhoIsOnline = {
	'option' : {
		'repeatID' : setTimeout("", 30000)
	},
	
	'init' : function() {
		var that = this;
		
		if(window.XMLHttpRequest) {
			var message = new XMLHttpRequest;
		} else if(window.ActiveXObject) {
			try {
				var message = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				var message = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			return null;
		}
		
		message.onreadystatechange = function() {
			if(message.readyState == 4) {
				if(message.status == 200) {
					//成功
				} else {
					//失敗
				}
			} else {
				//取得中
			}
		}
		
		if(location.href.match(/^http:/)) {
			this.option.repeatID = this.open(message);
		}
	},
	
	'open' : function(xmlhttp) {
		var that = this;
		
		try {
			var dummyTime = (new Date()).getTime();
			
			xmlhttp.open('GET', location.protocol + "//www.teichiku.co.jp/script/analyze/who_is_online.php?url=" + encodeURIComponent(location.href.replace(/index\.(html|php)/, "")) + "&t=" + dummyTime, true);
			xmlhttp.send(null);
			
			return setTimeout(function() {
				that.option.repeatID = that.open(xmlhttp);
			}, 30000);
		} catch(e) {
			
		}
	}
};

