myDate = new Date();
var $thisYear = myDate.getFullYear();
var yuga = {
	// imageのプリローダー
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	},
	
	URI: function(s){
		this.originalPath = s;
		
		
		this.getAbsolutePath = function(path){
			var img = new Image();
			img.src = path;
			path = img.src;
			img.src = '#';
			return path;
		};
	
		this.absolutePath = this.getAbsolutePath(s);
	
		
		this.isSelfLink = (this.absolutePath == location.href);
	
		
		var a = this.absolutePath.split('://');
		this.schema = a[0];
		var d = a[1].split('/');
		this.host = d.shift();
		var f = d.pop();
		this.dirs = d;
		this.file = f.split('?')[0].split('#')[0];
		var fn = this.file.split('.');
		this.fileExtension = (fn.length == 1) ? '' : fn.pop();
		this.fileName = fn.join('.');
		var fq = f.split('?');
		this.query = (fq[1]) ? fq[1].split('#')[0] : '';
		var ff = f.split('#');
		this.fragment = (ff[1]) ? ff[1].split('?')[0] : '';	
	}
};

		
$(function(){
		
	$('.btn').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});
	

	$("#copyright a").before($thisYear);
	
	
	$('div.o-1 dl , div.o-2 dl , div.o-3 dl').each(function(){
		$(this).find('dd:odd').addClass('even');
		$(this).find('dd:even').addClass('odd');
	});
	
	$('.tbl-4').each(function(){
		$(this).find('td:odd').addClass('even');
		$(this).find('td:even').addClass('odd');
		$(this).find('th:odd').addClass('even');
		$(this).find('th:even').addClass('odd');
	});
	$('.tbl-5').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');

	});
	$('.tbl-6').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');

	});
	
	
	$("a[@href^='http://'], a[@href^='https://'], a[@href$='.pdf'], a[@href$='.ppt'], a[@href$='.doc'], a[@href$='.xls'], a[@href$='.ai'], a[@href$='.eps'], a[@href$='.zip'], a[@href$='.xml']").each(function(){
		var $ThisLink = $(this).attr('href');
		var $SearchResult1 = $ThisLink.indexOf("http://www.titech.ac.jp/",0);
		var $SearchResult2 = $ThisLink.indexOf("http://www.ipo.titech.ac.jp/",0);
		var $SearchResult3 = $ThisLink.indexOf("http://www.gakumu.titech.ac.jp/kyoumu/",0);
			if($SearchResult1 < 0 && $SearchResult2 < 0 && $SearchResult3 < 0){
				$(this).attr("target", "_blank" );
			}
	})
	
	
	var pageUrl = location.href.split('#')[0];
	$('#wrapper a[@href]').each(function() {
	  if (this.href.indexOf(pageUrl + '#') == 0) {
		var id = this.href.split('#')[1];
		$(this).click(function() {
		  $('#' + id).ScrollTo('slow');
		  return false;
		});  
	  }
	});
	
});
