//#########################################################//
//## ディスコグラフィー用 dlタグ全体をクリック範囲にする ##//
//#########################################################//
var AddFuncDiscoDL = {
	'option' : {
		
	},
	
	'init' : function() {
		var that = this;
		
		var parent = document.getElementById("discography");
		var dlTags = parent.getElementsByTagName("DL");
		
		for(var i = 0, max = dlTags.length; i < max; i++) {
			if(dlTags[i].getElementsByTagName("A")[0]) {
				if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
					dlTags[i].style.cursor = "hand";
				} else {
					dlTags[i].style.cursor = "pointer";
				}
				
				dlTags[i].timeoutID = setTimeout("", 40);
				
				var ATag = dlTags[i].getElementsByTagName("A")[0];
				dlTags[i].href = ATag.href;
				dlTags[i].setAttribute("title", "クリックで詳細ページへ移動");
				ATag.style.textDecoration = "none";
				
				dlTags[i].onclick = function () {
					window.location = this.href;
				}
				dlTags[i].onmouseover = function () {
					clearTimeout(this.timeoutID);
					
					this.style.backgroundImage = "url(../img/basic/back_ani_white.gif)";
				}
				
				dlTags[i].onmouseout = function () {
					var self = this;
					
					this.timeoutID = setTimeout(function() {
						self.style.backgroundImage = "none";
					}, 40);
				}
			}
		}
	}
};

//######################################//
//## ディスコグラフィー選択ボタン追加 ##//
//######################################//
var insertCtrlDisco = {
	'option' : {
		'forbidden': false
	},
	
	'init' : function(request) {
		if(typeof request != 'undefined') {
			var that = this;
			
			var disco = document.getElementById("discography");
			disco.opacity = 10;
			disco.fadeID = setTimeout("", 30);
			
			var insertPoint = disco.getElementsByTagName("DL")[0];
			
			var div = document.createElement("div");
			div.setAttribute("id", "ctrl");
			
			var h3 = document.createElement("h3");
			h3.innerHTML = "表示コントロール";
			
			var hr = document.createElement("hr");
			
			var ul = document.createElement("ul");
			
			var li = new Array();
			
			li.push(document.createElement("li"));
			li[li.length - 1].setAttribute("id", "all");
			li[li.length - 1].innerHTML = "<span>Show All</span>";
			li[li.length - 1].onclick = function() { 
				if(!that.option.forbidden) {
					if(!YAHOO.env.ua.ie) {
						that.option.forbidden = true;
						that.fadeOut(disco, 'all');
					} else {
						that.openClose('all')
					}
				}
			};
			ul.appendChild(li[li.length - 1]);
			
			if(request.match(/BEST/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>BEST</span>";
				li[li.length - 1].onclick = function() {
					if(!that.option.forbidden) {
						if(!YAHOO.env.ua.ie) {
							that.option.forbidden = true;
							that.fadeOut(disco, 'best');
						} else {
							that.openClose('best')
						}
					}
				}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/ALBUM/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>Album</span>";
				li[li.length - 1].onclick = function() {
					if(!that.option.forbidden) {
						if(!YAHOO.env.ua.ie) {
							that.option.forbidden = true;
							that.fadeOut(disco, 'album');
						} else {
							that.openClose('album')
						}
					}
				}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/SINGLE/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>Single</span>";
				li[li.length - 1].onclick = function() {
					if(!that.option.forbidden) {
						if(!YAHOO.env.ua.ie) {
							that.option.forbidden = true;
							that.fadeOut(disco, 'single');
						} else {
							that.openClose('single')
						}
					}
				}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/DVD/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>DVD</span>";
				li[li.length - 1].onclick = function() {
					if(!that.option.forbidden) {
						if(!YAHOO.env.ua.ie) {
							that.option.forbidden = true;
							that.fadeOut(disco, 'dvd');
						} else {
							that.openClose('dvd')
						}
					}
				}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/ETC/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>Others</span>";
				li[li.length - 1].onclick = function() {
					if(!that.option.forbidden) {
						if(!YAHOO.env.ua.ie) {
							that.option.forbidden = true;
							that.fadeOut(disco, 'etc');
						} else {
							that.openClose('etc')
						}
					}
				}
				ul.appendChild(li[li.length - 1]);
			}
			
			for(var i = 0; i < li.length; i++) {
				li[i].onmouseover = function () {
					if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
						this.style.cursor = "hand";
					} else {
						this.style.cursor = "pointer";
					}
					this.style.backgroundImage = "url(../img/basic/back_ani_white.gif)";
				}
				li[i].onmouseout = function () {
					this.style.backgroundImage = "";
				}
			}
			
			div.appendChild(h3);
			div.appendChild(ul);
			
			disco.insertBefore(div, insertPoint);
			disco.insertBefore(hr, insertPoint);
		}
	},
		
	'openClose' : function(target) {
		var disco = document.getElementById("discography");
		var h3 = disco.getElementsByTagName("H3")[0];
		var dl = disco.getElementsByTagName("DL");
		var re = new RegExp(target, "i");
		
		for(var i = 0; i < dl.length; i++) {
			if(GET.className(dl[i]).search(re) != -1 || target == "all") {
				dl[i].style.display = "block";
			} else {
				dl[i].style.display = "none";
			}
		}
		if(document.getElementById("other")) {
			var li = document.getElementById("other").getElementsByTagName("LI");
			for(var i = 0; i < li.length; i++) {
				if(GET.className(li[i]).search(re) != -1 || target == "all") {
					li[i].style.display = "block";
				} else {
					li[i].style.display = "none";
				}
			}
		}
		
		switch(target) {
			case 'all' :
				h3.innerHTML = 'DISCOGRAPHY';
				break;
			case 'best' :
				h3.innerHTML = 'BEST';
				break;
			case 'album' :
				h3.innerHTML = 'ALBUM';
				break;
			case 'single' :
				h3.innerHTML = 'SINGLE';
				break;
			case 'dvd' :
				h3.innerHTML = 'DVD';
				break;
			case 'etc' :
				h3.innerHTML = 'OTHERS';
				break;
			default: 
				h3.innerHTML = 'DISCOGRAPHY';
				break;
		}
	},
	
	'fadeOut': function(obj, target) {
		var that = this;
		
		if(obj.opacity >= 0) {
			obj.style.filter = 'alpha(opacity=' + obj.opacity * 10 + ')'; // IE
			obj.style.MozOpacity = obj.opacity / 10; // Firefox
			obj.style.opacity = obj.opacity / 10; // Safari
			obj.opacity -= 1;
			
			return setTimeout(function() {
				obj.fadeID = that.fadeOut(obj, target);
			}, 30);
		} else {
			clearTimeout(obj.fadeID);
			if(YAHOO.env.ua.ie) obj.style.removeAttribute('filter');
			
			obj.opacity = 0;
			this.openClose(target);
			this.fadeIn(obj);
		}
	},
	
	'fadeIn': function(obj) {
		var that = this;
		
		if(obj.opacity <= 10) {
			obj.style.filter = 'alpha(opacity=' + obj.opacity * 10 + ')'; // IE
			obj.style.MozOpacity = obj.opacity / 10; // Firefox
			obj.style.opacity = obj.opacity / 10; // Safari
			obj.opacity += 1;
			
			return setTimeout(function() {
				obj.fadeID = that.fadeIn(obj);
			}, 30);
		} else {
			clearTimeout(obj.fadeID);
			if(YAHOO.env.ua.ie) obj.style.removeAttribute('filter');
			this.option.forbidden = false;
		}
	}
};

//####################//
//## イニシャライズ ##//
//####################//
YAHOO.util.Event.onDOMReady(function() {
	if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) CtrlMainWidth.force();
	AddFuncDiscoDL.init();
	insertCtrlDisco.init('ALBUM,SINGLE,DVD,ETC');
});
