/**
 *	@filename		lib.js
 *	@charset		utf-8
 *	@created		December 8, 2009
 *	@lastmodified	December 8, 2009
 *	@description	共通js
 */
(function(){



//
//	スクロール用
//
var moveObject = function(){
	var y = document.body.scrollTop || document.documentElement.scrollTop;
	var target = Math.max(Math.floor(y - (y / 8)));
	scrollTo(0, target);
	if(target > 0){
		setTimeout(moveObject,10);
	}
};

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	DOMツリー構築完了後に実行（onload前）
//
////////////////////////////////////////////////////////////////////////////////////////////////////
$(function(){


//
//	このページの先頭へボタン動作
//
$(".anchorTop a").click(function(){
	moveObject();
	return false;
});
$("#anchorTop a").click(function(){
	moveObject();
	return false;
});


//
//ポップアップリンク
//
$(".popup").click(function(){
	var url=$(this).attr("href");
	win1 = window.open(url);
	win1.focus();
	return false;
});

//印刷する
//
$("#getPrint a").click(function(){
	window.print();
	return false;
});


//
//ウィンドウを閉じる
//
$(".btnClose a").click(function(){
	window.close();
	return false;
});



//
//	別ウィンドウリンク
//
var win = null;
var width = null;
var height = null;

$("a.popupWindow").click(function(){
							
	var href = $(this).attr("href");
	var url = href.split("#")[0];
	var q = href.split("#")[1].split("&");
	var params = new Array();
	
	for(var i = 0; i != q.length; i++) {
		params[q[i].split('=')[0]]
			  =  q[i].split('=')[1];
	}
	
	//Win1ウィンドウが無い場合
	if(win==null||win.closed==true){
		if(params["width"]&&params["height"]){
			width = params["width"];
			height = params["height"];
			win = window.open(url,"Win1","location='0',status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height+"\"");
		}else{
			width = null;
			height = null;
			win = window.open(url);
		}
	}
	//Win1ウィンドウが在る場合
	else{
		//新規ウィンドウのwidth とheight が同じ場合はlocationだけ変更
		if(!width && !height && !(params["width"]&&params["height"])){
			win.location = url;
		}else if((width == params["width"])&&(height == params["height"])){
			win.location = url;
		}
		//そうでない場合はwinを閉じて、Win1ウィンドウが無い場合と同じ処理
		else{
			win.close();
			if(params["width"]&&params["height"]){
				width = params["width"];
				height = params["height"];
				win = window.open(url,"Win1","location='0',status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height+"\"");
			}else{
				width = null;
				height = null;
				win = window.open(url);
			}
		}
	}
	
	win.focus();
	return false;
});


//
//画像のマウスオーバー処理
//
$("a.ov").hover(function(){
							$(this).css({"width":$("img",this).attr("width"),"height":$("img",this).attr("height"),"display":"block","background-color":"#ffffff"});
							$("img",this).fadeTo(100,0.5);
						},
						function(){
							$("img",this).fadeTo(100,1);
						});
//
//	ナビの高さを揃える
//
if($("#globalNav ul li").length!=0){
	ajustGnavHeight();
	
	var prevHeight = $("body").height();
	
	setInterval(ajustGnavHeight,500);
	
	$(window).unload(function(){
		//clearInterval(ajustGnavHeight);
	});
}

function ajustGnavHeight(){
	var b = jQuery.browser;
	var v = jQuery.browser.version;
	var padding = function(){
		if(b.msie&&v=="6.0"){
			return -8;
		}else if(b.msie&&v=="8.0"){
			return 0;
		}else{
			return 0;
		}
	}();
	
	curHeight = $("body").height();
	
	if(curHeight != prevHeight || (b.msie&&v=="6.0")){
		var mHeight = 0;
		$("#globalNav ul li").each(function(){
			
			$("a",this).css("height","auto");
			var h = $("a",this).height();
			
			if( h > mHeight ){
				mHeight = h;
			}
			
			if($("#globalNav ul li").index(this) == $("#globalNav ul li").length - 1){
				$("#globalNav ul li").each(function(){
					$("a",this).css("height",mHeight - padding+"px");
				});
			}
		});
	}
	prevHeight = curHeight;
}

});
////////////////////////////////////////////////////////////////////////////////////////////////////


})();
