//==================================================================
//class for ie ( for base font)
//==================================================================

$(function(){
	if($.browser.msie){
		$("body").addClass("msie");
	}
	if (navigator.platform.indexOf("Win") != -1) {
		$("body").addClass("win");
	}
});


//==================================================================
//font change [jQuery]
//==================================================================

jQuery(function($){
    //変数にクッキー名を入れる
    var history = $.cookie('fontSize');
	
    //適用する箇所を指定。今回は部分的に#test内のpに
    var elm = $('body');
	
    //変数が空ならfontMを、空でなければクッキーに保存しておいたものを適用
    (!history)? elm.addClass('pageFont_n'):elm.addClass(history);
	
    //クリックしたら実行
    $('li','#fontChList').click(function(){
	
        //クリックした要素のID名を変数にセット
        var setFontSize = this.id;
	    
        //クッキーに変数を保存
				//$.cookie('fontSize', setFontSize);
				
				// 調整　パス：：：クッキーに変数を保存
	    $.cookie('fontSize', setFontSize,{expires: 365, path: '/'});
	
        //一度classを除去して、変数をclassとして追加
        elm.removeClass().addClass(setFontSize);
								





								//　+リロード++　heitline などのため
								location.reload();
								
								
								
								
    });
});




//==================================================================
//Equal Height Columns with jQuery [jQuery]
//==================================================================

function equalHeight(group) {
 tallest = 0;
 group.each(function() {
 thisHeight = $(this).height();
 if(thisHeight > tallest)
 {
 tallest = thisHeight;
 }
 });
 group.height(tallest);
}




/*
Usage:
$(document).ready(function() {
    equalHeight($(".recent-article"));
    equalHeight($(".footer-col"));
});

//.hogeの中にあるdivの高さを全て同じにする  
        equalHeight($("div.hoge > div"));  
  
        //.hoge-singleを付与された要素同士の高さを揃える  
        equalHeight($("div.hoge-single"));  
  
        //.hoge-Lと.hoge-Rの高さを揃える  
        equalHeight($("div.hoge-L,div.hoge-R")); 
								
*/

//==================================================================

//==================================================================
//rollover.js
//==================================================================

function initRollOvers() {
	if (!document.getElementById){
		return;
	}
	
	var preLoads = new Array();
	var allImages = document.getElementsByTagName('img');

	for (var i = 0; i < allImages.length; i++) {		
		if (allImages[i].className == 'imgover') {
			var src = allImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var oSrc = src.replace(ftype, '_over'+ftype);

			//-- 
			allImages[i].setAttribute('pSrc', src);
			allImages[i].setAttribute('oSrc', oSrc);

			//-- 
			preLoads[i] = new Image();
			preLoads[i].src = oSrc;

			//-- 
			allImages[i].onmouseover = function() {
				this.setAttribute('src', this.getAttribute('oSrc'));
			}
			allImages[i].onmouseout = function() {
				this.setAttribute('src', this.getAttribute('pSrc'));
			}
		}
	}
}

function addOnload(func){
	if ( typeof window.addEventListener != "undefined" ){
		window.addEventListener( "load", func, false );
	}else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", func );
	}else{
		if ( window.onload != null ){
			var oldOnload = window.onload;
			window.onload = function ( e ) {
			oldOnload( e );
			window[func]();
		};
	}else
		window.onload = func;
	}
}
addOnload(initRollOvers);

//==================================================================
//:first-child, :last-child
//==================================================================
$(function(){
    $('.sideMenuList li:first-child').addClass('firstChild');
    $('.sideMenuList li:last-child').addClass('lastChild');
});


/*--------------------------------------------------------------------------*
 *  
 *  heightLine JavaScript Library beta4
 *  
 *  MIT-style license. 
 *  
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *  
 *--------------------------------------------------------------------------*/
new function(){
	
	function heightLine(){
	
		this.className="heightLine";
		this.parentClassName="heightLineParent"
		reg = new RegExp(this.className+"-([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/\s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",heightLine);
}


//==================================================================
// pageindex btns
//==================================================================



$(function () {
    $('div.pageIndexBox').click(function () {
        var boxLink = $(this).find('a');
        if (boxLink.attr('target') == '_blank') {
            window.open(boxLink.attr('href'));
        }
        else window.location = boxLink.attr('href');
        return false;
    });
    $('div.pageIndexBox').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });
});

//==================================================================
// old type
//==================================================================
//別ウインドウを開く

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//==================================================================
// チェック用Class 追加 (headerのenglish 削除等に使用）
//==================================================================
$(function(){
    $('#haederLinks li:eq(2)').addClass('checkclass');
});
