$(document).ready(function(){
	// トップページ：サービスボックス
	var max = 0;
	$('.service .box').each(function(){
		if ($(this).height() > max)
			max = $(this).height();
	});
	$('.service .box').height(max); 
});


// ツールチップ
$(function(){
	
	// 全要素をからTITLE属性を持っている要素だけに絞る
	$("body *").filter(function(){
		return this.title && this.title.length>0;
	}).each(function(){
		// TITLE属性を持っている要素に適用する
		
		// あとで使う
		var self = $(this), title = self.attr("title");
		
		// TITLE属性を持っている要素にhover()で
		self.hover(
		
			// mouseover
			function(e){ // このeはevent自体を意味する
			
				// TITLEがあるとブラウザのチップが出るので一時的に空にしておく
				self.attr("title","");
			
				// とりあえず表示するtip要素を生成しておく
				$("body").append("<div id='title-tip'>"+title+"</div>");
				$("#title-tip").css({
					position: "absolute",
					
					// e.pageX(Y)でカーソルが要素に乗った時点でのX(Y)座標を取得する
					top: e.pageY+(-15), // カーソルと表示したtipが重なるとチラつくので少しずらす
					left: e.pageX+15
				});
			},
			
			// mouseout
			function(){
			
				// mouseoverで空にしたTITLEを戻す
				self.attr("title",title);
			
				// 要素から離れた場合はtipを非表示にして削除しておく
				$("#title-tip").hide().remove();
			}
		);
		
		// 要素上でカーソルが移動した場合は、逐一tipの位置を変える
		self.mousemove(function(e){
			$("#title-tip").css({
				top: e.pageY+(-15),
    			left: e.pageX+15
			});		
		});
	});
			
});



// ロールオーバー
function initRollOverImages() {
var image_cache = new Object();
	$(".rollover").not("[src*='_on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
};
$(document).ready(initRollOverImages);
