// Init Links
function initLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		// air links
		// external links
		if (anchor.getAttribute("href") && anchor.getAttribute("class") == "air") {
			anchor.setAttribute("title","これはエアリンクです");
			anchor.tmpHref = anchor.href;
			anchor.onmouseover = function () {
				this.href = "";
			};
			anchor.onmouseout = function () {
				this.href = this.tmpHref;
			};
			anchor.onfocus = function () {
				this.href = "";
				this.blur();
			};
			anchor.onblur = function () {
				this.href = this.tmpHref;
			};
			anchor.onclick = function () {
				this.href = this.tmpHref;
				return false;
			};
			anchor.onmousemove = function () {
				this.href = this.tmpHref;
			};
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}

// Init Search
function initSearch() {
	$("search-box").disabled = true;
	$("search-box").onfocus = function () {
		this.value = "";
	};
	$("search-submit").onmouseover = function () {
		$("search-box").value = "検索なんかできないのでトップページに戻ります！";
		$("search-box").disabled = true;
	};
	$("search-submit").onmouseout = function () {
		$("search-box").value = "";
	};
	$("search-submit").onclick = function () {
		location.href = "/";
	};
}

// Init images
function initImages() {
	if (!document.getElementById) return;
	var aPlds = new Array();
	var aBtns = new Array();
	// img
	var aImgs = document.getElementsByTagName('img');
	for (var k = 0; k < aImgs.length; k++) {
		if (aImgs[k].className == 'rollover') {
			aBtns.push(aImgs[k]);
		}
	}
	// input type="image"
	var aIpts = document.getElementsByTagName('input');
	for (var j = 0; j < aIpts.length; j++) {
		if (aIpts[j].className == 'rollover') {
			aBtns.push(aIpts[j]);
		}
	}
	// all image buttons
	for (var i = 0; i < aBtns.length; i++) {
		if (aBtns[i].className == 'rollover') {
			var tmpSrc;
			var img = aBtns[i];
			var src = img.getAttribute('src');
			if (!src) return;
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);
			img.setAttribute('hsrc', hsrc);
			aPlds[i] = new Image();
			aPlds[i].src = hsrc;
			img.onmouseover = function() {
				tmpSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			};
			img.onmouseout = function() {
				if (!tmpSrc) tmpSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', tmpSrc);
			};
		}
	}
}

// Init
function init() {
	initLinks();
	initSearch();
	initImages();
}

Event.observe(window, "load", init, false);
