//#####################################################################################//
//## アンカー付URLだったらアンカー情報をGETメソッドパラメータに変更してリダイレクト ###//
//#####################################################################################//
(function() {
	if(location.href.match(/#/)) {
		var temp = location.href.split("#");
		var baseURL = temp[0];
		var anchor = temp[temp.length - 1];
		location.replace(baseURL + "?anchor=" + anchor);
	}
})();

//#########################//
//## Stringメソッド拡張 ###//
//#########################//
String.prototype.camelize = function() {
    return this.replace(/-([a-z])/g, function($0, $1) {
    	return $1.toUpperCase()
    });
}
String.prototype.deCamelize = function() {
    return this.replace(/[A-Z]/g, function($0) {
    	return "-" + $0.toLowerCase()
    });
}

//###################//
//## 各種情報取得 ###//
//###################//
var GET = {
	'className' : function(obj) {
		return obj.getAttribute('class') || obj.getAttribute('className');
	},
	
	'posX' : function(IDorOBJ) {
		if(typeof IDorOBJ != 'string') {
			var target = IDorOBJ;
		} else {
			var target = document.getElementById(IDorOBJ);
		}
		
		var posX = 0;
		
		do {
			posX += target.offsetLeft || 0;
			if(target.nodeName != "BODY" && YAHOO.env.ua.ie != 7) posX -= target.scrollLeft || 0;
			if(!YAHOO.env.ua.opera && YAHOO.env.ua.ie != 8 && parseInt(this.style(target, "border-left-width"))) {
				posX += parseInt(this.style(target, "border-left-width"));
			}
			
			target = target.offsetParent;
		} while(target);
		
		return posX;
	},
	
	'posY' : function(IDorOBJ) {
		if(typeof IDorOBJ != 'string') {
			var target = IDorOBJ;
		} else {
			var target = document.getElementById(IDorOBJ);
		}
		
		var posY = 0;
		
		do {
			posY += target.offsetTop || 0;
			if(target.nodeName != "BODY" && YAHOO.env.ua.ie != 7) posY -= target.scrollTop || 0;
			if(!YAHOO.env.ua.opera && YAHOO.env.ua.ie != 8 && parseInt(this.style(target, "border-top-width"))) {
				posY += parseInt(this.style(target, "border-top-width"));
			}
			
			target = target.offsetParent;
		} while(target);
		
		return posY;
	},
	
	'scrollX' : function() {
		return document.body.scrollLeft || document.documentElement.scrollLeft;
	},
	
	'scrollY' : function() {
		return document.body.scrollTop || document.documentElement.scrollTop;
	},
	
	'browserWidth' : function() {
		return document.documentElement.clientWidth ? document.documentElement.clientWidth : (window.innerWidth ? window.innerWidth : document.body.clientWidth)
	},
	
	'browserHeight' : function() {
		return document.documentElement.clientHeight ? document.documentElement.clientHeight : (window.innerHeight ? window.innerHeight : document.body.clientHeight)
	},
	
	'pageSize' : function() {
		return document.body.scrollHeight ? document.body.scrollHeight : document.documentElement.scrollHeight;
	},
	
	'style' : function (element, property, pseudo) {
		if(element.currentStyle) {
			//IE or Opera
			if(property.indexOf("-") != -1) property = property.camelize();
			return element.currentStyle[property];
		} else if(getComputedStyle) {
			//Mozilla or Opera
			if(property.indexOf("-") == -1) property = property.deCamelize();
			return getComputedStyle(element, pseudo).getPropertyValue(property);
		}
		
		return "";
	},
	
	'mouse' : function(e) {
		var obj = new Object;
		
		if(e) {
			obj.x = e.pageX;
			obj.y = e.pageY;
		} else {
			obj.x = event.clientX + GET.scrollX();
			obj.y = event.clientY + GET.scrollY();
		}
		
		return obj;
	}
};

//###############################//
//## #main の幅をコントロール ###//
//###############################//
var CtrlMainWidth = {
	'option' : {
		'width' : 950,
		'borderWidth': 0
	},
	
	'force' : function() {
		var that = this;
		
		var main = document.getElementById("main");
		if(parseInt(GET.style(main, "border-left-width")) && parseInt(GET.style(main, "border-right-width"))) {
			this.option.borderWidth = parseInt(GET.style(main, "border-left-width")) + parseInt(GET.style(main, "border-right-width"));
		}
		
		if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
			main.style.width = this.option.width + this.option.borderWidth - 1 + "px";
		} else {
			main.style.width = this.option.width - 1 + "px";
		}
		setTimeout(function() {
			if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
				main.style.width = that.option.width + that.option.borderWidth + "px";
			} else {
				main.style.width = that.option.width + "px";
			}
		}, 1);
	}
};

//###################################//
//## ヘッダとフッタをコントロール ###//
//###################################//
var CtrlHeaderFooter = {
	'option' : {
		'mainWidth' : 950,
		'borderWidth': 0
	},
	
	'init' : function() {
		var that = this;
		
		var main = document.getElementById("main");
		if(parseInt(GET.style(main, "border-left-width")) && parseInt(GET.style(main, "border-right-width"))) {
			this.option.borderWidth = parseInt(GET.style(main, "border-left-width")) + parseInt(GET.style(main, "border-right-width"));
		}
		
		if(!YAHOO.env.ua.ie) {
			var body = document.getElementsByTagName("body")[0];
			body.style.overflowY = "scroll";
		}
		
		this.resize();
		
		if(window.addEventListener) { 
			window.addEventListener("scroll", function() {
				that.resize();
			}, false);
			window.addEventListener("resize", function() {
				that.resize();
			}, false);
		} else if(window.attachEvent) {
			window.attachEvent("onscroll", function() {
				that.resize();
			});
			window.attachEvent("onresize", function() {
				that.resize();
			});
		}
	},
	
	'resize': function() {
		var header = document.getElementById("header");
		var footer = document.getElementById("footer");
		
		if(GET.browserWidth() < this.option.mainWidth + this.option.borderWidth) {
			header.style.width = GET.scrollX() + GET.browserWidth() + "px";
			footer.style.width = GET.scrollX() + GET.browserWidth() + "px";
		} else {
			header.style.width = "100%";
			footer.style.width = "100%";
		}
	}
};

//#################//
//## FineScroll ###//
//#################//
var FineScroll = {
	'option' : {
		'k': 0.25,
		'scrollID' : setTimeout("", 20),
		'delayID' : setTimeout("", 500)
	},
	
	'init' : function(id) {
		var that = this;
		
		var parent = document;
		if(id && document.getElementById(id)) {
			parent = document.getElementById(id);
		}
		
		var aTags = parent.getElementsByTagName("A");
		
		for(var i = 0, len_i = aTags.length; i < len_i; i++) {
			if(aTags[i].getAttribute("href") && aTags[i].getAttribute("href").match(/#/)) {
				aTags[i].baseURL  = aTags[i].getAttribute("href").replace(/(.*)#(.+)$/i, "$1");
				aTags[i].targetID  = aTags[i].getAttribute("href").replace(/(.*)#(.+)$/i, "$2");
				
				if((location.href).indexOf(aTags[i].baseURL) != -1) {
					aTags[i].onclick = function() {
						clearTimeout(that.option.scrollID);
						
						if(document.getElementById(this.targetID)) {
							that.option.scrollID = that.setFunc(this.targetID);
						}
						
						return false;
					}
				}
			}
		}
		
		if(YAHOO.env.ua.webkit) {
			window.addEventListener('mousewheel', function() {
    			clearTimeout(that.option.scrollID);
			}, false);
		} else if(YAHOO.env.ua.ie || YAHOO.env.ua.opera) {
			window.onmousewheel = document.onmousewheel = function() {
				clearTimeout(that.option.scrollID);
			}
		} else {
			window.addEventListener('DOMMouseScroll', function() {
    			clearTimeout(that.option.scrollID);
			}, false);
		}
		
		if(YAHOO.env.ua.webkit && !YAHOO.env.ua.chrome && typeof window.addEventListener == 'function') {
			window.addEventListener('scroll', function() {
				clearTimeout(that.option.scrollID);
			}, false);
		}
		
		if(location.href.match(/\?anchor=/)) {
			clearTimeout(this.option.scrollID);
			
			var query = location.search.substring(1); 
			var temp = query.split("=");
			
			this.option.delayID = setTimeout(function() {
				clearTimeout(that.option.delayID);
				that.option.scrollID = that.setFunc(temp[temp.length - 1]);
			}, 500);
    	}
	},
	
	'setFunc' : function(id) {
		if(document.getElementById(id)) {
			var posY =  GET.posY(id);
			var pageSize = GET.pageSize();
			var browserHeight = GET.browserHeight();
			
			var adjuster = 0;
			if(location.href.match(/schedule/) && document.getElementById(id).nodeName != "BODY") adjuster = 35;
			
			var end = posY - adjuster;
			if(pageSize - posY - adjuster < browserHeight) {
				end = pageSize - browserHeight;
			}
			
			this.option.scrollID = this.move(id, end);
		}
	},
	
	'move': function(id, end) {
		var that = this;
		var speed;
		
		if(Math.abs(GET.scrollY() - end) > 1) {
			speed = (end - GET.scrollY()) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			window.scrollBy(0, speed);
			
			return setTimeout(function() {
				that.option.scrollID = that.move(id, end);
			}, 20);
		} else {
			window.scrollTo(GET.scrollX(), end);
			clearTimeout(this.option.scrollID);
		}
	}
};

//################################//
//## リンクを別ウィンドウで開く ##//
//################################//
var Popup = {
	'init' : function(id) {
		var that = this;
		
		var parent = document;
		if(id && document.getElementById(id)) {
			parent = document.getElementById(id);
		}
		
		var aTags = parent.getElementsByTagName("A");
		
		for(var i = 0, max = aTags.length; i < max; i++) {
			if(aTags[i].href && GET.className(aTags[i])) {
				if(GET.className(aTags[i]).match(/popup/)) {
					aTags[i].onclick = function() {
						that.dialog(this);
						return false;
					}
				}
				
				if(GET.className(aTags[i]).match(/recochoku/)) {
					aTags[i].onclick = function() {
						that.recochoku(this);
						return false;
					}
				}
			}
		}
	},
	
	'dialog' : function(obj) {
		if(confirm('リンク先を別ウィンドウで開きます\n（あらかじめポップアップを許可しておいて下さい）')) {
			window.open(obj.href, null);
		}
	},
	
	'recochoku' : function(obj) {
		if(confirm('リンク先を別ウィンドウで開きます\n（あらかじめポップアップを許可しておいて下さい）')) {
			window.open(obj.href, 'recochoku', 'width=620, height=400, menubar=no, toolbar=no, scrollbars=yes, location=no, status=no');
		}
	}
};

//##########################//
//## リンク先の画面を表示 ##//
//##########################//
var DisplaySiteImage = {
	'option' : {
		'touchID' : setTimeout("", 200), //A要素にタッチしてもすぐに反応しないように制御
		'siteID' : setTimeout("", 300) //サイトイメージ表示までの時差
	},
	
	'init' : function() {
		var that = this;
		
		//ローディング画像先読み
		var iconObj = new Image();
		iconObj.src = this.getBase() + '/img/basic/icon_loading_s.gif';
		
		//ローディングアイコン用 img要素
		var icon = document.createElement("img");
		icon.setAttribute("width", 16);
		icon.setAttribute("height", 16);
		
		//サイトイメージ用 img要素
		var thmbnail = document.createElement("img");
		thmbnail.setAttribute("width", 150);
		thmbnail.setAttribute("height", 180);
		
		//ローディングアイコン用 div要素
		var loading = document.createElement("div");
		loading.setAttribute("id", "loading-icon");
		loading.style.width = "16px";
		loading.style.height = "16px";
		
		//サイトイメージ用 div要素
		var site = document.createElement("div");
		site.setAttribute("id", "site-image");
		site.style.MozBorderRadius = "10px";
		site.style.MozBoxShadow = "2px 2px 8px #000000";
		site.style.WebkitBorderRadius = "10px";
		site.style.WebkitBoxShadow = "2px 2px 8px #000000";
		site.intervalID = setTimeout("", 30);
		
		//補足説明用の span要素
		var span = document.createElement("span");
		span.setAttribute("id", "site-title")
		site.appendChild(span);
		
		var bodyTag = document.getElementsByTagName("BODY")[0];
		
		var aTags = bodyTag.getElementsByTagName("A");
		
		for(var i = 0, max = aTags.length; i < max; i++) {
			if(GET.className(aTags[i]) && GET.className(aTags[i]).match(/outside/)) {
				
				//title属性の削除（for ie）
				if(YAHOO.env.ua.ie && aTags[i].getAttribute("title")) {
					aTags[i].titleBackup = aTags[i].getAttribute("title");
					aTags[i].removeAttribute("title");
				}
				
				aTags[i].onmouseover = function(e) {
					var self = this;
					
					clearTimeout(that.option.touchID);
					clearTimeout(that.option.siteID);
					
					//サイトイメージが残っていたら削除する（保険）
					if(document.getElementById("loading-icon")) {
						var erase = document.getElementById("loading-icon");
						erase.parentNode.removeChild(erase);
					}
					if(document.getElementById("site-image")) {
						var erase = document.getElementById("site-image");
						erase.parentNode.removeChild(erase);
					}
					
					if(!document.getElementById("loading-icon") && !document.getElementById("site-image")) {
						
						that.option.touchID = setTimeout(function() {
							//title属性の一時退避
							if(!YAHOO.env.ua.ie && self.getAttribute("title")) {
								self.titleBackup = self.getAttribute("title");
								self.removeAttribute("title")
							}
							
							self.X = GET.posX(self);
							self.Y = GET.posY(self);
							
							var href = self.getAttribute("href");
							var widthA = self.offsetWidth;
							var heightA = self.offsetHeight;
							
							//ローディングアイコンを読込み終えた時の動作
							icon.onload = function () {
								loading.appendChild(this);
								bodyTag.appendChild(loading);
								
								if((GET.mouse(e).x - GET.scrollX()) > GET.browserWidth() / 2) {
									loading.style.left = GET.mouse(e).x - loading.offsetWidth - 15 + "px"; 
								} else {
									if(GET.mouse(e).x + loading.offsetWidth > GET.scrollX() + GET.browserWidth()) {
										loading.style.left = (GET.scrollX() + GET.browserWidth() - loading.offsetWidth - 5) + "px";
									} else {
										loading.style.left = GET.mouse(e).x + "px";
									}
								}
								
								if((GET.mouse(e).y - GET.scrollY()) > GET.browserHeight() / 2) {
									loading.style.top = self.Y - loading.offsetHeight - 5 + "px"; 
								} else {
									if(GET.mouse(e).y + loading.offsetHeight > GET.scrollY() + GET.browserHeight()) {
										loading.style.top = GET.scrollY() + GET.browserHeight() - loading.offsetHeight - 5 + "px"; 
									} else {
										loading.style.top = self.Y + self.offsetHeight + 5 + "px";
									}
								}
								
								//引き続き、サイトイメージ生成（300ms後）
								that.option.siteID = setTimeout(function() {
									thmbnail.onload = function() {
										//ローディングアイコンの削除
										if(document.getElementById("loading-icon")) {
											icon.setAttribute("src", "");
											var erase = document.getElementById("loading-icon");
											erase.parentNode.removeChild(erase);
										}
										
										site.opacity = 0;
										site.insertBefore(this, span);
										
										//title属性がある場合はサムネイルに補足として表示させる
										if(self.titleBackup) {
											span.innerHTML = self.titleBackup;
										} else {
											span.innerHTML = "";
											span.style.display = "none";
										}
										
										bodyTag.appendChild(site);
										
										//サイトイメージにカーソル合わせると自身を消去（保険）
										site.onmouseover = function() {
											this.parentNode.removeChild(this);
										}
										
										if((GET.mouse(e).x - GET.scrollX()) > GET.browserWidth() / 2) {
											site.style.left = GET.mouse(e).x - site.offsetWidth - 5 + "px"; 
										} else {
											if(GET.mouse(e).x + site.offsetWidth > GET.scrollX() + GET.browserWidth()) {
												site.style.left = GET.scrollX() + GET.browserWidth() - site.offsetWidth - 5 + "px";
											} else {
												site.style.left = GET.mouse(e).x + 5 + "px";
											}
										}
										
										if((GET.mouse(e).y - GET.scrollY()) > GET.browserHeight() / 2) {
											site.style.top = self.Y - site.offsetHeight - 5 + "px"; 
										} else {
											if(GET.mouse(e).y + site.offsetHeight > GET.scrollY() + GET.browserHeight()) {
												site.style.top = GET.scrollY() + GET.browserHeight() - site.offsetHeight - 5 + "px"; 
											} else {
												site.style.top = self.Y + self.offsetHeight + 5 + "px";
											}
										}
										
										that.fadeIn(site);
									}
									thmbnail.setAttribute("src", 'http://capture.heartrails.com/150x180/delay=5?' + href);
								}, 300);
							}
							//ローディングアイコンを読み込む
							icon.setAttribute("src", iconObj.src);
						}, 200);
					}
				}
				
				aTags[i].onmouseout = function() {
					clearTimeout(that.option.touchID);
					clearTimeout(that.option.siteID);
					
					//span 要素の可視化
					span.style.display = "block";
					
					//title属性の復帰（for ie）
					if(!YAHOO.env.ua.ie && this.titleBackup) {
						this.setAttribute("title", this.titleBackup);
					}
					
					//画像ソースのリセット
					icon.setAttribute("src", "");
					site.setAttribute("src", "");
					
					//div要素の削除
					if(document.getElementById("loading-icon")) {
						var erase = document.getElementById("loading-icon");
						erase.parentNode.removeChild(erase);
					}
					if(document.getElementById("site-image")) {
						var erase = document.getElementById("site-image");
						erase.parentNode.removeChild(erase);
					}
				}
			}
		}
	},
	
	'fadeIn': function(obj) {
		var that = this;
		
		if(obj.opacity <= 10) {
			if(YAHOO.env.ua.ie)     obj.style.filter = 'alpha(opacity=' + obj.opacity * 10 + ')'; // IE
			if(YAHOO.env.ua.gecko)  obj.style.MozOpacity = obj.opacity / 10; // Firefox
			if(YAHOO.env.ua.webkit) obj.style.opacity = obj.opacity / 10; // Safari
			obj.opacity += 1;
			
			return setTimeout(function() {
				obj.intervalID = that.fadeIn(obj);
			}, 30);
		} else {
			clearTimeout(obj.intervalID);
			if(YAHOO.env.ua.ie) obj.style.removeAttribute('filter');
		}
	},
	
	'getBase' : function() {
		var obj = new RegExp("artist/");
		location.href.match(obj);
		var artist =  (RegExp.rightContext.split('/'))[0];
		obj = new RegExp(artist);
		location.href.match(obj);
		
		return RegExp.leftContext + artist;
	}
};

//####################//
//## スマートバック ##//
//####################//
var SmartBack  = {
	'option' : {
		'mainWidth' : 950,
		'borderWidth' : 20,
		'adjuster' : 5,  //固定時の余白
		'k': 0.2, // 運動係数
		'touchID' : setTimeout("", 200)
	},
	
	'init' : function() {
		var that = this;
		
		//画像先読み
		var iconObj = new Image();
		iconObj.src = this.getBase() + '/img/basic/icon_back.gif';
		
		var icon = document.createElement("img");
		icon.onload = function () {
			var parent = document.getElementsByTagName("BODY")[0];
			var target = document.createElement("div");
			
			var aTag = document.createElement("a");
			aTag.setAttribute("href", "#" + parent.getAttribute("id"));
			aTag.targetID = aTag.getAttribute("href").replace(/.*#(.+)$/i, "$1");
			
			aTag.onclick = function() {
				clearTimeout(FineScroll.option.scrollID);
				
				FineScroll.option.scrollID = FineScroll.setFunc(this.targetID);
				
				return false;
			}
			
			aTag.appendChild(this);
			target.appendChild(aTag);
			parent.appendChild(target);
			
			target.setAttribute("id", "back-to-top");
			target.style.top = GET.scrollY() + GET.browserHeight() - target.offsetHeight - that.option.adjuster + "px";
			target.style.visibility = "visible";
			target.moveXID = setTimeout("", 20);
			target.moveYID = setTimeout("", 20);
			
			if(typeof window.addEventListener == 'function') {
				window.addEventListener('scroll', function() {
					clearTimeout(that.option.touchID);
					clearTimeout(target.moveXID);
					clearTimeout(target.moveYID);
					
					that.option.touchID = setTimeout(function() {
						that.fixed(target);
					}, 200);
				}, false);
				window.addEventListener('resize', function() {
					clearTimeout(that.option.touchID);
					clearTimeout(target.moveXID);
					clearTimeout(target.moveYID);
					
					that.option.touchID = setTimeout(function() {
						that.fixed(target);
					}, 200);
				}, false);
			} else if(typeof window.attachEvent == 'object'){
				window.attachEvent('onscroll', function() {
					clearTimeout(that.option.touchID);
					clearTimeout(target.moveXID);
					clearTimeout(target.moveYID);
					
					that.option.touchID = setTimeout(function() {
						that.fixed(target);
					}, 200);
				});
				window.attachEvent('onresize', function() {
					clearTimeout(that.option.touchID);
					clearTimeout(target.moveXID);
					clearTimeout(target.moveYID);
					
					that.option.touchID = setTimeout(function() {
						that.fixed(target);
					}, 200);
				});
			}
			
			that.fixed(target);
		}
		icon.setAttribute("src", iconObj.src);
	},
	
	'fixed' : function(obj) {
		//X軸計算
		var endX = GET.scrollX() + this.option.adjuster;
		
		//Y軸計算
		var endY = GET.scrollY() + GET.browserHeight() - obj.offsetHeight - this.option.adjuster;
		
		//footer補正
		var footer = document.getElementById("footer");
		footer.posY = GET.posY(footer);
		if(endY + obj.offsetHeight + this.option.adjuster > footer.posY) {
			endY = footer.posY - obj.offsetHeight - this.option.adjuster;
		}
		
		obj.moveXID = this.moveX(obj, GET.posX(obj), endX);
		obj.moveYID = this.moveY(obj, GET.posY(obj), endY);
	},
	
	'moveX': function(obj, start, end) {
		var that = this;
		var speed;
		var tempPos;
		
		tempPos = GET.posX(obj);
		
		if(Math.abs(tempPos - end) > 1) {
			speed = (end - GET.posX(obj)) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.left = tempPos + speed + "px";
			
			return setTimeout(function() {
				obj.moveXID = that.moveX(obj, parseInt(obj.style.left), end);
			}, 20);
		} else {
			obj.style.left = end + "px";
			clearTimeout(obj.moveXID);
		}
	},
	
	'moveY': function(obj, start, end) {
		var that = this;
		var speed;
		var tempPos;
		
		tempPos = GET.posY(obj);
		
		if(Math.abs(tempPos - end) > 1) {
			speed = (end - GET.posY(obj)) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.top = tempPos + speed + "px";
			
			return setTimeout(function() {
				obj.moveYID = that.moveY(obj, parseInt(obj.style.top), end);
			}, 20);
		} else {
			obj.style.top = end + "px";
			clearTimeout(obj.moveYID);
		}
	},
	
	'getBase' : function() {
		var re1 = new RegExp("artist/");
		location.href.match(re1);
		
		var base = (RegExp.rightContext.split('/'))[0];
		
		var re2 = new RegExp(base);
		location.href.match(re2);
		
		return RegExp.leftContext + base;
	}
};

//##############################//
//## トピックパスコントロール ##//
//##############################//
var CtrlTopicPath = {
	'option' : {
		'targetHeight' : 0,
		'k' : 0.2
	},
	
	'init' : function() {
		if(document.getElementById("header") && document.getElementById("topicpath")) {
			var that = this;
			
			var parent = document.getElementById("header");
			parent.touchID = setTimeout("", 50);
			parent.moveID = setTimeout("", 40)
			parent.isOpened = false;
			
			var topicpath = document.getElementById("topicpath");
			this.option.targetHeight = topicpath.offsetHeight;
			
			var trigger = topicpath.getElementsByTagName("H2")[0];
			typeof document.body.style.minWidth != "undefined" ? trigger.style.cursor = "pointer" : trigger.style.cursor = "hand";
			
			trigger.onclick = function() {
				clearTimeout(parent.moveID);
				
				if(!parent.isOpened) {
					parent.moveID = that.move(parent, 0);
					parent.isOpened = true;
				} else {
					parent.moveID = that.move(parent, -that.option.targetHeight);
					parent.isOpened = false;
				}
			}
			
			parent.onmouseover = function() {
				clearTimeout(this.touchID);
			}
			
			parent.onmouseout = function() {
				var self = this;
				
				clearTimeout(this.touchID);
				
				this.touchID = setTimeout(function() {
					clearTimeout(self.moveID);
					
					self.moveID = that.move(self, -that.option.targetHeight);
					self.isOpened = false;
				}, 500);
			}
			
			parent.style.top = -this.option.targetHeight + "px";
			parent.style.marginBottom = -this.option.targetHeight + "px"
				
			parent.style.visibility = "visible";
		}
	},
	
	'move': function(obj, end) {
		var that = this;
		
		var speed = 0;
		var tempPos = parseInt(GET.style(obj, "top"));
		
		if(Math.abs(tempPos - end) > 1) {
			speed = (end - tempPos) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.top = tempPos + speed + "px";
			obj.style.marginBottom = -(tempPos + speed) + "px";
			
			return setTimeout(function() {
				obj.moveID = that.move(obj, end);
			}, 40);
		} else {
			obj.style.top = end + "px";
			obj.style.mrginBottom = -end + "px";
			
			clearTimeout(obj.moveID);
		}
	}
};

//################################//
//## フルスクリーンムービー制御 ##//
//################################//
var FullScreenMovie = {
	'option' : {
		'margin' : 45,
		'flashWidth' : 640,
		'flashHeight' : 360,
		'screenRatioX' : 16,
		'screenRatioY' : 9,
		'delayID' : setTimeout("", 40),
		'alertID' : setTimeout("", 5000)
	},
	
	'init' : function(file, jump, text) {
		var that = this;
		
		if(typeof MOVIE != 'undefined') {
			var okMOVIE = new Array();
			for(var i = 0; i < MOVIE.length; i++) {
				if(document.cookie.length > 0) {
					if(!(document.cookie.indexOf(MOVIE[i].cookie + "=true") != -1)) {
						okMOVIE.push(MOVIE[i]);
					}
				} else {
					okMOVIE.push(MOVIE[i]);
				}
				
				var limit = new Date();
				limit.setTime(limit.getTime() + (1000 * 60 * 60 * 24 * MOVIE[i].interval));
				limitGMT = limit.toGMTString();
				document.cookie = MOVIE[i].cookie + "=true;expires=" + limitGMT + ";";
			}
			
			if(okMOVIE.length > 0) {
				var choice = Math.floor(Math.random() * okMOVIE.length);
				
				this.insertFlash(okMOVIE[choice]);
			}
			
			this.addFooter();
		}
	},
	
	'insertFlash' : function(obj) {
		var that = this;
		
		var body = document.getElementsByTagName("BODY")[0];
		body.style.overflow = "hidden";
		
		//コンテナの設定
		var divTag = document.createElement("div");
		divTag.setAttribute("id", "fullscreen-movie");
		divTag.angle = 0;
		divTag.openID = setTimeout("", 40);
		divTag.fadeInID = setTimeout("", 40);
		
		if(!YAHOO.env.ua.ie || YAHOO.env.ua.ie > 6) {
			divTag.style.top = GET.browserHeight() / 2 + "px";
			divTag.style.height = 0;
			divTag.style.left = GET.browserWidth() / 2 + "px";
			divTag.style.width = 0;
		}
		
		//クローズボタンの設定
		var iconPath = this.getBase() + '/img/basic/icon_close.gif';
		
		var close = document.createElement("p");
		close.setAttribute("id", "fullscreen-movie-close");
		close.opacity = 0;
		close.fadeInID = setTimeout("", 40);
		
		typeof document.body.style.minWidth != "undefined" ? close.style.cursor = "pointer" : close.style.cursor = "hand";
		close.style.visibility = "hidden";
		close.innerHTML = '<img src="' + iconPath + '" width="80" height="30" alt="CLOSE" />';
		
		close.onclick = function() {
			that.removeFlash();
		}
		
		divTag.appendChild(close);
		
		//タイトルの設定
		var text = document.createElement("p");
		text.setAttribute("id", "fullscreen-movie-text");
		text.opacity = 0;
		text.fadeInID = setTimeout("", 40);
		
		text.style.visibility = "hidden";
		text.innerHTML = obj.text;
		
		divTag.appendChild(text);
		
		//FLASHオブジェクトの設定
		var flash = document.createElement("p");
		flash.setAttribute("id", "fullscreen-movie-flash");
		flash.opacity = 0;
		flash.fadeInID = setTimeout("", 40);
		flash.style.visibility = "hidden";
		
		var flashPath = this.getBase() + '/flash/fullscreen_movie.swf';
		
		if(YAHOO.env.ua.ie) {
			flash.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + flashPath + '" /><param name="salign" value="lt" /><param name="quality" value="high" /><param name="wmode" value="opaque" /><param name="FlashVars" value="moviePath=' + obj.source + '&jumpURL=' + obj.link + '" /></object>';
        } else {
			var embed = document.createElement("embed");
			embed.setAttribute("src", flashPath);
			embed.setAttribute("quality", 'high');
			embed.setAttribute("wmode", 'opaque');
			embed.setAttribute("salign", 'lt');
			embed.setAttribute("width", '100%');
			embed.setAttribute("height", '100%');
			embed.setAttribute("FlashVars", 'moviePath=' + obj.source + '&jumpURL=' + obj.link);
			embed.setAttribute("allowScriptAccess", 'sameDomain');
			embed.setAttribute("type", 'application/x-shockwave-flash');
			embed.setAttribute("pluginspage", 'http://www.macromedia.com/go/getflashplayer');
			
			flash.appendChild(embed);
		}
		
		divTag.appendChild(flash);
		
		body.appendChild(divTag);
		
		if(!YAHOO.env.ua.ie || YAHOO.env.ua.ie > 6) {
			divTag.openID = this.open(divTag, 0)
		} else {
			flash.fadeInID = this.fadeIn(flash);
			flash.style.visibility = "visible";
			
			text.fadeInID = this.fadeIn(text);
			text.style.visibility = "visible";
			
			window.attachEvent('onscroll',  this.fixed);
			window.attachEvent('onresize',  this.fixed);
			
			this.fixed();
		}
		
		this.resizeFlash(flash)
		
		if(window.addEventListener) { 
			window.addEventListener("resize", that.event, false);
		} else if(window.attachEvent) {
			window.attachEvent("onresize", that.event);
		}
		
		this.option.alertID = setTimeout(function() {
			if(confirm('動画の読み込みをスキップしますか？\n（FLASHが利用できない環境の方は必ずスキップして下さい。）')) {
				that.removeFlash();
			}
		}, 5000);
	},
	
	'removeFlash' : function() {
		if(document.getElementById("fullscreen-movie")) {
			var that = this;
			
			var body = document.getElementsByTagName("BODY")[0];
			var movie = document.getElementById("fullscreen-movie");
			
			body.removeChild(movie);
			body.style.overflow = "auto";
			
			if(window.removeEventListener) { 
				window.removeEventListener("resize", that.event, false);
			} else if(window.detachEvent) {
				window.detachEvent("onresize", that.event);
			}
			
			if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
				window.detachEvent('onscroll',  this.fixed);
				window.detachEvent('onresize',  this.fixed);
			}
		}
	},
	
	'resizeFlash' : function() {
		if(document.getElementById("fullscreen-movie")) {
			var divTag = document.getElementById("fullscreen-movie");
			var text = document.getElementById("fullscreen-movie-text");
			var flash = document.getElementById("fullscreen-movie-flash");
			
			var borderWidthTB = 0;
			var borderWidthLR = 0;
			
			if(GET.style(flash, "border-top-width")) borderWidthTB = parseInt(GET.style(flash, "border-top-width")) * 2;
			if(GET.style(flash, "border-left-width")) borderWidthLR = parseInt(GET.style(flash, "border-left-width")) * 2;
			
			var IE6FlashLeft = 0;
			var IE6FlashWidth = 0;
			if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
				IE6FlashWidth = borderWidthLR;
			}
			
			if((GET.browserWidth() - (this.option.margin * 2)) / (GET.browserHeight() - (this.option.margin * 2)) < this.option.screenRatioX / this.option.screenRatioY) {
				this.option.flashWidth = GET.browserWidth() - borderWidthLR - (this.option.margin * 2);
				this.option.flashHeight = (GET.browserWidth() - borderWidthTB - (this.option.margin * 2)) * this.option.screenRatioY / this.option.screenRatioX
			} else {
				this.option.flashWidth = (GET.browserHeight() - borderWidthLR - (this.option.margin * 2)) * this.option.screenRatioX / this.option.screenRatioY
				this.option.flashHeight = GET.browserHeight() - borderWidthTB - (this.option.margin * 2);
			}
			
			flash.style.top = (GET.browserHeight() - this.option.flashHeight - borderWidthTB) / 2 + "px";
			
			flash.style.width = this.option.flashWidth - IE6FlashWidth + "px";
			flash.style.height = this.option.flashHeight + "px";
			
			text.style.top = (GET.browserHeight() - this.option.flashHeight - borderWidthTB) / 2 + flash.offsetHeight + 10 + "px";
		}
	},
	
	'open': function(obj, end) {
		var that = this;
		
		var speed = 0;
		
		var tempPosX = parseInt(GET.style(obj, "left"));
		var tempWidth = parseInt(GET.style(obj, "width"));
		
		var tempPosY = parseInt(GET.style(obj, "top"));
		var tempHeight = parseInt(GET.style(obj, "height"));
		
		if(tempPosX > end || tempPosY > end) {
			if(Math.abs(tempPosX - end) > 1) {
				speed = (end - tempPosX) * (Math.sin(Math.PI / 180 * obj.angle));
				speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
				
				obj.style.left = tempPosX + speed + "px";
				obj.style.width = tempWidth + -(speed * 2) + "px";
			} else {
				obj.style.left = end + "px";
				obj.style.width = "100%";
			}
			
			if(Math.abs(tempPosY - end) > 1) {
				speed = (end - tempPosY) * (Math.sin(Math.PI / 180 * obj.angle));
				speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
				
				obj.style.top = tempPosY + speed + "px";
				obj.style.height = tempHeight + -(speed * 2) + "px";
			} else {
				obj.style.top = end + "px";
				obj.style.height = "100%";
			}
			
			obj.angle += 1;
			
			return setTimeout(function() {
				obj.openID = that.open(obj, end);
			}, 40);
		} else {
			clearTimeout(obj.openID);
			
			var flash = document.getElementById("fullscreen-movie-flash");
			var text = document.getElementById("fullscreen-movie-text");
			
			flash.fadeInID = this.fadeIn(flash);
			flash.style.visibility = "visible";
			
			text.fadeInID = this.fadeIn(text);
			text.style.visibility = "visible";
			
			if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
				window.attachEvent('onscroll',  this.fixed);
				window.attachEvent('onresize',  this.fixed);
				
				this.fixed();
			}
		}
	},
	
	'showCloseButton' : function() {
		var close = document.getElementById("fullscreen-movie-close");
		
		close.fadeInID = this.fadeIn(close);
		close.style.visibility = "visible";
	},
	
	'deleteTransparent' : function() {
		var flash = document.getElementById("fullscreen-movie-flash");
		
		clearTimeout(flash.fadeInID);
		
		if(YAHOO.env.ua.ie)     flash.style.filter = 'alpha(opacity=100)'; // IE
		if(YAHOO.env.ua.gecko)  flash.style.MozOpacity = 1; // Firefox
		if(YAHOO.env.ua.webkit) flash.style.opacity = 1; // Safari
		
		if(YAHOO.env.ua.ie) flash.style.removeAttribute('filter');
	},
	
	'fadeIn': function(obj) {
		var that = this;
		
		if(obj.opacity <= 10) {
			if(YAHOO.env.ua.ie)     obj.style.filter = 'alpha(opacity=' + obj.opacity * 10 + ')'; // IE
			if(YAHOO.env.ua.gecko)  obj.style.MozOpacity = obj.opacity / 10; // Firefox
			if(YAHOO.env.ua.webkit) obj.style.opacity = obj.opacity / 10; // Safari
			obj.opacity += 1;
			
			return setTimeout(function() {
				obj.fadeInID = that.fadeIn(obj);
			}, 40);
		} else {
			clearTimeout(obj.fadeInID);
			if(YAHOO.env.ua.ie) obj.style.removeAttribute('filter');
		}
	},
	
	'event' : function() {
		var that = FullScreenMovie;
		
		clearTimeout(that.option.delayID);
		
		that.option.delayID = setTimeout(function() {
			that.resizeFlash();
		}, 40);
	},
	
	'fixed' : function() {
		if(document.getElementById("fullscreen-movie")) {
			var target = document.getElementById("fullscreen-movie");
			
			target.style.top = GET.scrollY() + "px";
			target.style.left = GET.scrollX() + "px";
			target.style.height = "100%";
		}
	},
	
	'addFooter' : function() {
		var that = this;
		
		var parent = document.getElementById("footer");
		var insertPoint = document.getElementById("footer-page-info");
		
		var divTag = document.createElement("div");
		divTag.setAttribute("id", "fullscreen-movie-list");
		
		var ul = document.createElement("ul");
		
		var h2 = document.createElement("h2");
		h2.innerHTML = 'MOVIE LIST';
		
		for(var i = 0, len_i = MOVIE.length; i < len_i; i++) {
			(function() {
				var li = document.createElement("li");
					
				var aTag = document.createElement("a");
				aTag.setAttribute("href", MOVIE[i].link);
				aTag.no = i;
				
				aTag.onclick = function() {
					if(!document.getElementById('fullscreen-movie')) {
						that.insertFlash(MOVIE[this.no]);
					} else {
						alert("現在、別の動画が再生中です。")
					}
					return false;
				}
				
				aTag.innerHTML= '<strong>' + MOVIE[i].title + '</strong>' + MOVIE[i].text;
				
				li.appendChild(aTag);
				ul.appendChild(li);
			})();
		}
		divTag.appendChild(ul);
		divTag.appendChild(h2);
		
		parent.insertBefore(divTag, insertPoint);
	},
	
	'cancelAlert' : function() {
		clearTimeout(this.option.alertID);
	},
	
	'getBase' : function() {
		location.href.match(new RegExp("artist/"));
		
		var base = (RegExp.rightContext.split('/'))[0];
		
		location.href.match(new RegExp(base));
		
		return RegExp.leftContext + base;
	}
};

//############################//
//## タイトルアニメーション ##//
//############################//
var AnimationTitle = {
	'option' : {
		'k' : 0.12,
		'distance' : 25
	},
	
	'init' : function() {
		
		if(document.getElementById("main")) {
			
			var parent = document.getElementById("main");
			
			var h3 = parent.getElementsByTagName("H3")[0];
			h3.animationID = setTimeout("", 40);
			
			h3.animationID = this.animation(h3, this.option.distance);
			
			h3.style.visibility = "visible";
		}
	},
	
	'animation': function(obj, end) {
		var that = this;
		
		var speed = 0;
		var tempLetterSpacing = parseInt(GET.style(obj, "letter-spacing"));
		
		if(Math.abs(tempLetterSpacing - end) > 1) {
			speed = (end - tempLetterSpacing) * this.option.k;
			speed > 0 ? speed = Math.ceil(speed) : speed = Math.floor(speed);
			
			obj.style.letterSpacing = tempLetterSpacing + speed + "px";
			
			return setTimeout(function() {
				obj.animationID = that.animation(obj, end);
			}, 40);
		} else {
			clearTimeout(obj.animationID);
			
			obj.style.letterSpacing = end + "px";
		}
	}
};

//######################//
//## 情報スクローラー ##//
//######################//
var Scroller = {
    'init' : function(elem) {
		if(typeof elem.length !== "undefined") {
			for(var i = 0, len_i = elem.length; i < len_i; i++) {
				this.setFunc(elem[i]);
			}
		} else {
			this.setFunc(elem);
		}
	},
   	
   	'setFunc' : function(target) {
   		var that = this;
   		
   		target.slideID = setTimeout("", 20);
   		target.touchID = setTimeout("", 50);
   		target.paddingLeft = parseInt(GET.style(target, "padding-left"));
   		
   		target.style.textIndent = 0;
   		
		target.onmouseover = function() {
			clearTimeout(this.touchID);
			clearTimeout(this.slideID);
			
			var charSize = that.getCharLen(this);
			
			if(charSize + this.paddingLeft > this.offsetWidth) {
				target.slideID = that.slide(this, charSize);
			}
		}
		target.onmouseout = function() {
			var self = this;
			
			clearTimeout(this.slideID);
			
			this.touchID = setTimeout(function() {
				self.style.textIndent = 0;
			}, 50);
		}
   	},
   	
   	'slide': function(obj, charLen) {
   		var that = this;
   		var speed = 3;
   		var d = parseInt(obj.style.textIndent) - speed;
   		
		obj.style.textIndent = d + "px";
		
		if(d < -(charLen + obj.paddingLeft)) {
			obj.style.textIndent = obj.offsetWidth + 5 + "px";
		}
		
		return setTimeout(function() {
			obj.slideID = that.slide(obj, charLen);
		}, 20);
   	},
   	
   	'getCharLen': function(obj) {
   		var charSize = 0;
   		
   		var span = document.createElement("span");
		var text = document.createTextNode(obj.innerHTML.replace(/<!--.*-->|<\/?[^>]+>/gi, ""));
		span.appendChild(text);
		
		obj.appendChild(span);
		charSize = span.offsetWidth;
		obj.removeChild(span);
		
		return charSize;
   	}
};

//################################//
//## 閲覧人数カウントプログラム ##//
//################################//
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) {
			
		}
	}
};

//####################//
//## イニシャライズ ##//
//####################//
YAHOO.util.Event.onDOMReady(function() {
	if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
		DD_belatedPNG.fix("#main");
		
		//DD_belatedPNG.fix("div.menu ul");
		//DD_belatedPNG.fix("div.menu ul li");
	}
	
	CtrlHeaderFooter.init();
	FineScroll.init();
	Popup.init();
	DisplaySiteImage.init();
	SmartBack.init();
	WhoIsOnline.init();
	
	CtrlTopicPath.init();
	
	Shadowbox.init();
	
	FullScreenMovie.init();
});
