// サイト初期設定

$(function() {
	init_func();
	
	$.ajaxSetup({ cache: false });
	
	$('#btn_info_past').click(function() {
		$('#content').load(
			'http://' + location.hostname + '/schedule/info/infoside/?row=100',
			null,
			function () { init_func(); }
		);
	});

});

function init_func() {
	var wpimg_width = null;
	var wpimg_count = $('.wp-caption').size();
	if (wpimg_count > 0) {
		if (wpimg_count > 1) {
			if (wpimg_count % 3 != 1) {
				wpimg_width = 125;
				//$('.wp-caption img').css('width', '125px');
			} else {
				$('.wp-caption').css('font-size', '9px');
				$('.wp-caption').css('margin', '5px');
				$('.wp-caption').css('width', '125px');
				wpimg_width = 100;
			}
		}

		$('.wp-caption img').each(function(){
			if (wpimg_width != null) {
				$(this).attr('height', wpimg_width / $(this).attr('width') * $(this).attr('height'));
				$(this).attr('width', wpimg_width);
			}
			var imgwrap = '<a href="' + $(this).attr('src') + '" class="lightpop"></a>'
			$(this).wrap(imgwrap);
		});

		var max_height = 0;
		$('.wp-caption').each(function(){
			if (max_height < $(this).attr('height')) {
				max_height = $(this).attr('height');
			}
		});
		if (max_height != null) {
			$('div.wp-caption').attr('height', max_height);
		}
	}

	$('a.lightpop').lightpop({overlayBgColor:'#000', contentFrameType:'box'}, {}, '', '/images/lightpop/');
	$('a[href*="http:"]').each (function () {
		if ($(this).attr('href').indexOf(location.hostname) == -1) {
			$(this).addClass('blank');
		}
	});
	$('a.blank').click(function(){ this.target = "_blank"; });
}


