
$(function(){
	
	// hover
	var gnavih = new Array();
	// slide
	var gnavis = new Array();

	$('#nav > li').each(function(index, elem){
		if(index < 4){
			gnavih[index] = false;
			gnavis[index] = false;
			$(elem).hover(
				function(){
					gnavih[index] = true;
					if(!gnavis[index]){
						$('ul', $(elem)).slideDown(300);
						var isrc = $('a img', $(elem)).attr('src');
						if(!isrc.match(/_on\.(jpg|gif)$/)){
							isrc = isrc.replace(/\.(jpg|gif)$/, '_on\.$1');				
							$('a img', $(elem)).attr({src: isrc});
						}
						gnavis[index] = true;
					}
				},
				function(){
					gnavih[index] = false;
					$('ul', $(elem)).slideUp(300,function(){
						gnavis[index] = false;
						//alert(index);
						//alert(gnavih[index]);
						if(gnavih[index]){
							$(this).slideDown(300);
							var isrc = $('a img', $(elem)).attr('src');
							if(!isrc.match(/_on\.(jpg|gif)$/)){
								isrc = isrc.replace(/\.(jpg|gif)$/, '_on\.$1');				
								$('a img', $(elem)).attr({src: isrc});
							}
							gnavis[index] = true;
						}
					});
					var isrc = $('a img', $(elem)).attr('src');
					var bdid = $('body').attr('id');
					var crt = $(elem).attr('class');
					if(isrc.match(/_on\.(jpg|gif)$/)){
						isrc = isrc.replace(/_on\.(jpg|gif)$/, '\.$1');				
						$('a img', $(elem)).attr({src: isrc});
					}if(bdid == crt){
						isrc = isrc.replace(/\.(jpg|gif)$/, '_on\.$1');			
						$('a img', $(elem)).attr({src: isrc});
					}
				}
			);
		}
	});
	
	// search
	var h_serch_flag = false;
	$('#nav li.h_serch').hover(function(){
		if(!h_serch_flag){
			if($(this).attr('class') == 'h_serch'){
				$(this).addClass('on');
			}
			$('.search_box').fadeIn(300);
			$('#head ul li.mouseout_area').show();
			h_serch_flag = true;
		}
	},
	function(){
		$('#head ul li.mouseout_area').hide();
		$('.search_box').fadeOut(300,function(){$('#nav li.h_serch').removeClass('on'); h_serch_flag = false;});
	});
	
	// scroll top
	$('.pagetop a').click(function() {
			$(this).blur();
			$('html ,body').animate({ scrollTop: 0 }, 'fast');
			return false;
	});

	// chart menu
	$('#chart p').hide();
	$('#chart p#all').show();
	$('#chart ul li.all a, #chart ul li.men a, #chart ul li.women a').click(function(){
		var btnNm = $(this).parent().attr('class');
		if(btnNm != 'download'){
		$('#chart p').hide();
		$('#chart p#' +btnNm).fadeIn(500);
		}else{
		}
		return false;
	});
	
	// research_examples
	$('#research_examples li img.answer').hide();
	$('#research_examples li a').click(function(){
		$('img.question',$(this).parent()).hide();
		$('img.answer',$(this).parent()).show();
		return false;
	});
		
		// コンテンツ高さ調整
		changeContheight();

	
});

// content height +1
function changeContheight(){
	var contHeight = $('#content_bt').height();
	var bheight = contHeight % 2;

	if(bheight == 0){
		
		//エージェントがIEかどうか判別
		var browser = typeof(document.body.style.maxHeight);
		
		if(browser != 'undefined'){ //IE6以外だったら
			$('#content_bt').css('min-height',contHeight + 1);
		}else{ //IE6だったら
			//#content_btの高さが偶数だった場合に、1px追加する
			$('#content_bt').css('height', contHeight+1);
		};

	};
}


// popup

function openWindow(theURL, width, height, features, winName) { //v2.0
	if(typeof(width) == "undefined" || width == 0){
		width = 500;
	}
	
	if(typeof(height) == "undefined" || height == 0){
		height = 500;
	}
	
	if(typeof(features) == "undefined" || features == ""){
		features = "status=yes,menubar=no,scrollbars=yes,resizable=yes";
	}
	
	features = features + ', width = ' + width + ', height = ' + height;
	
  window.open(theURL,winName,features);
}
