$(function(){
	$.nyroModalSettings({
		closeButton: '',
		padding: 40,
		endFillContent:function(modal, settings) {
			var gallery = $('[rel="'+ settings.from.rel +'"]');
			var currentIndex = gallery.index(settings.from);
			if(currentIndex - 1 < 0) {
				$("#nyroModalContent .btn_previous a").css("visibility", "hidden");
			} else {
				$("#nyroModalContent .btn_previous a").css("visibility", "visible").click(function(e) {
					e.preventDefault();
					var index = currentIndex - 1;
					if (index >= 0 && index < gallery.length) {
						gallery.eq(index).nyroModalManual();
					}
					return false;
				});
			}
			if(currentIndex + 1 >= gallery.length) {
				$("#nyroModalContent .btn_next a").css("visibility", "hidden");
			} else {
				$("#nyroModalContent .btn_next a").css("visibility", "visible").click(function(e) {
					e.preventDefault();
					var index = currentIndex + 1;
					if (index >= 0 && index < gallery.length) {
						gallery.eq(index).nyroModalManual();
					}
					return false;
				});
			}
			$("#nyroModalContent").after("<p class='js_message nyroModalClose'>閉じるボタン、もしくはグレー背景をクリックすると一覧画面に戻ります。</p>");
			var index = currentIndex + 1;
			index = (index < 10)? "0" + index : index;
			var modal_num = gallery.size();
			modal_num = (modal_num < 10)? "0" + modal_num : modal_num;
			$("#nyroModalContent .modal_index").text("[ " + index + " / " + modal_num + " ]");
		},
		showBackground: function(elts, settings, callback) {
			elts.bg.css({opacity:0}).fadeTo(500, 0.75, callback);
			IE6fix();
		}
	});
	function IE6fix() {
		if ($.browser.msie && $.browser.version.split('.')[0] < 7) {
			$("body").css({
				width: 'auto'
			});
			$('html').css({overflow: 'hidden'});
			$("#nyroModalBg, #nyroModalIframeHideIe").css({
				position: 'absolute',
				top: '0px',
				left:'0px',
				width: '100%',
				height: '100%'
			});
		}
	}
});
