//********************************************************************* モーダルウィンドウ
jQuery.fn.extend({
	modalWindow: function(options){
		conf = jQuery.extend({
			fixed : false,
			color : '#fff',
			bgLayer : '#000'
		}, options);
		var ie6  = (typeof document.body.style.maxHeight == 'undefined') ? 1 : 0;
		var modalLayer = $('<div id="modalLayer"></div>');
		var modalTable = $('<table id="modalTable"><tr><td><div id="modalWrap"></div></td></tr></table>');
		var modalIframe= $('<iframe id="modalIframe"></iframe>');
		var body = $('body');
		var H    = body.height();
		var modalClose = $('<button id="modalClose" class="btn_dsn">閉じる</button>');
		
		this.css({
			'background-color':'#fff',
			'border':'10px #fff solid'
		});
		body.append(modalLayer).append(modalIframe).append(modalTable).append(modalClose);
		$('#modalWrap').html(this).css('position','relative');
		
		modalLayer
		.css({
			'position':'absolute',
			'top'     :'0',
			'left'    :'0',
			'width' : '100%',
			'height': H + 'px',
			'background-color':conf.bgLayer,
			'opacity':'0.50',
			'z-index':'5001'
		});
		modalIframe
		.css({
			'position':'absolute',
			'top'     :'0',
			'left'    :'0',
			'width' : '100%',
			'height': H + 'px',
			'background-color':conf.bgLayer,
			'border':'0px',
			'opacity':'0',
			'z-index':'5000'
		});
		modalTable
		.css({
			'position':'absolute',
			'top'  :'50px',
			'left' :'50%',
			'margin-top' : 0,
			'margin-left': -(modalTable.width()/2),
			'width':'auto',
			'height':'auto',
			'z-index':'5002'
		});
		$('#modalWrap',modalTable).prepend(modalClose);
		if (!conf.fixed) {
			$('html,body').animate({ scrollTop: 0 }, 300);
		}
		modalClose
		.css({
			'position':'absolute',
			'top' : '0',
			'right': '0',
			'margin' : '10px 10px 0 0',
			'width':'70px',
			'height':'22px',
			'text-align':'center',
			'cursor' :'pointer',
			'z-index':'9999',
			'background':'url(/image/btn.bg.png) no-repeat -250px -100px'
		})
		.hover(
			function(){ $(this).css({ 'background':'url(/image/btn.bg.png) no-repeat -250px -150px' }) },
			function(){ $(this).css({ 'background':'url(/image/btn.bg.png) no-repeat -250px -100px' }) }
		)
		.click(function(){
			modalLayer.remove();
			modalIframe.remove();
			modalTable.remove();
			modalClose.remove();
		});
		modalLayer.click(function(){
			modalLayer.remove();
			modalIframe.remove();
			modalTable.remove();
			modalClose.remove();
		});
	}
});

