/* ロードスクリプト */
$('document').ready(
	function(){
		/* 選択済の本文サイズに設定 */
		if($.cookie('cluster_fontsize')){
			setFontSize($.cookie('cluster_fontsize'),true);
		}
		
		/* アンカーリンクのスムース化 */
		$('a[href^=#]').click(
			function(){
				var href = this.hash;
				var targetObj = $(href=='#_top'?'body':href);
				if(targetObj.size()){
					var top = targetObj.offset().top;
					$($.browser.safari?'body':'html').animate({scrollTop:top});
 					/*$.scrollTo(targetObj,800,{easing:'swing'});*/
					return false;
				}
			}
		);

		/* 新着情報項目のボーダー背景を着色 */
		$('#newslist li:odd').css("background-color","#f1faee");

		/* 新着情報のうち、linkクラスの項目にターゲットを追加 */
		$('#newslist .link a').attr("target","_blank");

		/* researchイメージのトグル拡縮 */
		setToggle('#research01 #fig01',570,510,285,255);
		setToggle('#research01 #fig02',570,712,130,170);
		setToggle('#about01 #fig01',580,468,180,135);
		setToggle2('.topics #imageArea img',570,435,184,138);
	}
);

/*拡縮トグル適用*/
function setToggle(obj,wMax,hMax,wMin,hMin){
	if(navigator.appVersion.lastIndexOf('MSIE')!=-1){
		$(obj).toggle(
			function(){$(this).css({'width':wMax+'px','height':hMax+'px','margin':'0 0 14px 14px'})},
			function(){$(this).css({'width':wMin+'px','height':hMin+'px','margin':'0 0 0 14px'})}
		);
	}else{
		$(obj).toggle(
			function(){$(this).animate({'width':wMax+'px','height':hMax+'px','margin':'0 0 14px 14px'},'fast')},
			function(){$(this).animate({'width':wMin+'px','height':hMin+'px','margin':'0 0 0 14px'},'fast')}
		);
	}
}
function setToggle2(obj,wMax,hMax,wMin,hMin){
	if(navigator.appVersion.lastIndexOf('MSIE')!=-1){
		$(obj).toggle(
			function(){$(this).css({'width':wMax+'px','height':hMax+'px'})},
			function(){$(this).css({'width':wMin+'px','height':hMin+'px'})}
		);
	}else{
		$(obj).toggle(
			function(){$(this).animate({'width':wMax+'px','height':hMax+'px'},'fast')},
			function(){$(this).animate({'width':wMin+'px','height':hMin+'px'},'fast')}
		);
	}
}

/* 本文サイズ制御 */
/* statがtrueの場合はアニメートしない */
function setFontSize(val,stat){
	$('#header_sizemenu li a').css({backgroundPosition:"left bottom"});
	switch(val){
		case "large":
			(!stat)?$('body').animate({fontSize:"18px",lineHeight:"160%"},"fast"):$('body').css({fontSize:"18px",lineHeight:"160%"});
			$('#size_large').css({backgroundPosition:"left top"});
			$.cookie('cluster_fontsize','large',{path:'/'});
			break;
		case "small":
			(!stat)?$('body').animate({fontSize:"12px",lineHeight:"180%"},"fast"):$('body').css({fontSize:"12px",lineHeight:"180%"});
			$('#size_small').css({backgroundPosition:"left top"});
			$.cookie('cluster_fontsize','small',{path:'/'});
			break;
		default:
			(!stat)?$('body').animate({fontSize:"14px",lineHeight:"180%"},"fast"):$('body').css({fontSize:"14px",lineHeight:"180%"});
			$('#size_middle').css({backgroundPosition:"left top"});
			$.cookie('cluster_fontsize','middle',{path:'/'});
		}
}
function initialFontSize(val){

}


/* クッキー操作用関数（jQuery.cookieの転載）  */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/* Flashタグ生成 */
/* check Browsers */
var macIE = false;
var winIE = false;
var macMozilla = false;
var winMozilla = false;
var winChrome = false;
var macChrome = false;
var macSafari = false;
var winSafari = false;
if(navigator.appVersion.indexOf("MSIE")!=-1){
	if(navigator.appVersion.indexOf("Mac")!=-1){
		macIE = true;
	}else{
		winIE = true;
	}
}else if(navigator.userAgent.indexOf("Firefox")!=-1){
	if(navigator.appVersion.indexOf("Windows")!=-1){
		winMozilla = true;
	}else{
		macMozilla = true;
	}
}else if(navigator.appVersion.indexOf("Chrome")!=-1){
	if(navigator.appVersion.indexOf("Windows")!=-1){
		winChrome = true;
	}else{
		macChrome = true;
	}
}else if(navigator.appVersion.indexOf("Safari")!=-1){
	if(navigator.appVersion.indexOf("Windows")!=-1){
		winSafari = true;
	}else{
		macSafari = true;
	}
}
function writeFlashCode(swf,width,height,idName){
	if(swf==null){var swf="top";}
	if(width==null){var width="900";}
	if(height==null){var height="200";}
	if(idName==null){var idName="home_flash";}
	if((!macMozilla)&&(!winMozilla)&&(!macIE)&&(!winChrome)&&(!macChrome)&&(!macSafari)&&(!winSafari)){
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+idName+'" align="middle">\n');
		document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
		document.write('<param name="movie" value="'+swf+'.swf" />\n');
		document.write('<param name="quality" value="autohigh" />\n');
		document.write('<param name="bgcolor" value="#ffffff" />\n');
		document.write('<param name="wmode" value="transparent" />\n');
		document.write('</object>\n');
	} else {
		document.write('<embed src="'+swf+'.swf" quality="autohigh" wmode="transparent" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+swf+'" id="'+idName+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	}
}
