// プラットフォーム・ブラウザごとのフォントスタイル読込
var plat = (navigator.userAgent.indexOf("Win") >= 0) ;
if(plat) {
	document.write('<link rel="stylesheet" href="/common/css/font_win.css" type="text/css" media="all">');
}else{
	var plat = (navigator.userAgent.indexOf("Safari") >= 0) ;
	if(plat) {
		document.write('<link rel="stylesheet" href="/common/css/font_safari.css" type="text/css" media="all">');
	}else
	{document.write('<link rel="stylesheet" href="/common/css/font_mac.css" type="text/css" media="all">');}
}

var plat = (navigator.userAgent.indexOf("Opera") >= 0) ;
if(plat) {
	document.write('<link rel="stylesheet" href="/common/css/font_opera.css" type="text/css" media="all">');
}else{}

// フォントサイズ・ボタン変更
// サイズリスト
SizeList = new Array (93,108,124);
BGurl = new Array ('/images/btn_fsize_s_on.gif','/images/btn_fsize_m_on.gif','/images/btn_fsize_l_on.gif');
Activesize = new Array ('div#small','div#default','div#large');

//デフォルトサイズのインデックス数
DefaultKey = 1;

//タグに挿入するID名
BodyID = "wrapper";

if(GetCookie("YsystemFSS") == "none"){
	key = DefaultKey;
}else{
	key = Number(GetCookie("Ysystem"));
}
document.writeln('<style type="text/css">');
document.writeln('#'+BodyID+'{font-size: '+SizeList[key]+'%;}');
document.writeln('</style>');
document.writeln('<style type="text/css">');
document.writeln('div#header div#sitenv div#tool div#fontsize div#fbtn '+Activesize[key]+'{background:url('+BGurl[key]+') top left no-repeat;}');
document.writeln('</style>');

function cgfont(value){
	if(value=="large"){
		key = 2;
	}else if(value=="small"){
		key = 0;
	}else if(value=="default"){
		key = DefaultKey;
	}
	size = SizeList[key] + "%";
	image  = BGurl[key];
	bgid = value;
	if(document.all){
		document.all(BodyID).style.fontSize = size;
	}
	if(document.getElementById){
		document.getElementById(BodyID).style.fontSize = size;
	}
	WriteCookie("YsystemFSS",key);
	document.getElementById("large").style.backgroundImage = "url(/images/btn_fsize_l_off.gif)";
	document.getElementById("default").style.backgroundImage = "url(/images/btn_fsize_m_off.gif)";
	document.getElementById("small").style.backgroundImage = "url(/images/btn_fsize_s_off.gif)";
	document.getElementById(bgid).style.backgroundImage = "url("+image+")";
}


function WriteCookie(name,value){
	tmp = name+"="+value+";";
	tmp += "expires=Fri, 31-Dec-2030 23:59:59;";
	tmp += "path=/;";
	document.cookie = tmp;
}

function GetCookie(value){

	data = document.cookie+";";
	tmp = data.indexOf(value,0);
	if(tmp != -1){
		size = data.substring(tmp,data.length);
		start = size.indexOf("=",0);
		end = size.indexOf(";",start);
		return(unescape(size.substring(start+1,end)));
	}else{
		return "none";
	}
}


// ポップアップ
function popupgallery(filename,winname) {
newWin=window.open(filename,winname,"width=640,height=640,menubar=1,scrollbars=1,toolbar=1,resizable=1,status=1");
}

function popupmovie(filename,winname) {
newWin=window.open(filename,winname,"width=640,height=540,menubar=1,scrollbars=1,toolbar=1,resizable=1,status=1");
}

function PrintPage(){
	if(document.getElementById || document.layers){
		window.print();	
	}
}

// 汎用ロールオーバー
function smartRollover() {  
    if(document.getElementsByTagName) {  
        var images = document.getElementsByTagName("img");  
        for(var i=0; i < images.length; i++) {  
            if(images[i].getAttribute("src").match("_off."))  
            {  
                images[i].onmouseover = function() {  
                    this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));  
                }  
                images[i].onmouseout = function() {  
                    this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));  
                }  
            }  
        }  
    }  
}  
if(window.addEventListener) {  
    window.addEventListener("load", smartRollover, false);  
}  
else if(window.attachEvent) {  
    window.attachEvent("onload", smartRollover);  
} 

// プリント
function PrintPage(){
	if(document.getElementById || document.layers){
		window.print();
	}
}

// このページの最初へ
function scrollToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	window.scrollTo(Math.floor(x / 1.4), Math.floor(y / 1.4));
	if (x > 0 || y > 0) {
		window.setTimeout("scrollToTop()", 10);
	}
}

// 検索フォーム初期テキスト
function cText(obj){
if(obj.value==obj.defaultValue){
obj.value="";
}
}

// ボックス高さ合わせ
$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};


// IE用フォーム背景
// ADD 090409
$(function(){
$("input[type='text'],textarea")
.focus(function(){
$(this).addClass("focus");
})

.blur(function(){
$(this).removeClass("focus");
});
});
