/* ===============================================
# 検索窓処理
=============================================== */
function searchTextSet(n) {
	var elm = $("search-textbox");

	// 検索窓にフォーカスがいったら初期文字列消去
	if (n == 0) {
		if (elm.value == "PowerdByGoogle") {
			elm.value = "";
		}
	}

	// 検索窓に何もない状態でどこかをクリックしたら初期化
	if (n == 1) {
		if (elm.value == "" && (elm.style.color == "#999999" || elm.style.color == "rgb(153, 153, 153)")) {
			elm.style.color = "#333333";
		} else
		if (elm.value == "" && (elm.style.color == "#333333" || elm.style.color == "rgb(51, 51, 51)")) {
			elm.style.color = "#999999";
			elm.value = "PowerdByGoogle";
		}
	}

	// 検索窓に入力し始めたら文字の色を変更
	if (n == 2) {
		elm.style.color = "#333333";
	}
}

/* ===============================================
# class="imgover" の要素に、マウスオーバーで
　"_o.gif" の画像と入れ替える
=============================================== */
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
window.onload = initRollovers;
try{
	window.addEventListener("load",initRollovers,false);
}catch(e){
	window.attachEvent("onload",initRollovers);
}

/* ===============================================
# pageTop スムーズスクロール
=============================================== */
var __scroll = {sp:6, fps:16, timer:0};
function setScrollSp(sp) {
	if(typeof sp == "number") {
		this.__scroll.sp = sp;
	}
}
function setScrollFps(fps) {
	if(typeof fps == "number") {
		this.__scroll.fps = fps;
	}
}
function scrollToTop() {
	pageScroll(0, 0);
}
function getScrollLeft() {
	if(navigator.userAgent.indexOf("MSIE") != -1) {
		return (document.compatMode == "CSS1Compat") ? document.documentElement.scrollLeft : document.body.scrollLeft;
	} else {
 	 return (window.pageXOffset) ? window.pageXOffset : 0;
 }
}
function getScrollTop() {
	if(navigator.userAgent.indexOf("MSIE") != -1) {
		return (document.compatMode == "CSS1Compat") ? document.documentElement.scrollTop : document.body.scrollTop;
	} else {
 	 return (window.pageYOffset) ? window.pageYOffset : 0;
 }
}
function pageScroll(toX, toY, cuX, cuY) {
	clearTimeout(this.__scroll.timer);
	toX = (!toX || toX < 0) ? 0 : toX;
	toY = (!toY || toY < 0) ? 0 : toY;
	cuX = (!cuX) ? 0 + getScrollLeft() : cuX;
	cuY = (!cuY) ? 0 + getScrollTop() : cuY;
	cuX += (toX - getScrollLeft()) / this.__scroll.sp;
	cuY += (toY - getScrollTop()) / this.__scroll.sp;
	if(cuX < 0) { cuX = 0; }
	if(cuY < 0) {	cuY = 0;	}
	window.scrollTo(Math.floor(cuX), Math.floor(cuY));
	if(Math.floor(cuX) != toX || Math.floor(cuY) != toY) {
		this.__scroll.timer = setTimeout("pageScroll("+toX+","+toY+"," +cuX+","+cuY+")",this.__scroll.sp);
	}
}

/* ===============================================
# 印刷用
=============================================== */
// PRINT BUTTON +++++++++++++++++++++++++++++++++++++//
function openWin(){
	window.open(window.location.href,"printWindow");
}



/* ===============================================
# 文字サイズ
=============================================== */
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

window.onload = function() {
	try {
	document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
} 

/* ===============================================
# onload 処理
=============================================== */
window.onload = function() {
	//検索窓関連関数
	var elm = $("search-textbox");
	elm.onclick = new Function("searchTextSet(0)");
	elm.onkeypress = new Function("searchTextSet(2)");
	document.body.onclick = new Function("searchTextSet(1)");
	elm.value = "PowerdByGoogle";
	elm.style.color = "#999999";
}
