/* [http://www.mods-style.jp/]
 * Summary: common script
 * LastModified: 2009-03-10
 * This script requires jquery.js
 */

/*----------------------------------------------------------------------------

----------------------------------------------------------------------------*/
var mods = {
	utilityLinkInit: function() {
		$("#utility_nav li.legal a, a.legal").click(function() {
			window.open(this.href, "legalWin", "scrollbars=1, resizable=1, width=630,height=480");
			return false;
		});
		$("#utility_nav li.privacy_policy a, a.privacy_policy").click(function() {
			window.open(this.href, "ppWin", "scrollbars=1, resizable=1, width=630,height=480");
			return false;
		});
	},
	
	rollOverImg: function() {
		var active = "_on"; // active時のファイル名設定
		var _class = "img.rollover, input[type=image].rollover"; // 要素指定
		
		var img = [], preLoadImg = [], srcs = [];
		var src, srcOn, extpos, path, i, l;
		$(_class).each(function() {img.push(this);});
		for(i=0, l=img.length; i<l; i++) {
			src = img[i].getAttribute("src");
			extpos = src.lastIndexOf(".");
			path = src.substring(0, extpos);
			preLoadImg.push(new Image());
			// 既にactiveの場合は処理中止
			if(path.substring(path.length - 3, path.length) === active) continue;
			// preload
			preLoadImg[i].src = path + active + src.substring(extpos, src.length);
			// イベント設定
			img[i].onmouseover= function() {
				src = this.getAttribute("src");
				extpos = src.lastIndexOf(".");
				srcOn = (src.substring(0, extpos) + active + src.substring(extpos, src.length));
				this.setAttribute("src", srcOn);
			};
			img[i].onmouseout = function() {
				if(!src) return;
				this.setAttribute("src", src);
			};
		}
	},
	
	currentNav: function() {
		var gNav = document.getElementById("global_nav");
		if(!gNav) return;
		var nav = gNav.getElementsByTagName("a");
		var crClassName = "current";
		var path = location.pathname;
		if(path == "/" || path.substr(0,7) == "/index.") {
			nav[0].className = crClassName;
		} else if(path.indexOf("/styling/") != -1) {
			nav[1].className = crClassName;
		} else if(path.indexOf("/lineup/") != -1) {
			nav[2].className = crClassName;
		} else if(path.indexOf("/special/") != -1) {
			nav[3].className = crClassName;
		} else if(path.indexOf("/tvcm/") != -1) {
			nav[4].className = crClassName;
		} else if(path.indexOf("/club/") != -1 || path.indexOf("/clubmods/") != -1) {
			nav[5].className = crClassName;
		}
		
	},
	
	closeBtn: function() {
		document.write('<p class="close"><a href="javascript:window.close();"><img src="/images/btn_close.gif" alt="このウィンドウを閉じる" width="65" height="19" class="rollover"></a></p>');	
	}
};

/*----------------------------------------------------------------------------
 onload event function
----------------------------------------------------------------------------*/
$(document).ready(function() {
	mods.rollOverImg();
	mods.utilityLinkInit();
	mods.currentNav();
});

