// JavaScript Document
jQuery.fn.extend({

popupDisplay: function(target){
	$(target).hide();
	$(this).click(function() {
		$(target).slideDown("slow");
		return false;
	});
	$(target).click(function() {
		$(target).slideUp(100);	
		return false;
	});
},

_popupDisplay: function(target){
	//初期設定
	var overlay="#popupHelp_OL";
	var inner  =target;

	if($(overlay).html()==null){
		$("body").prepend('<div id="popupHelp_OL"></div>');
	}

	$(overlay).css({
		position: 'absolute',
		top: 0,
		left: 0,
		zIndex : 20000,
		width: '100%'
	});
	$(inner).css({
		position: 'absolute',
		top: 0,
		left: 0,
		zIndex: 20001
	});
	
	$(overlay).hide();
	$(inner).hide();

	//クリッカブル設定
	$(this).css({cursor:"pointer"});
	$(this).hover(
	function(){
		$(this).addClass("hover");
	},
	function(){
		$(this).removeClass("hover");
	});

	$(this).click(function() {
		$(overlay).popupSets(inner);
	});
},

popupSets:function(inner){

	var ovl=$(this);
	var inn=$(inner);

	var arrPageSizes = getPageSize();
	ovl.css({display: 'block'});
	ovl.css({
		backgroundColor: '#000',
		opacity	:	0.5,
		width	:	arrPageSizes[0],
		height	:	arrPageSizes[1]
	}).show();

	var arrPageScroll = getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it

	var inn_h=inn.height()/2;
	var inn_w=inn.width()/2;

	inn.css({
		top: arrPageScroll[1] + (arrPageSizes[3] / 2)-inn_h,
		left: arrPageScroll[0] + (arrPageSizes[2] / 2)-inn_w
	}).slideDown("slow");


	ovl.click(function() {
		//閉じる
		closeWindow();
	});

	//閉じるボタンの設定
	$(inn).css({cursor:"pointer"});
	$(inn).click(function() {
		closeWindow();         
	});


	$(window).resize(function() {
		// Get page sizes
		var arrPageSizes = getPageSize();
		// Style overlay and show it
		ovl.css({
			width: arrPageSizes[0],
			height: arrPageSizes[1]
		});
		// Get page scroll
		var arrPageScroll = getPageScroll();
		// Calculate top and left offset for the jquery-lightbox div object and show it
		inn.css({
			top: arrPageScroll[1] + (arrPageSizes[3] / 2)-inn_h,
			left: arrPageScroll[0] + (arrPageSizes[2] / 2)-inn_w
		});
	});

	function getPageSize(){
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) { 
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
	
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		if(xScroll < windowWidth){ 
			pageWidth = xScroll;  
		} else {
			pageWidth = windowWidth;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	}

	function getPageScroll(){
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {  // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft; 
		}
		arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	}
	
	function closeWindow() {
		ovl.hide();
		inn.slideUp(100);
		// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
		$('embed, object, select').css({ 'visibility' : 'visible' });
	}
}
});
