/*
 *
 *	common.js
 *
*/


/*  debug
----------------------------------------------------- */
// デバグモードの切り替え
var debugMode = false;

function _debug(_log) {
	if (!debugMode) return;
	if ( window.console ) {
		window.console.log(_log);
	} else {
		//alert(_log);	
	}
}

// ====================================================================================
// popupWindow
function popupWindow(url, width, height, option, windowName) {	
	if (!width) width = window.innerWidth || document.documentElement.clientWidth;
	if (!height) height = window.innerHeight || document.documentElement.clientHeight;
	if (!option) option = 'menubar=yes, toolbar=yes, location=yes, status=yes, scrollbars=yes, resizable=yes';
	if (!windowName) windowName = "popup";
	var x = (screen.availWidth - width)/2;
	var y = (screen.availHeight - height)/2;
	var o = option+', width='+width+', height='+height+', left='+x+', top='+y;
	var blockMessage = "ウィンドウがお使いのブラウザでポップアップブロックされました。\nポップアップブロックを解除してください。";
	var win = window.open(url, windowName, o);
	if (win) {
		win.focus();
	} else {
		alert(blockMessage);
	}
}

// ====================================================================================
// 画像のhover設定
$(function() {
	function initRollovers() {
		if (!document.getElementById) { return; }
		var aPreLoad = new Array();
		var sTempSrc;
		var aImages = new Array();
		var imgs = document.getElementsByTagName('img');
		var inputs = document.getElementsByTagName('input');
		for (var i=0; i<imgs.length; i++) {
			aImages.push(imgs[i]);
		}
		for (var i=0; i<inputs.length; i++) {
			aImages.push(inputs[i]);
		}
		for (var i = 0; i < aImages.length; i++) {		
			if (aImages[i].className == 'hover') {
				if (aImages[i].parentNode.nodeName == "A" || aImages[i].type == "image") {
					var src = aImages[i].getAttribute('src');
					var ftype = src.substring(src.lastIndexOf('.'), src.length);
					var hsrc = src.replace(ftype, '_on'+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('_on'+ftype, ftype) };
						this.setAttribute('src', sTempSrc);
					};
				}
			}
		}
	}
	initRollovers();
});

