//########################//
//## 広告Flashタグ挿入 ##//
//########################//
var CtrlADFlash = {
	'init' : function(days, finish, cookie, setTime, imgPath, jumpURL, dummyURL) {
		YAHOO.util.Event.onDOMReady(function() {
			CtrlADFlash.draw(days, finish, cookie, setTime, imgPath, jumpURL, dummyURL, 'ad-flash-small', '../../../flash/ad_small.swf',  'small');
		});
	},
	
	'draw' : function(days, finish, cookie, setTime, imgPath, jumpURL, dummyURL, id, swfname, type) {
		if(finish.match(/^\d\d\d\d-\d\d-\d\d/)) {
			var parts = finish.split(" ");
			
			var YMD = parts[0].split("-");
			if(typeof parts[1] != 'undefined') {
				if(parts[1].match(/^\d\d:\d\d:\d\d$/)) {
					var HMS = parts[1].split(":");
					var d = new Date(YMD[0], YMD[1]-1, YMD[2], HMS[0], HMS[1], HMS[2]);
				} else {
					var d = new Date(YMD[0], YMD[1]-1, YMD[2]);
				}
			} else {
				var d = new Date(YMD[0], YMD[1]-1, YMD[2]);
			}
			
			if(serverTime - d.getTime() < 0) {
				if(cookie != 'ALWAYS' && document.cookie.indexOf(cookie + "=true") != -1) {
					return;
				} else {
					var winWidth;
					var winHeight;
					if(type == 'small') {
						winWidth = "400";
						winHeight = "300";
					} else {
						winWidth = window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);
						winHeight = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
					}
					
					var tempImg = document.createElement("img");
					tempImg.path = imgPath;
					tempImg.onload = function() {
						if(winWidth / winHeight > this.width / this.height) {
							if(winHeight < this.height + 100) {
								imgPath = 'http://www.teichiku.co.jp/script/original/ctrl_image.php%3Fsrc=' + imgPath + '%26height=' + (winHeight - 100);
							}
						} else {
							if(winWidth < this.width + 100) {
								imgPath = 'http://www.teichiku.co.jp/script/original/ctrl_image.php%3Fsrc=' + imgPath + '%26width=' + (winWidth - 100);
							}
						}
						var body = document.getElementsByTagName("BODY");
						var insertPoint = document.getElementById("header");
						
						var div = document.createElement("div");
						div.setAttribute("id", id);
						
						var hr = document.createElement("hr");
						
						if(YAHOO.env.ua.ie) {
							if(jumpURL != null) {
								if(dummyURL != null) {
									div.innerHTML = '<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="100%" height="100%"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + swfname + '" /><param name="quality" value="high" /><param name="wmode" value="transparent"><param name="FlashVars" value="setTime=' + setTime + '&imgPath=' + imgPath + '&jumpURL=' + jumpURL + '&dummyURL=' + dummyURL + '" /></object>';
								} else {
									div.innerHTML = '<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="100%" height="100%"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + swfname + '" /><param name="quality" value="high" /><param name="wmode" value="transparent"><param name="FlashVars" value="setTime=' + setTime + '&imgPath=' + imgPath + '&jumpURL=' + jumpURL + '" /></object>';
								}
							} else {
								div.innerHTML = '<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="100%" height="100%"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + swfname + '" /><param name="quality" value="high" /><param name="wmode" value="transparent"><param name="FlashVars" value="setTime=' + setTime + '&imgPath=' + imgPath + '" /></object>';
							}
						} else {
							var wrapper = document.createElement("div");
							var embed = document.createElement("embed");
							
							embed.setAttribute("src", swfname);
							embed.setAttribute("quality", "high");
							embed.setAttribute("wmode", "transparent");
							embed.setAttribute("width", "100%");
							embed.setAttribute("height", "100%");
							if(jumpURL != null) {
								if(dummyURL != null) {
									embed.setAttribute("FlashVars", 'setTime=' + setTime + '&imgPath=' + imgPath + '&jumpURL=' + jumpURL + '&dummyURL=' + dummyURL);
								} else {
									embed.setAttribute("FlashVars", 'setTime=' + setTime + '&imgPath=' + imgPath + '&jumpURL=' + jumpURL);
								}
							} else {
								embed.setAttribute("FlashVars", 'setTime=' + setTime + '&imgPath=' + imgPath);
							}
							embed.setAttribute("allowScriptAccess", "sameDomain");
							embed.setAttribute("type", "application/x-shockwave-flash");
							embed.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
							
							wrapper.appendChild(embed);
							div.appendChild(wrapper);
						}
						div.appendChild(hr);
						body[0].insertBefore(div, insertPoint);
						div.style.height = winHeight + "px";
						
						if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
							window.attachEvent('onscroll',  CtrlADFlash.fixed);
							window.attachEvent('onresize',  CtrlADFlash.fixed);
							
							CtrlADFlash.fixed();
						}
						
						var limit = new Date();
						limit.setTime(limit.getTime() + (1000 * 60 * 60 * 24 * days));
						limitGMT = limit.toGMTString();
						document.cookie = cookie + "=true;expires=" + limitGMT + ";";
					}
					var d = new Date();
					tempImg.setAttribute("src", imgPath + '?t=' +d.getTime());
				}
			}
		}
	},
	
	'remove' : function() {
		var target;
		
		if(document.getElementById("ad-flash")) {
			target = document.getElementById("ad-flash");
		} else if(document.getElementById("ad-flash-small")) {
			target = document.getElementById("ad-flash-small");
		}
		
		target.parentNode.removeChild(target);
		if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
			window.detachEvent('onscroll',  CtrlADFlash.fixed);
			window.detachEvent('onresize',  CtrlADFlash.fixed);
		}
	},
	
	'fixed' : function() {
		var target;
		
		if(document.getElementById("ad-flash")) {
			target = document.getElementById("ad-flash");
		} else if(document.getElementById("ad-flash-small")) {
			target = document.getElementById("ad-flash-small");
		}
		
		target.style.top = GET.scrollY() + "px";
		target.style.left = GET.scrollX() + "px";
		target.style.height = "100%";
	},
	
	'addFooter' : function(interval, limit, image , url, dummy, title) {
		YAHOO.util.Event.onDOMReady(function() {
			var max = limit.length;
			
			var parent = document.getElementById("footer");
			var target = document.getElementById("insertPointFooter");
			
			var hr = document.createElement("hr");
			if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 8) {
				hr.setAttribute("className", "clear");
			} else {
				hr.setAttribute("class", "clear");
			}
			var ul = document.createElement("ul");
			ul.setAttribute("id", "AD");
			
			var p = document.createElement("p");
			p.setAttribute("id", "AD-note");
			p.innerHTML = '現在このページに「お知らせ」として表示されるFLASH一覧です。クリックするとFLASHを再表示します。';
			
			for(var i = 0; i < max; i++) {
				var parts = limit[i].split(" ");
				
				var YMD = parts[0].split("-");
				if(typeof parts[1] != 'undefined') {
					if(parts[1].match(/^\d\d:\d\d:\d\d$/)) {
						var HMS = parts[1].split(":");
						var d = new Date(YMD[0], YMD[1]-1, YMD[2], HMS[0], HMS[1], HMS[2]);
					} else {
						var d = new Date(YMD[0], YMD[1]-1, YMD[2]);
					}
				} else {
					var d = new Date(YMD[0], YMD[1]-1, YMD[2]);
				}
				
				if(serverTime - d.getTime() < 0) {
					var text = document.createTextNode(title[i]);
					
					var li = document.createElement("li");
					
					var a = document.createElement("a");
					a.setAttribute("href", dummy[i]);
					a.interval = interval[i];
					a.image = image[i];
					a.url = url[i];
					a.dummy = dummy[i];
					a.appendChild(text);
					a.onclick = function() {
						if(!document.getElementById('ad-flash-small')) {
							CtrlADFlash.draw(this.interval, '2099-01-01 23:59:00', 'ALWAYS', -1, this.image, this.url, this.dummy, 'ad-flash', '../../../flash/ad.swf', 'full');
						} else {
							alert("現在表示されている「お知らせ」を非表示にして下さい。")
						}
						return false;
					}
					
					li.appendChild(a);
					ul.appendChild(li);
				}
			}
			
			if(ul.hasChildNodes()) {
				parent.insertBefore(hr, target);
				parent.insertBefore(ul, target);
				parent.insertBefore(p, target);
			}
		});
	}
}

//########################//
//## 歌詞 Flashタグ挿入 ##//
//########################//
var Lyric = {
	'init' : function(file, sizeX, sizeY) {
		var parent = document.getElementById("flash");
		var div = document.createElement("div");
		div.setAttribute("id", "data");
        
		if(YAHOO.env.ua.ie) {
			div.innerHTML = '<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="' + sizeX + '" height="' + sizeY + '"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + file + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /></object>';
        } else {
            var wrapper = document.createElement("div");
            var embed = document.createElement("embed");
            
            embed.setAttribute("src", file);
            embed.setAttribute("quality", "high");
            embed.setAttribute("wmode", "transparent");
            embed.setAttribute("width", sizeX);
            embed.setAttribute("height", sizeY);
            embed.setAttribute("allowScriptAccess", "sameDomain");
            embed.setAttribute("type", "application/x-shockwave-flash");
            embed.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
            
            wrapper.appendChild(embed);
            div.appendChild(wrapper);
        }
        parent.appendChild(div);
    }
}

//####################//
//## イニシャライズ ##//
//####################//
YAHOO.util.Event.onDOMReady(function() {
	if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) CtrlMainWidth.force();
	if(!YAHOO.env.ua.webkit) Shadowbox.init();
});