var explain = {
	Crawl : function() {
		jQuery('.explain').each(function(i, obj) {
			jQuery(obj).click(function() {
				jQuery.get('/public/explain/'+jQuery(obj).attr('rel')+'.html', function(data) {
					var dat = jQuery('<div/>')
						.css('width', jQuery(window).width() * 0.75)
						.css('background-color', '#fff')
						.css('padding', '1px')
						.append(data)
					;
					explain.Overlay(dat);
				});
			});
		});
	},
	
	Overlay : function(obj) {
		// 背景オーバーレイ用
		var overlay = jQuery('<div/>')
			.attr('id', 'overlay')
			.attr('style', 'background-color:#fff;position:absolute;top:0;left:0;display:block;z-index:1;')
			.width(jQuery('body').width())
			.height(jQuery('body').height())
			.css('opacity', 0)
			.appendTo(jQuery('body'))
		;
		// 下地表示
		var back = jQuery('<div/>')
			.attr('id', 'base')
			//.width(jQuery('body').width() * 0.75)
			//.height(jQuery(window).height() * 0.75)
			//.height(240)
			.css('position', 'absolute')
//			.css('left', (jQuery('body').width() * 0.125)+'px')
			.css('left', (jQuery(window).width() * 0.125)+'px')
			.css('top', (jQuery(window).height() * 0.125) + 'px')
			.css('background-color', '#333')
			.css('padding', '3px')
			.css('-moz-border-radius', '5px')
			.css('opacity', '0')
			.css('z-index', '2')
			.append(jQuery('<div/>')
				.attr('id', 'explain_desc')
				.append(obj)
			)
			.append(jQuery('<p/>')
				.css('text-align', 'center')
				.append(jQuery('<input/>')
					.attr('type', 'button')
					.attr('value', '閉じる')
					.click(function() {
						explain.CloseOverlay();
					})
				)
			)
			.appendTo(jQuery('body'))
		;
		if (jQuery(back).height() > jQuery(window).height()) {
			jQuery('#explain_desc')
				.height(jQuery(window).height() * 0.8)
				.css('overflow', 'scroll')
			;
		}
		back.css('top', (jQuery(window).height() / 2) - (back.height() / 2) + jQuery(window).scrollTop() + 'px');
		jQuery('#overlay').fadeTo(250, 0.75, function() {
			jQuery('#base').fadeTo(250, 1);
		});
	},
	
	CloseOverlay : function() {
		jQuery('#base')
			.fadeTo(250, 0, function() {
				jQuery('#overlay')
					.fadeTo(250, 0, function() {
						jQuery('#overlay').remove();
					});
				jQuery('#base').remove();
			});
		;
	}
};

jQuery(document).ready(function() {
	explain.Crawl();
});


