// ipop.js ポップアップウインドウ
//
// 使い方：
// <div id="ipop">
//   <div id="ipop_title">タイトル</div>
//   <div id="ipop_close">閉じるボタン</span>
//   中身
// </div>
//
// 上記のようなHTMLを作り、$.ipop() で呼び出す。

(function($) {
	$.ipop3 = function() {
		var wx, wy;		// ウインドウの左上座標
		var mx, my;		// マウスの座標

		// ウインドウの座標を画面中央にする。
		wx = $().scrollLeft() + ($(window).width() - $('#ipop3').outerWidth()) / 2+60-40;
		if (wx < 0) wx = 0;
		//wy = $().scrollTop() + ($(window).height() - $('#ipop3').outerHeight()) / 2+150;
		wy =420;
		if (wy < 0) wy = 0;

		// ポップアップウインドウを表示する。
		$('#ipop3').css('top', wy).css('left', wx).css("z-index","9999").fadeIn(100);
		$('#ipop').css("z-index","8000");
		//$('#ipop2').css("z-index","8000");
		
		$('#ipop3').click(function() {
		$('#ipop3').css("z-index","9999");
		$('#ipop').css("z-index","8000");
		$('#ipop2').css("z-index","8000");
		});

		// 閉じるボタンを押したとき
		$('#ipop3_close').click(function() {$('#ipop3').fadeOut(100);});

		// タイトルバーをドラッグしたとき
		$('#ipop3_title').mousedown(function(e) {
			mx = e.pageX;
			my = e.pageY;
			$().mousemove(mouseMove).mouseup(mouseUp);
			return false;
		});
		function mouseMove(e) {
			wx += e.pageX - mx;
			wy += e.pageY - my;
			$('#ipop3').css('top', wy).css('left', wx);
			mx = e.pageX;
			my = e.pageY;
			return false;
		}
		function mouseUp() {
			$().unbind('mousemove', mouseMove).unbind('mouseup', mouseUp);
		}
	}
})(jQuery);


