﻿
//画像プリロード
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}




$(function() {

	// load dorpdown menu
	var srcDomain = '';

	$('<div style="display:none">').appendTo('body').load('dropdown.html #dropdown', null, function() {
		var dropdown = $('#dropdown');
		var menuId;
		for (var i = 1; i <= 7; i++) {
			menuId = '.menu' + i;
			$(menuId + 'place').replaceWith($(menuId, dropdown));
		}

		/* hover でメニュー表示 */
		$('#topnav li').hover(function() {
			btnHover($('img:not(.noover)', this).get(0));
			$(this).find('.sub').show();
		}, function() {
			btnHoverOut($('img:not(.noover)', this).get(0));
			$(this).find('.sub').hide();
		});

		// リンクがクリックされたらドロップダウンを閉じておく
		$('#topnav li a').click(function() {
			var parent = $('#topnav li').has(this);

			btnHoverOut($('img:not(.noover)', parent).get(0));
			parent.find('.sub').hide();
		});

	});

	initRollover('#contactbtn a img, .imgover');

	// global menu の preload
	$('#topnav li img').each(function() {
		btnHover($('<img>').attr('src', this.src).get(0));
	});


});


// rollover

function initRollover(target) {
	var postfix = 'r';
	jQuery(target).not('[src*="'+ postfix +'."]').each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		           + postfix
		           + src.substring(src.lastIndexOf('.'));
		jQuery('<img>').attr('src', src_on);
		img.hover(function() {
			img.attr('src', src_on);
		}, function() {
			img.attr('src', src);
		});
	});
}


function btnHover(node) {
	if (node) {
		node.src = node.src.replace(/^(.*)\.(gif|jpg|png)$/gi, '$1r.$2');
	}
}

function btnHoverOut(node) {
	if (node) {
		node.src = node.src.replace(/^(.*)r\.(gif|jpg|png)$/gi, '$1.$2');
	}
}


//部表示
	function ShowBuLink() {
		var maxNum = 37;
		//ファイル名の配列作成
		var imageListAll = new Array();
		var imageRListAll = new Array();
		for(i = 1; i <= maxNum;i++) {
			var flName = "/images/bu/bu";
			if(i < 10) {
				flName += "0";
			}
			imageListAll.push(flName + i + ".gif");
			imageRListAll.push(flName + i + "r.gif");
		}
		//リンク名称の配列作成
		var nameListAll = new Array();
		for(i = 1; i <= maxNum;i++) {
			var txt = "部";
			if(i < 10) {
				txt += "0";
			}
			txt += i;
			nameListAll.push(txt);
		}
		//URLの配列作成
		var urlListAll = new Array();
		urlListAll.push("http://a-jitsu.net/blog/?cat=9");
		urlListAll.push("http://a-jitsu.net/blog/?cat=8");
		urlListAll.push("http://a-jitsu.net/blog/?cat=10");
		urlListAll.push("http://a-jitsu.net/blog/?cat=11");
		urlListAll.push("http://a-jitsu.net/blog/?cat=12");
		urlListAll.push("http://a-jitsu.net/blog/?cat=13");
		urlListAll.push("http://a-jitsu.net/blog/?cat=14");
		urlListAll.push("http://a-jitsu.net/blog/?cat=15");
		urlListAll.push("http://a-jitsu.net/blog/?cat=16");
		urlListAll.push("http://a-jitsu.net/blog/?cat=17");
		urlListAll.push("http://a-jitsu.net/blog/?cat=18");
		urlListAll.push("http://a-jitsu.net/blog/?cat=19");
		urlListAll.push("http://a-jitsu.net/blog/?cat=20");
		urlListAll.push("http://a-jitsu.net/blog/?cat=21");
		urlListAll.push("http://a-jitsu.net/blog/?cat=22");
		urlListAll.push("http://a-jitsu.net/blog/?cat=23");
		urlListAll.push("http://a-jitsu.net/blog/?cat=24");
		urlListAll.push("http://a-jitsu.net/blog/?cat=25");
		urlListAll.push("http://a-jitsu.net/blog/?cat=26");
		urlListAll.push("http://a-jitsu.net/blog/?cat=27");
		urlListAll.push("http://a-jitsu.net/blog/?cat=28");
		urlListAll.push("http://a-jitsu.net/blog/?cat=29");
		urlListAll.push("http://a-jitsu.net/blog/?cat=30");
		urlListAll.push("http://a-jitsu.net/blog/?cat=31");
		urlListAll.push("http://a-jitsu.net/blog/?cat=32");
		urlListAll.push("http://a-jitsu.net/blog/?cat=33");
		urlListAll.push("http://a-jitsu.net/blog/?cat=34");
		urlListAll.push("http://a-jitsu.net/blog/?cat=42");
		urlListAll.push("http://a-jitsu.net/blog/?cat=35");
		urlListAll.push("http://a-jitsu.net/blog/?cat=43");
		urlListAll.push("http://a-jitsu.net/blog/?cat=44");
		urlListAll.push("http://a-jitsu.net/blog/?cat=36");
		urlListAll.push("http://a-jitsu.net/blog/?cat=37");
		urlListAll.push("http://a-jitsu.net/blog/?cat=38");
		urlListAll.push("http://a-jitsu.net/blog/?cat=40");
		urlListAll.push("http://a-jitsu.net/blog/?cat=41");
		urlListAll.push("http://a-jitsu.net/blog/?cat=46");
		//インデックスの配列作成
		var idxListAll = new Array();
		for(i = 0; i <= imageListAll.length - 1; i++) {
			//以下部活動は固定なのでこのリストには入れない。
			//野球、サッカー、女子バレー、バトミントン
			if((i != 1)&&(i != 0)&&(i != 8)&&(i != 5)) {
				idxListAll.push(i);
			}
//			if((idxListAll[i] != 1)&&(idxListAll[i] != 0)&&(idxListAll[i] != 8)&&(idxListAll[i] != 5)) {
//				idxListAll.push(i);
//			}
		}
		//10件選ぶ
		var idxList = new Array();
		//以下部活動は固定なので先にリストに入れる
		//野球、サッカー、女子バレー、バトミントン
		idxList.push(1);
		idxList.push(0);
		idxList.push(8);
		idxList.push(5);
		//残り6件を選ぶ
		for(i = 1; i <= 6; i++) {
			var idx = Math.floor(Math.random() * idxListAll.length);
			//固定表示している部活の重複回避
//			while (idx == 1 || idx == 0 || idx == 8 || idx == 5) {
//				var idx = Math.floor(Math.random() * idxListAll.length);
//			}
			idxList.push(idxListAll[idx]);
			idxListAll.splice(idx, 1);
		}
		//選んだ10件を表示
		var area = document.getElementById("areaBu");
		if(area != null) {
			for(i = 0; i <= idxList.length - 1; i++) {
				var link = document.createElement("a");
				link.setAttribute("href", urlListAll[idxList[i]]);
				link.setAttribute("target", "_top");
				var img = document.createElement("img");
				img.src = imageListAll[idxList[i]];
				img.alt = nameListAll[idxList[i]];
				img.setAttribute("baseImage", imageListAll[idxList[i]]);
				img.setAttribute("rollImage", imageRListAll[idxList[i]]);
				img.onmouseover = function() {
					this.src = this.getAttribute("rollImage");
				}
				img.onmouseout = function() {
					this.src = this.getAttribute("baseImage");
				}
				link.appendChild(img);
				area.appendChild(link);
				var br = document.createElement("br");
				area.appendChild(br);
			}
		}
	}

