// JavaScript Document
(function(){
  var params = new Array('http://morinomiya-u.gdd.jp/?guid=on', '携帯サイトを表示しますか？');
  if ((document.referrer.indexOf(location.hostname) == -1) && navigator.userAgent.match(/iPhone|iPad|iPod|Android/i) && confirm(params[1])) location.href = params[0];		
})();

/*------------------------------------
	init
------------------------------------*/
function init()
{
  scrollTop();
  include_Tmp();
}



/*------------------------------------
	FontSize
------------------------------------*/
var fs_arry ={ s: "77%", m: "93%",	b: "123.1%"};

/*- Set FontSize CSS ---------------*/
function setFontsize()
{
	var src,replace_src,cookie,nm;
	
	cookie = getCookie("fs");
	//console.log(cookie);
	
	if(cookie != null)
	{
		$("#box").css("font-size",fs_arry[cookie]);
		if(cookie== "b") nm = 0;
		if(cookie== "m") nm = 1;
	}else {
		$("#box").css("font-size",fs_arry["m"]);
		nm=1;
	}
	
	src =$("#fontsize dd:eq(" +nm+ ")").find("img").attr("src");
	replace_src = srcReplace(src,"_on");
	$("#fontsize dd:eq(" +nm+ ")").find("img")
			.attr({src:replace_src}).end().addClass("current_fs");
}

/*- Set FontSize Cookie ------------ */
function setFsCookie()
{
	var value,num,src,replace_src;
	
	$("#fontsize dd").click(function()
		{
			num = $("#fontsize dd").index(this);
			
			if(num== 0) value = "b";
			if(num== 1) value = "m";

			setCookie("fs", value);
			$("#box").css("font-size",fs_arry[value]);
			
			if($(".current_fs").size() > 0)
			{
				src = $(".current_fs").find("img").attr("src");
				replace_src = srcReplace(src,"_on");
				$(".current_fs").find("img").attr({src:replace_src}).end().removeClass("current_fs");
			}

			src = $(this).find("img").attr("src");
			replace_src = srcReplace(src,"_on");
			$(this).find("img").attr({src:replace_src}).end().addClass("current_fs");
	});
}

/*- Get Cookie ---------------------*/
function getCookie(str)
{
	var cookie = $.cookie(str);	
	return cookie;
}

/*- Set Cookie ---------------------*/
function setCookie(str,value)
{
	$.cookie(str, value, {expires: 31, path: '/'});
}

/*------------------------------------
	RollOver
------------------------------------*/
function rollOverAlpha(){
	$("a img").hover(
		function(){
			$(this).stop().animate({"opacity":0.4},"slow");
		},
		function(){
			$(this).stop().animate({"opacity":1},"slow");
	}).click(function(){ $(this).stop().css('opacity',1);});
}



/*------------------------------------
	SRC Reolace
------------------------------------*/
function srcReplace(src, prefix)
{
	var ftype = src.substring(src.lastIndexOf('.'), src.length);
	
	if(src.search(prefix) == -1){
		src = src.replace(ftype, prefix+ftype);
	}else {
		src = src.replace(prefix+ftype, ftype);
	}
	
	return src;
}



/*------------------------------------
	POPUP WINDOW
------------------------------------*/
function popup(url,wnm,pram)
{
	w = window.open(url, wnm, pram);
	w.focus();
}



/*------------------------------------
	Scroll Top
------------------------------------*/
function scrollTop()
{
	$(".pagetop").click(function(){
		$('html,body').stop().animate({ scrollTop: 0 }, 'slow');
		return false;
	});
}



/*------------------------------------
	INCLUDE 
------------------------------------*/
function include_Tmp()
{
	var _id,_include
	_id = $('body').attr('id');
	
	if( _id == 'student' )     { _include = 'side_targetStudents.html'; }
	if( _id == 'guardian' )    { _include = 'side_targetGuardian.html'; }
	if( _id == 'examinee' )    { _include = 'side_targetExaminee.html'; }
	if( _id == 'graduate' )    { _include = 'side_targetGraduate.html'; }
	if( _id == 'research' )    { _include = 'side_Research.html'; }
	if( _id == 'institution' ) { _include = 'side_Institution.html'; }
	if( _id == 'publication' ) { _include = 'side_Publication.html'; }
	if( _id == 'guide' )       { _include = 'side_Guide.html'; }
	if( _id == 'campus' )      { _include = 'side_Campus.html'; }
	if( _id == 'entrance' )    { _include = 'side_Entrance.html'; }
	if( _id == 'work' )        { _include = 'side_Work.html'; }
	if( _id == 'shinkyu' )     { _include = 'side_facultyShinkyu.html'; }
	if( _id == 'rigaku' )      { _include = 'side_facultyRigaku.html'; }
	if( _id == 'kango' )       { _include = 'side_facultyKango.html'; }
	if( _id == 'daigakuin' )     { _include = 'side_facultyDaigakuin.html'; }
	
	if( typeof _include != undefined) {
		$('#side_inc').load('/inc/' +_include);
	}
	$('#side_bnrs').load('/inc/side_bnrs.html');
	$('#sidemap').load('/inc/sidemap.html',
	  function(){
		if( _id=='daigakuin') {
			$('#sidemap').find('.daigakuin').remove();
		}else if( _id !== "faculty") {
			$('#sidemap').find('.' +_id).remove().end().find('.daigakuin').remove();
		}
	});
	$('#footer').load('/inc/footer.html');
	$('#header').load('/inc/header.html',
	  function(){
		setFontsize();
		setFsCookie();
		rollOverAlpha();
	});
	
}



/*------------------------------------
	onLoad
------------------------------------*/

if(window.addEventListener){  
	window.addEventListener("load", init, false);  
}  
else if(window.attachEvent){  
	window.attachEvent("onload", init);  
}



