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 opera9 = (navigator.userAgent.indexOf("Opera/9") != -1) || false;
var opera = (navigator.userAgent.indexOf("Opera") != -1 && !opera9) || 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 drawTopicsInfo() {
if (document.getElementById){
		document.write('<p class="note">各トピックタイトル左のアイコンをクリックすると情報の開閉ができます。</p>');
}
}

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

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 (opera || opera9) {
				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 re = new RegExp(target, "i");
	var temp = 0;
		
	while(dl.item(temp) !== null) {
		if(dl.item(temp).className.search(re) != -1 || 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 = 70;

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

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

// #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 || opera9) {
		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 class="all"><a href="#all" onkeypress="document.focus(); openCloseDiscography(\'all\'); return false;" onclick="openCloseDiscography(\'all\'); return false;">ALL</a></li>');
		document.write('<li><a href="#dvd" onkeypress="document.focus(); openCloseDiscography(\'dvd\'); return false;" onclick="openCloseDiscography(\'dvd\'); return false;">DVD / VHS</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 class="all"><a href="#all" onkeypress="document.focus(); openCloseTABLE(\'all\'); return false;" onclick="openCloseTABLE(\'all\'); return false;">ALL</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 />');
	}
}

//####################################//
//## macIE テーブルボーダーバグ回避 ##//
//####################################//
function autoClick() {
	if(macIE) {
		openCloseTABLE('all');
	}
}

//###################################//
//## Opera9 表示バグ対応スクリプト ##//
//###################################//
function delMark() {
	if(opera9) {
		window.onscroll = function(e) {
			var list = document.getElementById("list");
			changeWidth(list, 564);
			setTimeout("changeWidth(list, 565)", 1);
		}
	}
}
function changeWidth(obj, width) {
	obj.style.width = width + "px";
}