//#########################################################//
//## ディスコグラフィー用 dlタグ全体をクリック範囲にする ##//
//#########################################################//
var AddFuncDiscoDL = {
	'option' : {
		'startC' : "#eeeeee",
		'endC' : [ "#7200ff", "#ff76ca", "#27a1ff", "#09dc4a", "#ff0000", "#ff6600", "#faec0d" ],
		'level' : 10,
		'step' : 20
	},
	
	'init' : function() {
		var that = this;
		
		var parent = document.getElementById("discography");
		
		//DLタグの設定
		var dlTags = parent.getElementsByTagName("DL");
		for(var i = 0, maxI = dlTags.length; i < maxI; i++) {
			
			dlTags[i].parent = dlTags[i].parentNode;
			dlTags[i].counter = 0;
			dlTags[i].touchID = setTimeout("", 10);
			
			if(GET.className(dlTags[i]) != "limited") {
				dlTags[i].endC = this.option.endC[Math.floor(Math.random() * this.option.endC.length)];
				
				if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
					dlTags[i].style.cursor = "hand";
				} else {
					dlTags[i].style.cursor = "pointer";
				}
				
				var ATag = dlTags[i].getElementsByTagName("A")[0];
				dlTags[i].href =  ATag.getAttribute("href");
				dlTags[i].setAttribute("title", "クリックで詳細ページに移動");
				ATag.style.textDecoration = "none";
				
				dlTags[i].onclick = function () {
					window.location = this.href;
				}
				dlTags[i].onmouseover = function() {
					var self = this;
					clearTimeout(this.touchID);
					
					this.touchID = setTimeout(function () {
						self.style.backgroundImage = "url(../img/basic/back_ani_white.gif)";
						self.parentNode.style.borderColor = self.endC;
					}, 10);
				}
				dlTags[i].onmouseout = function() {
					var self = this;
					
					this.touchID = setTimeout(function () {
						self.counter = 0;
						self.style.backgroundImage = "none";
						self.parentNode.style.borderColor = that.option.startC;
						self.endC = that.option.endC[Math.floor(Math.random() * that.option.endC.length)];
					}, 10);
				}
			} else {
				//初回盤各Verの設定
				var liTags = dlTags[i].getElementsByTagName("LI");
				for(var j = 0, maxJ = liTags.length; j < maxJ; j++) {
					if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
						liTags[j].style.cursor = "hand";
					} else {
						liTags[j].style.cursor = "pointer";
					}
					
					liTags[j].num = j;
					liTags[j].dl = dlTags[i];
					liTags[j].setAttribute("title", "クリックで詳細ページへ移動");
					liTags[j].aTag = liTags[j].getElementsByTagName("A")[0];
					liTags[j].touchID = setTimeout("", 10);
					
					liTags[j].onmouseover = function() {
						var self = this;
						clearTimeout(this.touchID);
						
						this.touchID = setTimeout(function () {
							self.dl.endC = that.option.endC[self.num];
							
							self.dl.style.backgroundImage = "url(../img/basic/back_ani_white.gif)";
							self.dl.parentNode.style.borderColor = self.dl.endC;
						}, 10);
					}
					liTags[j].onmouseout = function() {
						var self = this;
						clearTimeout(this.touchID);
						
						this.touchID = setTimeout(function () {
							self.style.backgroundImage = "none";
							self.dl.counter = 0;
							self.dl.style.backgroundImage = "none";
							self.dl.parentNode.style.borderColor = that.option.startC;
						}, 10);
					}
					liTags[j].onclick = function() {
						window.location = this.aTag.getAttribute("href");
					}
				}
			}
		}
	}
};

//######################################//
//## ディスコグラフィー選択ボタン追加 ##//
//######################################//
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("DIV")[0];
			
			var h3 = document.createElement("h3");
			h3.innerHTML = "表示コントロール";
			
			var hr = document.createElement("hr");
			
			var ul = document.createElement("ul");
			ul.setAttribute("id", "ctrl");
			
			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 / VHS</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>etc</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 = "";
				}
			}
			
			disco.insertBefore(ul, insertPoint);
			disco.insertBefore(hr, insertPoint);
		}
	},
		
	'openClose' : function(target) {
		var disco = document.getElementById("discography");
		var h3 = disco.getElementsByTagName("H3")[0];
		var div = disco.getElementsByTagName("DIV");
		var re = new RegExp(target, "i");
		
		for(var i = 0; i < div.length; i++) {
			if(GET.className(div[i]).search(re) != -1 || target == "all") {
				div[i].style.display = "block";
			} else {
				div[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 / VHS';
				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');
});
