//########################//
//## 動画 Flashタグ挿入 ##//
//########################//
function drawFlashMovie(id, file, xsize, ysize, flv, jump) {
	document.write('<h4>ニューリリース</h4>' + "\n");
	if((navigator.userAgent.indexOf("MSIE 5") != -1 && (navigator.userAgent.indexOf("PPC Mac") != -1 || navigator.userAgent.indexOf("PowerPC") != -1)) || YAHOO.env.ua.ie == 0) {
		if(flv != null) {
			if(jump != null) {
				document.write('<div><embed src="'+ file + '" quality="high" wmode="transparent" width="' + xsize + '" height="' + ysize +  '" FlashVars="flvPath=' + flv + '&jumpURL=' + jump + '" name="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></div>' + "\n");
			} else {
				document.write('<div><embed src="'+ file + '" quality="high" wmode="transparent" width="' + xsize + '" height="' + ysize +  '" FlashVars="flvPath=' + flv + '" name="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></div>' + "\n");
			}
		} else {
			document.write('<div><embed src="'+ file + '" quality="high" wmode="transparent" width="' + xsize + '" height="' + ysize + '" name="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></div>' + "\n");
		}
	} else {
		document.write('<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="' + xsize + '" height="' + ysize + '">' + "\n");
		document.write('<param name="allowScriptAccess" value="sameDomain" />' + "\n");
		document.write('<param name="movie" value="' + file + '" />' + "\n");
		document.write('<param name="quality" value="high" />' + "\n");
		document.write('<param name="wmode" value="transparent" />' + "\n");
		if(flv != null) {
			if(jump != null) {
				document.write('<param name="FlashVars" value="flvPath=' + flv + '&jumpURL=' + jump + '" />' + "\n");
			} else {
				document.write('<param name="FlashVars" value="flvPath=' + flv + '" />' + "\n");
			}
		}
		document.write('</object>' + "\n");
	} 
}

//##########################//
//## 更新履歴表示チェック ##//
//##########################//
var ChkModify = {
	'init' : function() {
		var flag = false;
		var modify = document.getElementById("modify");
		var p = modify.getElementsByTagName("P");
		var max = p.length;
		var re = new RegExp("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]");
		var re2 = new RegExp("［information］");
		
		for(var i = 0; i < max; i++) {
			if(re.exec(p[i].innerHTML) != null) {
				var string = re.exec(p[i].innerHTML);
				var dateValue = string[0].split("-");
				var targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
				var nowDate = new Date();
				if(nowDate.getTime() - targetDate.getTime() < 7 * 24 * 60 * 60 * 1000) {
					flag = true;
				}
				if(getClassName(p[i]) != null) {
					if(getClassName(p[i]).match(/^del_[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
						var parts = getClassName(p[i]).split("_");
						dateValue = parts[1].split("-");
						targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
						nowDate = new Date();
						if(nowDate.getTime() > targetDate.getTime()) {
							p[i].style.display = "none";
						} else {
							flag = true;
						}
					}
				}
			}
			
			if(re2.exec(p[i].innerHTML) != null) {
				if(getClassName(p[i]) != null) {
					if(getClassName(p[i]).match(/^del_[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
						var parts = getClassName(p[i]).split("_");
						dateValue = parts[1].split("-");
						targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
						nowDate = new Date();
						if(nowDate.getTime() > targetDate.getTime()) {
							p[i].style.display = "none";
						} else {
							flag = true;
						}
					}
				}
			}
		}
		if(flag) modify.style.display = "block";
	}
}

//######################//
//## IE6で透明PNG使用 ##//
//######################//
var ChangePNG = {
	'init' : function() {
		if(0 < YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7 && document.getElementById("info-push-unit")) {
			var div = document.getElementById("info-push-unit");
			var h4 = div.getElementsByTagName("H4");
			h4[0].runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="./img/basic/back_h4_push.png", sizingmethod="scale")';
			h4[0].style.backgroundImage = "none";
		}
	}
}

//##############################################################################//
//## topics スライドメニュー 要 mootools ver 1.11（Element.Event & Fx.Slide） ##//
//##############################################################################//
var TopicsSlider = {
	'init' : function() {
		var topics = document.getElementById("topics");
		var dl =  topics.getElementsByTagName("DL");
		var div = topics.getElementsByTagName("DIV");
		
		if(dl.length == div.length) {
			var len = dl.length;
			for(var i = 0; i < len; i++) {
				dl[i].id = "toggle" + i;
				div[i].id = "topics" + i;
				
				if(getClassName(dl[i]) != null) {
					if(getClassName(dl[i]).match(/^del_[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
						var parts = getClassName(dl[i]).split("_");
						var dateValue = parts[1].split("-");
						var targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
						var nowDate = new Date();
						if(nowDate.getTime() > targetDate.getTime()) {
							dl[i].style.display = "none";
							div[i].style.display = "none";
						}
					}
				}
				
				if(0 < YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 5.5) {
					dl[i].style.cursor = "hand";
				} else {
					dl[i].style.cursor = "pointer";
				}
			}
			
			for(var i = 0; i < len; i++) {
				var imgHeight = 0;
				var p = div[i].getElementsByTagName("P");
				if(p != null) {
					for(var j = 0; j < p.length; j++) {
						if(getClassName(p[j]) == "image") {
							imgHeight += p[j].offsetHeight;
						}
					}
				}
					
				if(imgHeight != 0) {
					if(YAHOO.env.ua.ie == 0 || 7 <= YAHOO.env.ua.ie) {
						div[i].style.minHeight = imgHeight + "px";
					} else {
						div[i].style.height = imgHeight + "px";
					}
				}
			}
			
			for(var i = 0; i < len; i++) {
				eval("var mySlide" + i +  " = new Fx.Slide('topics" + i + "')");
				
				var dd = dl[i].getElementsByTagName("DD");
				
				
				if(dd[0].firstChild.nodeValue.match(/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
    				var dateValue = dd[0].firstChild.nodeValue.split("-")
					var targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
					var nowDate = new Date();
					if (nowDate.getTime() - targetDate.getTime() < 3 * 24 * 60 * 60 * 1000) {
						eval("mySlide" + i + ".show()");
						dl[i].style.fontWeight = "bold";
						dl[i].style.color = "#ff0000";
					} else {
						eval("mySlide" + i + ".hide()");
						dl[i].style.fontWeight = "normal";
						dl[i].style.color = "#333333";
					}
				} else {
					eval("mySlide" + i + ".hide()");
					dl[i].style.fontWeight = "normal";
					dl[i].style.color = "#333333";
				}
				
				$(dl[i].id).addEvent('click', function(e){
					var tempStr = "mySlide" + (this.id).substr(6);
					e = new Event(e);
					if(eval(tempStr + ".open")) {
						this.style.fontWeight = "normal";
						this.style.color = "#333333";
						if(7 <= YAHOO.env.ua.ie && YAHOO.env.ua.ie < 8) {
							eval(tempStr + ".toggle()").chain(FlexMainWidth.force);
						} else {
							eval(tempStr + ".toggle()");
						}
					} else {
						this.style.color = "#ff0000";
						this.style.fontWeight = "bold";
						eval(tempStr + ".toggle()");
					}
					e.stop();
				});
			}
		}
		
	}
}

//#########################################################//
//## ディスコグラフィー用 dlタグ全体をクリック範囲にする ##//
//#########################################################//
var AddFuncDiscoDL = {
	'init' : function() {
		var startC = "#eeeeee";
		var endC = "#ffcc66";
		
		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(0 < 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.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.png)";
				}, 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.png)";
					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 ;
	}
}

//####################//
//## イニシャライズ ##//
//####################//
YAHOO.util.Event.onDOMReady(function() {
	Shadowbox.init();
	ChkModify.init();
	//ChangePNG.init();
	TopicsSlider.init();
	AddFuncDiscoDL.init();
});
