//########################//
//## 広告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 PromotionVideo = {
	'init' : function(file, sizeX, sizeY, flv, jump) {
		var parent = document.getElementById("info-push-unit");
		var div = document.createElement("div");
		div.setAttribute("id", "pv");
		
		var h4 = document.createElement("h4");
		h4.innerHTML = 'ニューリリース';
		
		parent.appendChild(h4);
        
		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="opaque" /><param name="FlashVars" value="flvPath=' + flv + '&jumpURL=' + jump + '" /></object>';
        } else {
            var wrapper = document.createElement("div");
            var embed = document.createElement("embed");
            
            embed.setAttribute("src", file);
            embed.setAttribute("quality", "high");
            embed.setAttribute("wmode", "opaque");
            embed.setAttribute("width", sizeX);
            embed.setAttribute("height", sizeY);
            embed.setAttribute("FlashVars", 'flvPath=' + flv + '&jumpURL=' + jump);
            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);
    }
}

//##########################//
//## 更新履歴表示チェック ##//
//##########################//
var ChkModify = {
	'option': {
		'mainWidth' : 950,
		'targetWidth' : 480,
		'targetHeight' : 68,
		'menuPaddingLeft' : 500,
		'timerID1' : setTimeout("", 20),
		'timerID2' : setTimeout("", 20),
		'hideFlash' : true
	},
	
	'init': function() {
		if(document.getElementById("modify")) {
			var menu = document.getElementById("menu");
			var modify = document.getElementById("modify");
			var p = modify.getElementsByTagName("P");
			var display = 0;
			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］");
			var flag = false;
			
			for(var i = 0; i < p.length; i++) {
				if(GET.className(p[i]) != '' && GET.className(p[i]) != null) {
					if(GET.className(p[i]).match(/^del_[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
						var parts = GET.className(p[i]).split("_");
						dateValue = parts[1].split("-");
						targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
						if(serverTime > targetDate.getTime()) {
							p[i].style.display = "none";
						} else {
							flag = true;
							display++;
						}
					}
				} else {
					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]);
						if(serverTime - targetDate.getTime() < 30 * 24 * 60 * 60 * 1000) {
							flag = true;
							display++;
						} else {
							p[i].style.display = "none";
						}
					} else if(re2.exec(p[i].innerHTML) != null) {
						flag = true;
						display++;
					}
				}
			}
			if(flag){
				modify.style.display = "block";
				this.initScroll();
				
				if(display == 1) {
					modify.style.top = "2.1em";
				} else {
					modify.style.top = "1.6em";
				}
				
				if(modify.offsetHeight < ChkModify.option.targetHeight) {
					modify.style.height = "auto";
				} else {
					modify.style.height = ChkModify.option.targetHeight + "px";
					
					var more = document.createElement("p");
					more.setAttribute("id", "more-modify");
					more.innerHTML = "全ての更新履歴を表示する"
					
					modify.appendChild(more);
					
					modify.onmouseover = function() {
						clearTimeout(ChkModify.option.timerID2);
						ChkModify.option.timerID1 = setTimeout(function() {
							modify.style.height = "auto";
							more.style.display = "none";
						}, 20);
						if(ChkModify.option.hideFlash) {
							if(YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 522) {
								if(document.getElementById("info-push-unit")) {
									var push = document.getElementById("info-push-unit");
									push.style.display = "none";
								}
							}
						}
					}
					
					modify.onmouseout = function() {
						clearTimeout(ChkModify.option.timerID1);
						clearInterval(ChkModify.option.timerID3);
						ChkModify.option.timerID2 = setTimeout(function() {
							modify.style.height = ChkModify.option.targetHeight + "px";
							more.style.display = "block";
						}, 20);
						if(ChkModify.option.hideFlash) {
							if(YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 522) {
								if(document.getElementById("info-push-unit")) {
									var push = document.getElementById("info-push-unit");
									push.style.display = "block";
								}
							}
						}
					}
				}
				
				if(typeof document.body.style.maxHeight != "undefined") {
					menu.style.width = ChkModify.option.mainWidth - ChkModify.option.menuPaddingLeft + "px"
				}
				menu.style.paddingLeft = ChkModify.option.menuPaddingLeft + "px";
				
				modify.style.position = "absolute";
				
				if(GET.browserWidth() > ChkModify.option.mainWidth) {
					if (window.addEventListener) {
						if(YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 522) {
							modify.style.left = (GET.browserWidth() - 17 - ChkModify.option.mainWidth) / 2 + 20 + "px";
						} else {
							modify.style.left = (GET.browserWidth() - 17 - ChkModify.option.mainWidth) / 2 + 10 + "px";
						}
					} else {
						modify.style.left = (GET.browserWidth() - ChkModify.option.mainWidth) / 2 + 10 + "px";
					}
				} else {
					modify.style.left = "10px";
				}
				
				if (window.addEventListener) { 
					window.addEventListener("resize", function() {
						if(GET.browserWidth() > ChkModify.option.mainWidth) {
							if(YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 522) {
								modify.style.left = (GET.browserWidth() - 17 - ChkModify.option.mainWidth) / 2 + 20 + "px";
							} else {
								modify.style.left = (GET.browserWidth() - 17 - ChkModify.option.mainWidth) / 2 + 10 + "px";
							}
						} else {
							modify.style.left = "10px";
						}
					}, false);
				} else if (window.attachEvent) {
					window.attachEvent("onresize", function() {
						if(GET.browserWidth() > ChkModify.option.mainWidth) {
							modify.style.left = (GET.browserWidth() - 0 - ChkModify.option.mainWidth) / 2 + 10 + "px";
						} else {
							modify.style.left = "10px";
						}
					});
				}
				modify.style.width = ChkModify.option.targetWidth + "px";
			}
		}
	},
	
	'initScroll' : function() {
		var parent = document.getElementById("modify");
		var pTags = parent.getElementsByTagName("P");
		var max = pTags.length;
		
		for(var i = 0; i < max; i++) {
			this.setFunc(pTags[i]);
		}
	},
   	
   	'setFunc' : function(target) {
   		target.indent = 0;
   		target.timerID1 = setInterval("", 40);
   		target.timerID2 = setTimeout("", 20);
   		
		target.onmouseover = function() {
			clearTimeout(target.timerID2);
			
			var span = document.createElement("span");
			var text = document.createTextNode(target.innerHTML.replace(/<\/?[^>]+>/gi, ""));
			span.appendChild(text);
			target.appendChild(span);
			var charSize = span.offsetWidth + 20;
			target.removeChild(span);
			
			target.style.backgroundImage = "url(./img/basic/back_ani_white.gif)";
			
			var len = charSize;
			
			if(len > ChkModify.option.targetWidth) {
				target.timerID1 = setInterval(function() {
					target.indent = target.indent - 2;
					target.style.textIndent = target.indent + "px";
					
					if(target.indent < -len) {
						target.indent = target.offsetWidth + 5;
					}
				}, 40);
			}
		}
		target.onmouseout = function() {
			clearInterval(this.timerID1);
			
			target.timerID2 = setTimeout(function() {
				target.indent = 0;
				target.style.textIndent = "0";
				target.style.backgroundImage = "";
			}, 20);
		}
   	},
   	
   	'strLength' : function(strSrc) {
		var len = 0;
		strSrc = escape(strSrc);
		for(i = 0; i < strSrc.length; i++, len++){
			if(strSrc.charAt(i) == "%"){
				if(strSrc.charAt(++i) == "u"){
					i += 3;
					len++;
				}
				i++;
			}
		}
		return len;
   	}
}

//######################//
//## ブログチェッカー ##//
//######################//
var BlogChecker = {
	'check' : function(target, url) {
		YAHOO.util.Event.onDOMReady(function() {
			var backup = document.getElementById(target).innerHTML;
			if(window.XMLHttpRequest != null) {
				var message = new XMLHttpRequest;
			} else if(window.ActiveXObject) {
				try {
					var message = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					var message = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} else {
			       return null;
			}
			message.onreadystatechange = function() {
				if(message.readyState == 4) {
					if(message.status == 200) {
						document.getElementById(target).innerHTML = backup + message.responseText;
					} else {
						document.getElementById(target).innerHTML = backup + '<span class="article">ブログの読み込みに失敗しました。</span>';
					}
				} else {
					document.getElementById(target).innerHTML = backup + '<span class="article">ブログチェック中...</span>';
				}
			}
			if(url != null) {
				message.open('GET', "./script/original/get_blog.php?url=" + url, true);
			}
			message.send(null);
		});
	}
}

//##############################################################################//
//## 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(GET.className(dl[i]) != null) {
					if(GET.className(dl[i]).match(/^del_[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)) {
						var parts = GET.className(dl[i]).split("_");
						var dateValue = parts[1].split("-");
						var targetDate = new Date(dateValue[0], dateValue[1]-1, dateValue[2]);
						if(serverTime > targetDate.getTime()) {
							if(!YAHOO.env.ua.webkit || 522 <= YAHOO.env.ua.webkit) {
								dl[i].style.display = "none";
								div[i].style.display = "none";
							}
						}
					}
				}
				
				if(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(GET.className(p[j]) == "image") {
							imgHeight += p[j].offsetHeight;
						}
					}
				}
					
				if(imgHeight != 0) {
					if(!YAHOO.env.ua.ie || 7 <= YAHOO.env.ua.ie) {
						div[i].style.height = "auto";
						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(GET.className(dd[0]).match(/always/)) {
					eval("mySlide" + i + ".show()");
					dl[i].style.fontWeight = "bold";
					dl[i].style.color = "#ff0000";
				} else 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]);
					if (serverTime - 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(YAHOO.env.ua.ie == 7) {
							eval(tempStr + ".toggle()").chain(CtrlMainWidth.force);
						} else {
							eval(tempStr + ".toggle()");
						}
					} else {
						this.style.color = "#ff0000";
						this.style.fontWeight = "bold";
						eval(tempStr + ".toggle()");
					}
					e.stop();
				});
			}
		}
	}
}

//##########################//
//## 泡表示 Flashタグ挿入 ##//
//##########################//
var ShowBubble = {
	'draw' : function() {
		var parent = document.getElementById("main");
		
		var div = document.createElement("div");
		div.setAttribute("id", "bubble");
		
		var h4 = document.createElement("h4");
		h4.innerHTML = '泡表示';
		
		div.appendChild(h4);
		
		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="950" height="735"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="./flash/bubble.swf" /><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", './flash/bubble.swf');
            embed.setAttribute("quality", "high");
            embed.setAttribute("wmode", "transparent");
            embed.setAttribute("width", 950);
            embed.setAttribute("height", 735);
            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);
    },
    
    'remove': function() {
    	if(document.getElementById("bubble")) {
    		var target = document.getElementById("bubble");
    		target.parentNode.removeChild(target);
    	}
    }
}

//##########################//
//## shadowbox用 href操作 ##//
//##########################//
var AddURL = {
	'init': function() {
		var aTags = document.getElementsByTagName("A");
		var max = aTags.length;
		
		
		for(var i = 0; i < max; i++) {
			var rel = aTags[i].getAttribute("rel");
			if(rel != null && rel.match(/shadowbox/)) {
				aTags[i].href += '?shadowbox';
			}
		}
	}
}

//###############################//
//## マウスストーカー表示切替 ###//
//###############################//
var CtrlStalker = {
	'init': function() {
		var body = document.getElementsByTagName("BODY");
		var header = document.getElementById("header");
		var p = document.createElement("p");
		p.style.position = "absolute";
		p.style.top = "0";
		p.style.left = "0";
		p.style.zIndex = "5000";
		p.style.margin = "0";
		p.style.padding = "5px";
		p.style.color = "#ffffff";
		p.style.fontSize = "82%";
		
		var text = document.createTextNode('「追いかけアイコン」と「ふりがな」を表示する');
		
		var input = document.createElement("input");
		input.setAttribute("id", "ctrl-stalker");
		input.setAttribute("type", "checkbox");
		
		p.appendChild(input);
		p.appendChild(text);
		
		input.onclick = function() {
			CtrlStalker.check();
		}
		
		header.appendChild(p);
		
		if(document.cookie.indexOf("irukaCtrlStalkerHidden=false") != -1) {
			input.checked = true;
		}
		
		this.check();
	},
	
	'check': function() {
		if(document.getElementById("ctrl-stalker")) {
			var body = document.getElementsByTagName("BODY");
			
			var limit = new Date();
			limit.setTime(limit.getTime() + (1000 * 60 * 60 * 24 * 30));
			
			var target = document.getElementById("ctrl-stalker");
			var divTags = document.getElementsByTagName("DIV");
			var spanTags = document.getElementsByTagName("SPAN");
			
			if(target.checked) {
				var ext = '.png';
				if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) ext = '.gif'
				
				MouseStalker.init("iruka", "./img/other/icon_iruka" + ext);
				//MouseStalker.init("qrcode", "./img/other/icon_qrcode_sakanakun_te" + ext);
				MouseStalker.init("hitode", "./img/other/icon_hitode" + ext);
				MouseStalker.init("kai", "./img/other/icon_kai" + ext);
				
				ShowBubble.remove();
				
				for(var i = 0; i < spanTags.length; i++) {
					if(GET.className(spanTags[i]) != null && GET.className(spanTags[i]).match(/ruby/)) {
						spanTags[i].setAttribute('class', 'ruby-shown');
						spanTags[i].setAttribute('className', 'ruby-shown');
					}
				}
				document.cookie = "irukaCtrlStalkerHidden=false;expires=" + limit.toGMTString() + ";";
			} else {
				for(var i = 0; i < divTags.length; i++) {
					if(divTags[i].k && divTags[i].power) {
						clearInterval(divTags[i].timerID);
						body[0].removeChild(divTags[i--]);
					}
				}
				
				ShowBubble.draw();
				
				for(var i = 0; i < spanTags.length; i++) {
					if(GET.className(spanTags[i]) != null && GET.className(spanTags[i]).match(/ruby/)) {
						spanTags[i].setAttribute('class', 'ruby-hidden');
						spanTags[i].setAttribute('className', 'ruby-hidden');
					}
				}
				document.cookie = "irukaCtrlStalkerHidden=true;expires=" + limit.toGMTString() + ";";
			}
		}
	}
}

//#######################//
//## マウスストーカー ###//
//#######################//
var MouseStalker = {
	'option': {
		'mouseX': -100,
		'mouseY': -100,
		'zIndex': 99999
	},
	
	'init': function(id, path) {
		var img = document.createElement("img");
		
		img.onload = function() {
			var stalker = document.createElement("div");
			stalker.setAttribute("id", id);
			stalker.style.position = "absolute";
			stalker.style.top = MouseStalker.option.mouseY + "px";
			stalker.style.left = MouseStalker.option.mouseX + "px";
			stalker.style.zIndex = MouseStalker.option.zIndex--;
			stalker.style.width = this.width + "px";
			stalker.style.height = this.height + 2 + "px";
			if(id == "iruka") {
				stalker.backup = 0.94;
			} else {
				stalker.backup = 0.9 + Math.random() * 0.06;
			}
			stalker.k = stalker.backup;
			stalker.power = 0.003 + Math.random() * 0.0005;
			
			stalker.calcX = 0;
			stalker.calcY = 0;
			
			stalker.appendChild(this);
			
			var body = document.getElementsByTagName("BODY");
			
			body[0].appendChild(stalker);
			
			document.onmousemove = function(e) {
				MouseStalker.option.mouseX = GET.mouse(e).x + 20;
				MouseStalker.option.mouseY = GET.mouse(e).y + 20;
			}
			
			stalker.timerID = setInterval(function() {
				MouseStalker.move(stalker)
			}, 20);
		}
		img.setAttribute("src", path);
	},
	
	'move' : function(obj) {
		obj.calcX = obj.calcX * obj.k + (MouseStalker.option.mouseX - GET.posX(obj)) * obj.power;
		obj.calcY = obj.calcY * obj.k + (MouseStalker.option.mouseY - GET.posY(obj)) * obj.power;
		
		if(
			Math.abs(obj.calcX) < 1.5 
			&& Math.abs(obj.calcY) < 1.5
			&& Math.abs(MouseStalker.option.mouseX - GET.posX(obj)) < 30
			&& Math.abs(MouseStalker.option.mouseY - GET.posY(obj)) < 30
		) {
			obj.k = 1;
		} else {
			obj.k = obj.backup;
		}
		
		obj.style.top = parseInt(obj.style.top) + obj.calcY + "px";
		obj.style.left = parseInt(obj.style.left) + obj.calcX + "px";
	}
}

//##########################//
//## 指定オブジェクト浮遊 ##//
//##########################//
var FloatingObject = {
	'init': function(id) {
		if(document.getElementById(id)) {
			var target = document.getElementById(id);
			target.defaultTop = GET.posY(target);
			target.style.top =  GET.style(target, "top");
			target.amplitude = 15 + parseInt(Math.random() * 10); //振幅
			target.k = 0.015 + Math.random() * 0.003; //バネ係数
			target.calcY = 0;
			
			target.timerID = setInterval(function() {
				FloatingObject.move(target);
			}, 40);
		}
	},
	
	'move' : function(obj) {
		obj.calcY = obj.calcY * 1 + (obj.defaultTop - obj.amplitude - GET.posY(obj)) * obj.k;
		obj.style.top = parseInt(obj.style.top) + obj.calcY + "px";
	}
}

//####################//
//## イニシャライズ ##//
//####################//
window.onload = function() {
	Popup.init();
	FineScroll.init();
	CtrlHeaderFooter.init();
	
	FloatingObject.init('button-catalog')
	FloatingObject.init('button-profile')
	FloatingObject.init('button-cap')
	
	ChkModify.init();
	CtrlStalker.init();
	AddURL.init();
	
	TopicsSlider.init();
	Shadowbox.init();
}