//#########################################################//
//## ディスコグラフィー用 dlタグ全体をクリック範囲にする ##//
//#########################################################//
var AddFuncDiscoDL = {
	'init' : function() {
		var startC = "#cccccc";
		var endC = "#187fc4";
		
		var level = 15;
		var step = 1;
		var reset = 1000;
		
		var colors = CtrlGradation.gradation(startC, endC, level);
		var div = document.getElementById("discography");
		var dlTags = div.getElementsByTagName("DL");
		var dlTagsLength = dlTags.length;
		
		for(var i = 0; i < dlTagsLength; i++) {
			dlTags[i].counter = 0;
			
			dlTags[i].timerID1 = setInterval("", step);
			dlTags[i].timerID2 = setTimeout("", 1);
			dlTags[i].timerID3 = setTimeout("", reset);
			
			var ATags = dlTags[i].getElementsByTagName("A");
			dlTags[i].href = ATags[0].href;
			dlTags[i].setAttribute("title", ATags[0].title);
			ATags[0].style.textDecoration = "none";
			
			if(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
				dlTags[i].style.cursor = "hand";
			} else {
				dlTags[i].style.cursor = "pointer";
			}
			
			dlTags[i].onclick = function () {
				window.location = this.href;
			}
			dlTags[i].onmouseover = function () {
				clearInterval(this.timerID1);
				clearTimeout(this.timerID2);
				clearTimeout(this.timerID3);
				var obj = this;
				
				this.style.backgroundImage = "url(../img/basic/back_ani_white.gif)";
				
				this.timerID1 = setInterval(function() {
					if(obj.counter < 0) obj.counter = 0;
					if(obj.counter < level) CtrlGradation.setColor(obj, colors[obj.counter++]);
					else clearInterval(obj.timerID1);
				}, step);
			}
			dlTags[i].onmouseout = function () {
				clearInterval(this.timerID1);
				var obj = this;
				
				this.timerID2 = setTimeout(function() {
					obj.counter = 0;
					obj.style.borderColor = startC;
					obj.style.backgroundImage = "url(../img/basic/back_stripe_white.gif)";
				}, 1);
				
				this.timerID3 = setTimeout(function() {
					clearInterval(obj.timerID1);
					clearTimeout(obj.timerID2);
					clearTimeout(obj.timerID3);
					
					obj.counter = 0;
					obj.style.backgroundImage = "url(../img/basic/back_stripe_white.gif)";
					obj.style.borderColor = startC;
				}, reset);
			}
		}
	}
}

var CtrlGradation = {
	'setColor' : function(obj, color) {
		obj.style.borderColor = "#" + color;
	},
	
	'toHex': function(p) {
		p = Math.round(p);
		if(p <= 0x00) {
			return '00' ;
		} else if(p < 0x10) {
			return "0" + p.toString(16);
		} else if(p <= 0xff) {
			return p.toString(16);
		} else {
			return 'ff';
		}
	},
	
	'toRGB': function(c) {
		var p = parseInt('0x' + (c.charAt(0) == "#" ? c.substring(1) : c));
		var r = (p & 0xff0000) >>> 0x10;
		var g = (p & 0x00ff00) >>> 0x08;
		var b = (p & 0x0000ff) >>> 0x00;
		return { r:r, g:g, b:b };
	},
	
	'gradation': function(p0, p1, n) {
		var c0 = this.toRGB(p0);
		var c1 = this.toRGB(p1);
		var re = new Array(n);
		var dr = (c1.r - c0.r) / (n - 1);
		var dg = (c1.g - c0.g) / (n - 1);
		var db = (c1.b - c0.b) / (n - 1);
		for(var i = 0; i < n; i++) {
			re[i] = this.toHex(c0.r) + '' + this.toHex(c0.g) + '' + this.toHex(c0.b);
			c0.r += dr;
			c0.g += dg;
			c0.b += db;
		}
		return re;
	}
}

//######################################//
//## ディスコグラフィー選択ボタン追加 ##//
//######################################//

var insertCtrlDisco = {
	'init' : function(request) {
		if(typeof request != 'undefined') {
			var main = document.getElementById("main");
			var disco = document.getElementById("discography");
			
			var div = document.createElement("div");
			div.setAttribute("id", "ctrl");
			
			var h3 = document.createElement("h3");
			h3.innerHTML = "表示コントロール";
			
			var ul = document.createElement("ul");
			var hr = document.createElement("hr");
			
			var li = new Array();
			
			li.push(document.createElement("li"));
			li[li.length - 1].setAttribute("id", "all");
			li[li.length - 1].innerHTML = "<span>All</span>";
			li[li.length - 1].onclick = function() { insertCtrlDisco.openClose('all') };
			ul.appendChild(li[li.length - 1]);
			
			if(request.match(/S/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>Single</span>";
				li[li.length - 1].onclick = function() { insertCtrlDisco.openClose('single');}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/A/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>Album</span>";
				li[li.length - 1].onclick = function() { insertCtrlDisco.openClose('album');}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/D/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>DVD</span>";
				li[li.length - 1].onclick = function() { insertCtrlDisco.openClose('dvd');}
				ul.appendChild(li[li.length - 1]);
			}
			
			if(request.match(/E/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>etc</span>";
				li[li.length - 1].onclick = function() { insertCtrlDisco.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);
			
			main.insertBefore(div, disco);
			main.insertBefore(hr, disco);
		}
	},
		
	'openClose' : function(target) {
		var disco = document.getElementById("discography");
		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";
				}
			}
		}
	}
}

//####################//
//## イニシャライズ ##//
//####################//
YAHOO.util.Event.onDOMReady(function() {
	AddFuncDiscoDL.init();
	//insertCtrlDisco.init('SADE');
});
