
$(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."]').hover(
		function () {
			$(this).css('opacity', 0.7);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);



	// pull down

	$("#gNavi div:last").addClass("last");
	$("#gNavi div").each(function(){
		var a = $(this).prev();
		$(this).parent().addClass("pulldown");
		if($("img", a).attr("src").match("_off")) {
			a.addClass("pulldown");
			$("img", a).unbind('mouseout');
		}
	}).addClass("pulldown");

	$("#gNavi > li.pulldown").hover(
		function(e){
			if ($("div.pulldown", this).queue().length<=1) {
				if($.browser.msie){
					$("div.pulldown", this).show();
				}else {
					$("div.pulldown", this).animate({height:'show', opacity:'show'}, 300).css("z-index", 30);
				}
				$("a.pulldown img", this).attr("src", $("a.pulldown img", this).attr("src").replace("_off.", "_on."));
			}
		},
		function(e){
			if($.browser.msie){
				$("div.pulldown", this).hide();
			}else {
				$("div.pulldown", this).animate({height:'hide', opacity:'hide'}, 300).css("z-index", 10);
			}
			$("a.pulldown img", this).attr("src", $("a.pulldown img", this).attr("src").replace("_on.", "_off."));
		}
	);


	// pngfix

	if($.browser.msie && $.browser.version < 7) DD_belatedPNG.fix('#gNavi div, #gNavi div ul, #gNavi div dl');




	// external

	var notBlank = new Array("keisen-chouri.com");

	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");


	$("a[href^='/form/'], a[href^='http://www.keisen-chouri.com/form/']").attr("target", "_blank");

	// smoothScroll

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

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");
		})
}

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


function showMovie(){
	Mediabox.open('/movie/keisen_movie.flv', 'keisen movie', '720 480');
}
function showDM(){
	Mediabox.open('/taiken/dm/', '体験入学DM', '1100 1650');
}
function showJT(){
	Mediabox.open('/facilities/jt/', '製菓・製パン科の新実習棟が完成！', '800 1130');
}

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 == "new"){
		title = "what's new keisen";
	}else if(category == "event"){
		title = "キャンパスイベント";
	}else if(category == "taiken"){
		title = "オープンキャンパス予告＆レポート";
	}else if(category == "practice"){
		title = "実習レポート";
	}
	var cat = category ? category + '/' : '';
	Mediabox.open('/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)*/
}

