//#########################################################//
//## ディスコグラフィー用 dlタグ全体をクリック範囲にする ##//
//#########################################################//
var AddFuncDiscoDL = {
	'option' : {
		'startC' : "#0e2b37",
		'endC' : [ "#ffffff" ],
		'level' : 15,
		'step' : 10
	},
	
	'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(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
				dlTags[i].style.cursor = "hand";
			} else {
				dlTags[i].style.cursor = "pointer";
			}
			
			dlTags[i].counter = 0;
			dlTags[i].intervalID = setInterval("", this.option.step);
			dlTags[i].timeoutID = setTimeout("", 40);
			dlTags[i].endC = this.option.endC[Math.floor(Math.random() * this.option.endC.length)];
			dlTags[i].colors = CtrlGradation.gradation(this.option.startC, dlTags[i].endC, this.option.level);
			
			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)";
				//this.intervalID = that.gradation(this);
			}
			
			dlTags[i].onmouseout = function () {
				var self = this;
				
				clearInterval(this.intervalID);
				
				this.timeoutID = setTimeout(function() {
					//self.counter = 0;
					self.style.backgroundImage = "url(../img/basic/back_stripe_white.gif)";
					//self.style.borderColor = that.option.startC;
					//self.endC = that.option.endC[Math.floor(Math.random() * that.option.endC.length)];
					//self.colors = CtrlGradation.gradation(that.option.startC, self.endC, that.option.level);
				}, 40);
			}
		}
	},
	
	'gradation' : function(obj) {
		var that = this;
		
		return setInterval(function() {
			if(obj.counter < that.option.level) {
				CtrlGradation.setColor(obj, obj.colors[obj.counter++]);
			} else {
				clearInterval(obj.intervalID);
			}
		}, that.option.step);
	}
};

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(/BEST/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>BEST</span>";
				li[li.length - 1].onclick = function() { insertCtrlDisco.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() { insertCtrlDisco.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() { insertCtrlDisco.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() { insertCtrlDisco.openClose('dvd');}
				ul.appendChild(li[li.length - 1]);
			}
			if(request.match(/AUDIO/)) {
				li.push(document.createElement("li"));
				li[li.length - 1].innerHTML = "<span>DVD-Audio</span>";
				li[li.length - 1].onclick = function() { insertCtrlDisco.openClose('audio');}
				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() { 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() {
	if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) CtrlMainWidth.force();
	AddFuncDiscoDL.init();
	insertCtrlDisco.init('ALBUM,SINGLE');
});
