$(function() {
	//smartRollover

	var imgCount = 0;
	var images_pre = new Array();
	$('img[src*="_off."],input[src*="_off."]').each (function(){
		images_pre[imgCount] = new Image();
		images_pre[imgCount].src = $(this).attr("src").replace("_off.", "_on.");
		$(this).hover(
			function () {
				$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
			},
			function () {
				$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
			}
		);
		imgCount ++;
	});



	// opacity Rollover

	$('img[src*="_op."],input[src*="_op."],#bottomBnr a img').hover(
		function () {
			$(this).css('opacity', 0.7);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);



	// external

	var notBlank = new Array("");

	var n = "";
	for (var i = 0; i < notBlank.length; i ++) if(notBlank[i]) n += ":not([href*='" + notBlank[i] + "'])";
	if(document.domain) n += ":not([href*='" + document.domain + "'])";

	$("a[rel='external'], a[href$='.pdf']").attr("target", "_blank");
	$("a[href^=http]"+n).attr("target", "_blank");


	// smoothScroll

	$('a[href^="#"], a[href^="' + location.pathname + '#"]').each (function(){
		var hash = this.hash;
		if(hash.length > 1 && !this['rel']){
			$(this).click(function() {
				smoothScroll(hash);
				return false;
			})
		}
	});



	// bbs
	$("a[rel='bbs']").click( function(e){
		e.preventDefault();
		var wo = window.open($(this).attr("href"), "pop", "width=700, height=600, scrollbars=1, menubar=1, resizable=1, menubar=1");
	});



	// add last
	$(".has_last > *:last-child").addClass("last");

	// stripe
	$("table.stripe tr:nth-child(even)").addClass("even");
	$("table.stripe tr:nth-child(odd)").addClass("odd");

	// opera only
	if($.browser.opera) {
		$("body").css("padding-left", 1)
	}
});

function smoothScroll(hash) {
	var target = $(hash).offset().top;

	$(($.browser.safari) ? 'body' : 'html')
		.animate({scrollTop: target >= 15 ? target - 15 : target}, 600, 'swing', function(){$(this).unbind("mousewheel DOMMouseScroll");})
		.bind("mousewheel DOMMouseScroll",function(){
			$(this).queue([]).stop();
			$(this).unbind("mousewheel DOMMouseScroll");
		})
}

if($.browser.msie && $.browser.version < 7) DD_belatedPNG.fix('#footer li img, .png');


function boxFit(w, b, ib, c, d) {
	var prop = $.browser.msie && $.browser.version < 7 ? "height" : "min-height";

	var l = Math.ceil($(w + " > " + b).size()/c);

	for(var i = 0; i < l; i ++) {
		var id = "Wrap" + d + "-" + i;
		$(w).append('<div id="' + id + '" class="clearfix">');

		var h = 0;
		var ih = 0;
		$(w + " > " + b).each( function(j){
			h = Math.max($(this).height(), h);
			if(ib != "") ih = Math.max($(ib, this).height(), ih);
			if(j == c - 1) {
				$(this).addClass("right");
			}

			$(this).appendTo("#" + id);

			if(j >= c - 1 || $(w + " > " + b).size() < 1) {
				$(b, "#" + id).css(prop, h);
				if(ib != "") $(ib, "#" + id).css(prop, ih);
				return false;
			}
		});
	}
}

var path = location.pathname;
var dir = path.split("/");
dir.shift();

var rootdir = "";
if(dir[0] == "test" || dir[0] == "sample") {
	rootdir = "/" + dir[0];
}

document.write('<link rel="stylesheet" href="' + rootdir + '/common/js/mediaboxAdvWhite.css" type="text/css" media="all" />');
document.write('<script type="text/javascript" src="' + rootdir + '/common/js/mootools-1.2.4-core-yc.js"></script>');
document.write('<script type="text/javascript" src="' + rootdir + '/common/js/mediaboxAdv-1.2.4.js"></script>');

var cal_load_flg = true;
function showCalendar(y, m, category){
	cal_load_flg = true;
	var year = y;
	var mon = m;
	if(!year || !mon) {
		var date = new Date();
		year = date.getFullYear();
		mon = date.getMonth() + 1;
		mon = String(mon);
		if(mon.length < 2) mon = "0" + mon;
	}
	var title;
	if(!category) {
		title = "keisen calendar";
	}else if(category == "information"){
		title = "学校からのお知らせ";
	}else if(category == "blog"){
		title = "キャンパスライフブログ";
	}else if(category == "student"){
		title = "在校生ブログ";
	}else if(category == "join"){
		title = "体験入学に参加した高校生のブログ";
	}
	var cat = category ? category + '/' : '';
	Mediabox.open(rootdir + '/calendar/' + year + '/' + mon + '/' + cat, title, '730 520');
}

function setHeight(h) {
	var target = 520;
	if(h > 490) {
		target = h + 30;
	}
/*	$("#mbImage, #mbImage iframe").animate({ 
			height: target
		}, 500);*/
	$("#mbImage iframe").css("height", target);
	$("#mbCenter").animate({ 
			height: target + 50
		}, 300);
/*	$("#mbCenter").height(target + 50)*/
}


/* お問い合わせフォームの送信 
------------------------------------------------------------ */

function sendform(md){
	if(document.getElementById){
		fm = document.getElementById('docform');
	}else{
		fm = document.all('docform');
	}
	mo = document.createElement("input");
	mo.type = "hidden";
	mo.name="mode";
	mo.value=md;
	fm.appendChild(mo);
	fm.submit();
}

function focusObj(){

}
function outFocusObj(){

}
function blurObj(){

}
function blurNumObj(){

}
function isEmail(){

}

