// 名前の衝突をふせぐために名前空間を用意する
var MAIN;
if( ( MAIN && ( (typeof MAIN !== 'object') || !('isNamespace' in MAIN) ) ) || (MAIN === false) || (MAIN === 0) ) {
	throw new Error('"MAIN" already exists! You cannot define "MAIN".');
} else if( MAIN && ('isNamespace' in MAIN) ) {
	throw new Error('Namespace "MAIN" already exists!');
}
MAIN = {};  // 名前空間用のオブジェ生成
MAIN.toString = function() { return '[object MAIN(is Namespace)]'; };
MAIN.isNamespace = true;

// ■ポップアップ
// %param / url:String / URL
// %param / [name:String] / ウインドウ名（default:''）
// %param / [width:Number] / 幅（default:600）
// %param / [height:Number] / 高さ（default:600）
// %param / [opt:String] / 幅、高さ以外のオプション用の文字列（default:'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1'）
// ------
// %return / :Window / 新規ウィンドウ（失敗のときは『null』）
MAIN.openPopup = function(url, name, width, height, opt) {
	if( (url === '') || (typeof url !== 'string') ) { return null; }

	name = ( (name !== '') && (typeof name === 'string') )? name : '';
	width = ( (width > 0) && (width !== null) && (width !== '') && (! isNaN(width) ) && (typeof width !== 'object') && (typeof width !== 'boolean') )? parseInt(width) : 600;
	height = ( (height > 0) && (height !== null) && (height !== '') && (! isNaN(height)  ) && (typeof height !== 'object') && (typeof height !== 'boolean') )? parseInt(height) : 600;
	opt = ( (opt !== '') && (typeof opt === 'string') )? opt : 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';

	opt = 'width=' + width + ',height=' + height + ',' + opt;
	return window.open(url, name, opt);
};


// ------


var istRollOver = {
	preloadedImages:new Array(),
	preloadImage:function(uri){
		var plength = istRollOver.preloadedImages.length
		istRollOver.preloadedImages[plength] = new Image();
		istRollOver.preloadedImages[plength].src = uri;
	}
}

$(function(){
	$('#GRV li ul').removeClass('hide');
	$('#GRV li ul').hide();
	var bodyID = $('BODY').attr("id");
	var classID = $('BODY').attr("class");
	
	
	switch (bodyID){
 	case "TOPICS":
   		$('.parent01').removeClass('imgHover');
   		$('.parent01').attr('src','/common/images/grv/grv_01_cr.gif');
   		break;
	
	case "BASIC":
   		$('.parent02').removeClass('imgHover');
   		$('.parent02').attr('src','/common/images/grv/grv_02_cr.gif');
   		break;
	
	case "MORE":
   		$('.parent03').removeClass('imgHover');
   		$('.parent03').attr('src','/common/images/grv/grv_03_cr.gif');
   		break;
	
	case "QANDA":
   		$('.parent04').removeClass('imgHover');
   		$('.parent04').attr('src','/common/images/grv/grv_04_cr.gif');
   		break;
	
	case "DATA":
   		$('.parent05').removeClass('imgHover');
   		$('.parent05').attr('src','/common/images/grv/grv_05_cr.gif');
   		break;
	
	case "GUIDELINE":
   		$('.parent06').removeClass('imgHover');
   		$('.parent06').attr('src','/common/images/grv/grv_06_cr.gif');
   		break;
	
	case "PRODUCT":
   		$('.parent07').removeClass('imgHover');
   		$('.parent07').attr('src','/common/images/grv/grv_07_cr.gif');
   		break;
	

  
	}
	
	
	// BODYにclassが入っている
	//　左メニューカレント用ソース
	if(classID){
	
	$('ul#SubNavUl li').each(function(){
	/* 正規表現を使用し、bodyクラスの中にliのクラス名と同じものが含まれるか調べる */
	
	
	
	re = new RegExp(this.className, "i");
	if(classID.match(re)){
	$(this).children().children().attr('src',$(this).children().children().attr('src').replace('_off','_on'));
	$(this).children().children().removeClass('imgHover');
	}
	});
	};
	
	$(window).unload(function(){
	$('ul#SubNavUl li').each(function(){
 		$(this).children().children().attr('src',$(this).children().children().attr('src').replace('_on','_off'));
	 });
	});
	
	
	// ロールオーバー
	
	$('.imgHover').hover(function(){
		$(this).attr('src',$(this).attr('src').replace('_off','_on'));
	},function(){
		$(this).attr('src',$(this).attr('src').replace('_on','_off'));
	});


	
	$('#GRV li:has(ul)').hover(function(){
		$(this).children("ul").fadeIn("fast");
	},function(){
		$(this).children("ul").hide();
	});
	
	
});
