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 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 ie = (document.all && win && !opera && !opera9) || false;
var ie7 = (navigator.userAgent.indexOf("MSIE 7") != -1) || false;
var ie5 = (!document.getElementByID && navigator.userAgent.indexOf("MSIE 5") != -1) || false;
var macIE = (navigator.userAgent.indexOf("MSIE") != -1 && mac) || 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;
var netscape = (navigator.userAgent.indexOf("Netscape") != -1) || false;


function initTribute() {
	if(ie || ie7) {
		flexWidth();
	}
	ctrlSafariWidth();
	if(window.ie6) changePNG('./', 'tribute');
}

function initArtist() {
	delItem();
	forceFont("artist", "#444444");
	if(ie || ie7) {
		flexWidth();
	}
	ctrlSafariWidth();
}

//#######################//
//## フレキシブルWidth ##//
//#######################//

function flexWidth(target) {
	window.attachEvent('onresize',  chkContentsWidth());
	setTimeout(chkContentsWidth(target), 1);
}

function chkContentsWidth(target) {
	return function () {
		var body = document.getElementById("main");
		var width = getWindowWidth();
		
		if(width < 1024) {
			if(target == 'sche') {
				body.style.width = "99%";
				setTimeout(function() {	body.style.width = "100%"; }, 1);
			} else {
				body.style.width = "100%";
			}
		} else {
			if(target == 'sche') {
				body.style.width = "1023px";
				setTimeout(function() { body.style.width = "1024px"; }, 1);
			} else {
				body.style.width = "1024px";
			}
		}
	}
}

function getWindowWidth() {
	return document.body.clientWidth
}
//################################//
//## Safari用 widthコントロール ##//
//################################//
function ctrlSafariWidth() {
	if(safari) {
		var body = document.getElementsByTagName("BODY");
		body[0].style.width = "99.5%";
	}
}

//########################################//
//## Aタグにsmoothbox用のパラメータ追加 ##//
//########################################//
function addParam() {
	var aTags = document.getElementsByTagName("A");
	var aTagsLength = aTags.length;
	
	for(var i = 0; i < aTagsLength; i++) {
		if(aTags[i].className == "smoothbox" && !macIE) {
			aTags[i].href += "?keepThis=true&TB_iframe=true&width=700&height=420";
		}
		
	}
}

//################################################//
//## トップページliタグ全体をクリック範囲にする ##//
//################################################//
function addClick() {
	var div = document.getElementById("artist");
	var liTags = div.getElementsByTagName("LI");
	var liTagsLength = liTags.length;
	
	for(var i = 0; i < liTagsLength; i++) {
		var ATags = liTags[i].getElementsByTagName("A");
		liTags[i].href = ATags[0].href + "?keepThis=true&TB_iframe=true&width=700&height=420";
		liTags[i].title = ATags[0].title;
		liTags[i].className = "smoothbox";
		ATags[0].style.textDecoration = "none";
		if(!ie5) {
			liTags[i].style.cursor = "pointer";
		}
		liTags[i].onmouseover = function () {
			this.style.backgroundImage = "url(./img/basic/back_animation.gif)";
		}
		liTags[i].onmouseout = function () {
			this.style.backgroundImage = "url(./img/basic/back_artist_li.png)";
		}
	}
}

function addJumpButton() {
	if(!opera9 && !opera && !macIE) {
		var div = document.getElementById("main");
		var liTags = div.getElementsByTagName("LI");
		var liTagsLength = liTags.length;
		
		
		for(var i = 0; i < liTagsLength; i++) {
			var ATags = liTags[i].getElementsByTagName("A");
			
			var div = document.createElement("div");
			var a = document.createElement("a");
			var img = document.createElement("img");
			
			a.appendChild(img);
			div.appendChild(a);
			liTags[i].appendChild(div);
			
			div.className = "jump";
			
			a.setAttribute("href", ATags[0].href);
			a.setAttribute("title", "このアイコンをクリックするとページを切り替えて詳細を表示します");
			
			img.setAttribute("src", "http://www.teichiku.co.jp/artist/takuro/tributeimg/basic/icon_jump.gif");
			img.setAttribute("width", 15);
			img.setAttribute("height", 15);
			img.setAttribute("alt", "このアイコンをクリックするとページを切り替えて詳細を表示します");
			img.jump = ATags[0].href;
			img.onclick = function() {
				location.href = this.jump;
			};
		}
	}
}

//####################################//
//## ページ切り替えアイコン説明表示 ##//
//####################################//
function showEx(select) {
	if(!opera9 && !opera && !macIE) {
		switch(select) {
			case 'jump':
				document.write('<p class="ex"><img src="http://www.teichiku.co.jp/artist/takuro/tribute/img/basic/icon_jump.gif" width="15" height="15" alt="ページを切り替えて表示します" /> このアイコンをクリックするとページを切り替えて詳細を表示します。（標準では同じページ内に展開）</p>');
			default:
				retrurn;
		}
	}
}


//###################################//
//## smoothbox用カタログページ整形 ##//
//###################################//
function delItem() {
	var ref = document.location.href;
	if(ref.indexOf("?") != -1 && !macIE) {
		var temp;
		
		//div#main スタイル変更
		if(temp = document.getElementById("main")) {
			temp.style.width = "100%";
			temp.style.margin = "-15px auto 0 auto";
			temp.style.padding = "0";
			temp.style.border = "none";
		}
		
		//body スタイル変更
		
		//ヘッダ削除
		if(temp = document.getElementById("header")) temp.style.display = "none";
		
		//h2削除
		if(temp = document.getElementById("h2")) temp.style.display = "none";
		
		//フッタ 削除
		if(temp = document.getElementById("footer")) temp.style.display = "none";
		
		//アクセス解析 削除
		if(temp = document.getElementById("analyze")) temp.style.display = "none";
		
		setJump();
	}
}

//####################################################################//
//## IE6 XP 用 メイリオ適用 XHTML1.1 こっそりlang属性付加します関数 ##//
//####################################################################//
function xpIE6() {
	if (window.ActiveXObject && !window.XMLHttpRequest){
		var temp;
		if(temp = document.getElementById("artist")) temp.lang = "ja";
		if(temp = document.getElementById("artist")) temp.lang = "ja";
		return;
	}
}
//######################//
//## IE7  用 強制BOLD ##//
//######################//
function forceFont(target, color) {
	if (window.ActiveXObject && window.XMLHttpRequest){
		var ref = document.location.href;
		if(ref.indexOf("?") != -1 && !macIE) {
			var temp;
			if(temp = document.getElementById(target)) {
				temp.style.color = color;
				temp.style.fontWeight = "bold";
			}
		}
		return;
	}
}

//##################################//
//## リンク先を別ウィンドウで開く ##//
//##################################//
function setJump() {
	var aTags = document.getElementsByTagName("A");
	for(var i = 0; i < aTags.length; i++) {
		aTags[i].onclick = function() {
			dialog(this);
			return false;
		}
	}
}

function dialog(obj) {
	if(obj.href != "") {
		var address = location.href.split("#");
		if(obj.href.indexOf("#") != -1) {
			if(obj.href.indexOf(address[0]) != -1) {
				if(confirm('ページ内を移動します（画面がスクロール）')) {
					location.href = obj.href;
				}
			} else {
				if(confirm('リンク先を別ウィンドウで開きます（あらかじめポップアップを許可しておいて下さい）')) {
					window.open(obj.href, null);
				}
			}
		} else {
			if(confirm('リンク先を別ウィンドウで開きます（あらかじめポップアップを許可しておいて下さい）')) {
				window.open(obj.href, null);
			}
		}
	}
}

//######################//
//## IE6で透明PNG使用 ##//
//######################//
function changePNG(level, type) {
	var main = document.getElementById("main");
	var h2 = main.getElementsByTagName("H2");
	
	switch(type) {
		case "top":
			h2[0].runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + level + "img/basic/back_h2_main.png" + '", sizingmethod="image")';
			h2[0].style.backgroundImage = "none";
			break;
		case "profile":
			h2[0].runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + level + "img/basic/back_h2_main.png" + '", sizingmethod="image")';
			h2[0].style.backgroundImage = "none";
			break;
		case "tribute":
			h2[0].runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + level + "img/basic/back_h2_tribute.png" + '", sizingmethod="image")';
			h2[0].style.backgroundImage = "none";
			break;
		default:
			var img = document.getElementsByTagName("IMG");
			var exp = new RegExp("\.png$", "i");
			
			for(var i = 0; i < img.length; i++) {
				if(img[i].src.search(exp) != -1) {
					img[i].runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + img[i].src + '", sizingmethod="scale")';
					img[i].src = "http://www.teichiku.co.jp/artist/takuro/img/basic/blank.gif";
				}
			}
			break;
	}
}
