/** 表示中の画像 */
var current_image = null;
/** 表示中プロフィール */
var current_profile = null;

var profile_width = 0;
var profile_height = 0;

/**
 *	プロフィール表示
 */
function show_profile( img, profileid ) {
	var profile = document.getElementById( profileid )

	if( profile ) {
		hide_profile();

		current_image = img;
		current_profile = profile;

		current_profile.style.display = "block";

		//非表示イベント設定
		current_image.onmouseout = function(e) { chk_hide_profile(e); };
		current_profile.onmouseout = function(e) { chk_hide_profile(e); };

		if( document.location.pathname.match( /member/ ) ) {
			profile_width = 205;
			profile_height = 190;
		}
		else if( document.location.pathname.match( /qa/ ) ) {
			profile_width = 235;
			profile_height = 205;
		}
	}
}

/**
 *	プロフィール表示
 */
function qa_show_profile( img, profileid, idx ) {
	var profile;
	var oElements = document.getElementsByName(profileid);
    profile = oElements[idx];

	var image;
	var oElements2 = document.getElementsByName(img);
    image = oElements2[idx];

	if( profile ) {
		hide_profile();

		current_image = image;
		current_profile = profile;
		current_profile.style.display = "block";

		//非表示イベント設定
		current_image.onmouseout = function(e) { chk_hide_profile(e); };
		current_profile.onmouseout = function(e) { chk_hide_profile(e); };
		if( document.location.pathname.match( /member/ ) ) {
			profile_width = 205;
			profile_height = 190;
		}
		else if( document.location.pathname.match( /qa/ ) ) {
			profile_width = 235;
			profile_height = 205;
		}
	}
}

/**
 *	プロフィール表示
 */
function show_profile_byname( img, name, index) {
	var profiles = document.getElementsByName( name );
	var profile = profiles[index];
	
	if( profile ) {
		hide_profile();

		current_image = img;
		current_profile = profile;

		current_profile.style.display = "block";

		//非表示イベント設定
		current_image.onmouseout = function(e) { chk_hide_profile(e); };
		current_profile.onmouseout = function(e) { chk_hide_profile(e); };

		if( document.location.pathname.match( /member/ ) ) {
			profile_width = 205;
			profile_height = 190;
		}
		else if( document.location.pathname.match( /qa/ ) ) {
			profile_width = 235;
			profile_height = 205;
		}
	}
}

/**
 *	マウス位置チェック
 */
function chk_hide_profile( e ) {
	if( current_profile && current_image ) {
		var x = 0;
		var y = 0;

		if( window.event ) {
			x = window.event.clientX + getScrollLeft();
			y = window.event.clientY + getScrollTop();
		}
		else if( e ) {
			x = e.pageX;
			y = e.pageY;
		}

		if( !navigator.userAgent.match( /MSIE 7/ ) ) {
			pathname = document.location.pathname;
			if( pathname.match( /\/qa\// ) ) {
				y += 0;
			}
			if( pathname.match( /\/member\// ) ) {
				y += 35;
			}
		}

		//プロフィール領域
		var box_top = getOffsetTop( current_profile );
		var box_left = getOffsetLeft( current_profile );
		//var box_bottom = box_top + current_profile.offsetHeight;
		//var box_right = box_left + current_profile.offsetWidth;
		var box_bottom = box_top + profile_height;
		var box_right = box_left + profile_width;

		//box_top += 2;
		box_left += 2;
		box_bottom -= 2;
		box_right -= 2;

		//画像部分領域
		var box_top2 = getOffsetTop( current_image );
		var box_left2 = getOffsetLeft( current_image );
		var box_bottom2 = box_top2 + current_image.offsetHeight;
		var box_right2 = box_left2 + current_image.offsetWidth;

		box_top2 += 2;
		box_left2 += 2;
		//box_bottom2 -= 2;
		box_right2 -= 2;

		//alert( "img----\ntop:" + box_top2 + "\nleft:" + box_left2 + "\nbottom:" + box_bottom2 + "\nright:" + box_right2 + "\n\nx:" + x + "\ny:" + y );
		//alert( "prof----\ntop:" + box_top + "\nleft:" + box_left + "\nbottom:" + box_bottom + "\nright:" + box_right + "\n\nx:" + x + "\ny:" + y );
		if( ( y < box_top || box_bottom < y || x < box_left || box_right < x ) && ( y < box_top2 || box_bottom2 < y || x < box_left2 || box_right2 < x ) ) {
			hide_profile();
		}
	}
}

/**
 *	プロフィール非表示
 */
function hide_profile() {
	if( current_profile ) {
		current_profile.style.display = "none";

		current_profile.onmouseout = null;
		current_profile = null;
	}
	if( current_image ) {
		current_image.onmouseout = null;
		current_image = null;
	}
}

