//=============================================
//
//  IEならbodyにクラスを追加
//  Windowsならbodyにwinクラスを追加
//
//=============================================
function checkType()
{
	var isMSIE = /*@cc_on!@*/0;
	
	if(isMSIE){
		jQuery("body").addClass("ie");
	}
	
	if(navigator.userAgent.indexOf("MSIE 6") != -1 ){
		jQuery("body").addClass("ie6");
	}
	else if(navigator.userAgent.indexOf("MSIE 7") != -1 ){
		jQuery("body").addClass("ie7");
	}
	else if(navigator.userAgent.indexOf("MSIE 8") != -1 ){
		jQuery("body").addClass("ie8");
	}
	else if(navigator.userAgent.indexOf("Firefox") != -1 )
	{
		jQuery("body").addClass("ff");
	}
	
	if(navigator.userAgent.indexOf("Win") != -1 ){
		jQuery("body").addClass("win");
	}
}

jQuery(document).ready(checkType);
/*==================================================================
//
//  LINK
//
==================================================================*/
function setClickableArea()
{
	jQuery(".clickable:has(a), a.clicable")
		.hover(
			function(){ jQuery(this).addClass("over"); },
			function(){ jQuery(this).removeClass("over"); }
		)
		.click(function(){
			var href = jQuery(this).find("a").attr("href");
			var target = jQuery(this).find("a").attr("target");
			clickLink(href, target);
		})
		.find('a').bind("click", function(event){
			event.preventDefault();
		});
		//aタグのイベントの動作だけをキャンセルしてバブリングは続行する
}
function clickLink(URL, target){
	if(URL != "" ){
		if(target == "top"){
			top.location.href = URL;
		}else if(target == "_blank"){
			window.open(URL, "");
		}else if(target){
			eval("parent.' + target + '.location.href = URL");
		}else{
			location.href = URL;
		}
	}
}
jQuery(document).ready(setClickableArea);
/*==================================================================
//
//  ロールオーバー
//
==================================================================*/
function initRollOverImages() {
	var image_cache = new Object();
	jQuery(".rollover a img, img.rollover").not("[src*='_o.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_over = this.src.substr(0, dot) + '_o' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_over;
		jQuery(this).parent("a, button").hover(
			function() { $(this).find("img").attr("src", imgsrc_over); },
			function() { $(this).find("img").attr("src", imgsrc); }
		);
	});
}
jQuery(document).ready(initRollOverImages);
/*
 * クリッカブルないの画像にimgOver → img.clickableImgOver
 */
function imgInit(){
	jQuery(".imgOver a img, img.imgOver").mouseover(imgOver);
	jQuery(".imgOver a img, img.imgOver").mouseout(imgOut);
	//
	jQuery(".clickable").hover(
		function(){
			jQuery(this).find("img.clickableImgOver.fade0").fadeTo(0, 0.6);
			jQuery(this).find("img.clickableImgOver").fadeTo(50, 0.6);
		},
		function(){
			jQuery(this).find("img.clickableImgOver").fadeTo(300, 0.999999);
		}
	);
}
//
function imgOver(){
	jQuery(this).fadeTo(50, 0.6);
}
//
function imgOut(){
	jQuery(this).fadeTo(300, 0.999999);
}
jQuery(document).ready(imgInit);

/*==================================================================
//
//  クリック時の枠線を消す
//
==================================================================*/
jQuery(document).ready(function(){
	jQuery("a").focus(function(){this.blur()});
});

/*==================================================================
//
//  ポップアップウィンドウ
//
==================================================================*/
/*
_obj :	パラメーターをオブジェクトで渡す。
		それぞれ、未指定だとデフォルトの値が入る。
		
		width		: 	幅
		height		: 	高さ
		name		:	ウィンドウネイム。デフォルトは '_blank'
						'_blank' だとステータスバーなどなし
		scroll		:	デフォルトは 'yes'
		resizabele	:	デフォルトは 'yes'
*/
function popWin(_url, _obj) {
	if(_obj == undefined) _obj = {};
	if(_obj.name == undefined){
		_obj.name = '_blank';
		_obj.menu = 'yes';
	}else{
		_obj.menu = 'no';
	}
	if(_obj.scroll == undefined) _obj.scroll = 'yes';
	if(_obj.resizable == undefined) _obj.resizable = 'yes';
	
	windowFeatures = 'scrollbars='+ _obj.scroll +',';
	windowFeatures+= 'resizable='+ _obj.resizable +',';
	windowFeatures+= 'menubar='+ _obj.menu +',';
	windowFeatures+= 'location='+ _obj.menu +',';
	windowFeatures+= 'toolbar='+ _obj.menu +',';
	windowFeatures+= 'status='+ _obj.menu +',';
	windowFeatures+= 'directories='+ _obj.menu;
	
	if(_obj.width)
	{
		var popLeft = (screen.availWidth-_obj.width)/2;
		windowFeatures+= ', left='+ popLeft;
		windowFeatures+= ', width='+ _obj.width;
	}
	if(_obj.height)
	{
		var popTop = (screen.availHeight-_obj.height)/2-20;
		windowFeatures+= ', top='+ popTop;
		windowFeatures+= ', height='+ _obj.height;
	}
	//alert(windowFeatures);
	var win;
	win = window.open(_url, _obj.name, windowFeatures);
	win.focus();
}


//=============================================
//
//  横並びリストの高さを揃える&一番右の右マージンを0に
//  リストのコンテナーにrowListクラス
//
//=============================================
function forceHeight(tag, num)
{
	//var num = 5; //横一列の個数
	
	jQuery(".rowList").each(function(){
		
		var maxH = 0;
		var boxList = [];
		
		jQuery(this).find(tag).each(function(index){
		
			boxList.push( jQuery(this) );
			
			if( maxH < jQuery(this).height() )
			{
				maxH = jQuery(this).height();
			}
			
			if(index % num == num-1)
			{
				for(i=0; i<boxList.length; i++)
				{
					boxList[i].height(maxH);
				}
				
				jQuery(this).css("margin-right", "0");
				
				maxHeight = 0;
				boxList = [];
			}
		});
	});
}

jQuery(document).ready(function(){
	forceHeight("li .inner .concept_program_body", 2);
	forceHeight("li .inner .course_body", 2)
});

//=============================================
//
//  ナビ現在位置
//
//=============================================
jQuery(document).ready(function(){
	
	//グローバルナビ
	jQuery('#gnav li').each(function(){
		var href = jQuery(this).find('a').attr('href');
		//
		//console.log(location.pathname, href, location.href.match(href) );
		//
		if( location.href.match(href) )
		{
			jQuery(this).addClass('current');
		}
	})
});
