jQuery(document).ready(function($) {

	var postfix = '_ov';
	$('.over').not('[src*="'+ postfix +'."]').each(function() {

		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		           + postfix
		           + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		);
	});


	jQuery.easing.quart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};  
	$('.pageTop a').click(function () {
		$('html,body').animate({ scrollTop: 0 }, 1000, 'quart');
		return false;
	});

	/* PAGESETUP
	-----------------------------------------------------------------------------------------------------------------*/
	js_lNavi_visual();
	js_window_open();
	js_link_icon();
	js_pNavi_visual();
	js_bNavi_visual();

});

/*	//	PAGE PRINT
-----------------------------------------------------------------------------------------------------------------*/
function js_page_print(){
	window.print();
	return false
}
/*	//	
-----------------------------------------------------------------------------------------------------------------*/
function js_window_close(){
	window.close();
	return false;
}
/*	//	
-----------------------------------------------------------------------------------------------------------------*/
function js_window_open(){
	var js_para = null;
	// js_para[0] = width
	// js_para[1] = height
	// js_para[2] = window.name
	$('a[class^="js_window_open"], area[class^="js_window_open"]').each(function(index){
		$(this).click(function(){
			var wo = null;
			// get window width & height
			js_para = $(this).attr('class').match(/[0-9]+/g);
			// get window.name
			window.name ? js_para[2] = window.name+'_' : js_para[2] = ('');
			wo = window.open(this.href, js_para[2]+'popup'+index,'width='+js_para[0]+',height='+js_para[1]+',scrollbars=yes');
			wo.focus();
			return false;
		});
	});
}
/* lNavi visual SETUP 091224/
-----------------------------------------------------------------------------------------------------------------*/
function js_lNavi_visual(){
	$('#lNavi ul ul').hide();
	var _root_elm = $('#sub > div:first').attr('class');
	$('#lNavi ul li:first-child').addClass('firstChild');
	$('#lNavi ul li:last-child').addClass('lastChild');
	$('#lNavi .cName').each(function(){
		$(this).click(function(){
			$(this).next().toggle();
		});
		$(this).hover(function(){ $(this).addClass('p_hover');},function(){ $(this).removeClass('p_hover')});
	});
	$('#lNavi .cName + ul').addClass('cList');
	$('#lNavi .icon > p a').each(function(){
		$(this).append('&nbsp;<img src="/image/common/images/ico/ico_lnavi_blank.gif" width="8" height="10" alt="" />');
		$(this).click(function(){
			window.open(this.href,'extarnal');
			return false;
		});
	});
	if(_root_elm){
		_routing = new Array;
		_routing[0] = _root_elm.match(/l[\dA-Z]+_[\d]+cr/);
		_routing[1] = _root_elm.match(/l[\dA-Z]+_[\d]+/);
		_routing[2] = _root_elm.match(/n[\d]+_[\d]+cr/);
		_routing[3] = _root_elm.match(/n[\d]+cr/);
		if(_routing[0]){ _routing[0].push(_routing[0][0].match(/[\dA-Z]+/g))}
		if(_routing[1]){ _routing[1].push(_routing[1][0].match(/[\dA-Z]+/g))}
		if(_routing[2]){ _routing[2].push(_routing[2][0].match(/[\d]+/g))}
		if(_routing[3]){ _routing[3].push(_routing[3][0].match(/[\d]+/g))}
		if(_routing[0] != null){
			$('.lNav'+_routing[0][1][0]+'_'+_routing[0][1][1]+' > p a,'+
			  '.lNav'+_routing[0][1][0]+'_'+_routing[0][1][1]+' > p strong').addClass('current').parent().next().show();
		}else if(_routing[1] != null){
			$('.lNav'+_routing[1][1][0]+'_'+_routing[1][1][1]+' > ul').show();
		}else{
		}
		if(_routing[1] != null && _routing[2] != null){
			$('.lNav'+_routing[1][1][0]+'_'+_routing[1][1][1]+' .nav'+_routing[2][1][0]+'_'+_routing[2][1][1]+' > p a,'+
			  '.lNav'+_routing[1][1][0]+'_'+_routing[1][1][1]+' .nav'+_routing[2][1][0]+'_'+_routing[2][1][1]+' > p strong').addClass('current').parent().parent().parent().show();
		}else if(_routing[1] != null && _routing[3] != null){
			$('.lNav'+_routing[1][1][0]+'_'+_routing[1][1][1]+' .nav'+_routing[3][1]+' > p a').addClass('current').parent().next().show();
		}else{
		}
	}
}
/* lNavi visual SETUP 091224/
-----------------------------------------------------------------------------------------------------------------*/
function js_bNavi_visual(){
	var _root_elm = $('.bNavi').parent().attr('class');
	$('.bNaviIn ul ul').hide();
	if(_root_elm){
		$('.bNavi').each(function(){
			_root_elm = $(this).parent().attr('class');
			_routing = new Array;
			_routing[0] = _root_elm.match(/bN[\d]+_[\d]+cr/);
			_routing[1] = _root_elm.match(/bN[\d]+cr/);
			if(_routing[0]){ _routing[0].push(_routing[0][0].match(/[\d]+/g))}
			if(_routing[1]){ _routing[1].push(_routing[1][0].match(/[\d]+/g))}
			if(_routing[0] != null){
				$('.'+_routing[0][0]+' a.bNav'+_routing[0][1][0]+'_'+_routing[0][1][1]).addClass('current').parent().parent().show();
			}else if(_routing[1] != null){
				$('.'+_routing[1][0]+' a.bNav'+_routing[1][1]).addClass('current');
			}else{
			}
		});
	}
}
/* js_pNavi_visual 100112/
-----------------------------------------------------------------------------------------------------------------*/
function js_pNavi_visual(){
	$('.pNavi li a span, .pNavi4 li a span, .pNavi3 li a span, .pNavi2 li a span, .pNaviW li a span, .pNaviW4 li a span').each(function(){
		$(this).css('display','inline-block');
		//console.log($(this).innerWidth() +' - '+ $(this).parent().innerWidth());
		if(($(this).innerWidth() + 18) > $(this).parent().innerWidth() || $(this).innerHeight() > 50){
			$(this).css('display','block').css('width',($(this).parent().innerWidth()-11)+'px').css('margin-left','11px')
			.parent().parent().addClass('line2');
		}
		if($(this).css('display') == 'inline-block'){
			$(this).css('width',($(this).innerWidth()+2)+'px').css('display','block').css('margin','0 auto');
		}
		if($(this).css('display') == 'inline'){
			$(this).css('width',($(this).innerWidth()+2)+'px').css('display','block').css('margin','0 auto');
		}
		if($(this).css('display') == 'block' && $(this).innerHeight() < 35){
			$(this).parent().parent().removeClass('line2');
		}
		$(this).prepend('<img src="/image/common/images/ico/ico_arrR02.gif" class="pNaviArr" alt="" />');
	});
}
/* link_type icon SETUP 091213/
-----------------------------------------------------------------------------------------------------------------*/
function js_link_icon(){
	var icons = {
		'type08' : '<img src="/image/common/images/ico/option_ico_email.gif" width="12" height="9" alt="" />',
		'ico_news_prod' : '<img src="/image/common/images/ico/ico_news_prod.gif" width="36" height="13" style="position:absolute;top:2px;left:0px;" alt="製品" />',
		'ico_news_com' : '<img src="/image/common/images/ico/ico_news_com.gif" width="36" height="13" style="position:absolute;top:2px;left:0px;" alt="企業" />',
		'ico_news_ir' : '<img src="/image/common/images/ico/ico_news_ir.gif" width="36" height="13" style="position:absolute;top:2px;left:0px;" alt="IR" />'
	};
	$('.ul_news dd.ico_news_prod,'+
	  ' .ul_news02 dd.ico_news_prod,'+
	  ' .ul_news dd.ico_news_com,'+
	  ' .ul_news02 dd.ico_news_com,'+
	  ' .ul_news dd.ico_news_ir,'+
	  ' .ul_news02 dd.ico_news_ir,'+
	  ' a[href*="mailto"]').each(function(){
		if($(this).attr('href')){
			if($(this).attr('href').match(/mailto/)){
				if($(this).text().length != 0){ $(this).prepend(icons['type08']+'&nbsp;');}
			}
		}else if($(this).attr('class').match(/ico_news_prod/)){ $(this).prepend(icons['ico_news_prod']);
		}else if($(this).attr('class').match(/ico_news_com/)){ $(this).prepend(icons['ico_news_com']);
		}else if($(this).attr('class').match(/ico_news_ir/)){ $(this).prepend(icons['ico_news_ir']);
		}else{}
	});
}

/*	//	Firefox Print CSS
-----------------------------------------------------------------------------------------------------------------*/
var firefox = (navigator.userAgent.indexOf("Firefox") != -1)? true : false; 
if(firefox) document.write('<link rel="stylesheet" type="text/css" media="print" href="/common/css/fx_print.css" />');

/* cookie operation 091208
-----------------------------------------------------------------------------------------------------------------*/
function class_cookielib(){
	this.getCookie = getCookie;
	this.setCookie = setCookie;
	this.removeCookie = removeCookie;
	var expireDate = new Date();
	expireDate.setFullYear(expireDate.getFullYear()+1);
	expireStr = "expires=" + expireDate.toUTCString();
	function getCookie(name){
		var gc=name+"=";
		var Cookie=document.cookie;
		if (Cookie.length>0) {
			var start=Cookie.indexOf(gc);
			if (start!=-1) {
				start+=gc.length;
				terminus=Cookie.indexOf(";",start);
				if (terminus==-1) terminus=Cookie.length;
				return unescape(Cookie.substring(start,terminus));
			}
		}
		return '';
	}
	function setCookie() {
		var key = arguments[0];
		var val = arguments[1];
		var path = (typeof(arguments[2]) != 'undefined' ? arguments[2] : '/');
		
		var exp = (typeof(arguments[3]) != 'undefined'  ? arguments[3] : expireStr);
		var sc = key + "=" + escape(val) + "; path=" + path + "; " + exp;
		document.cookie = sc;
	}
	function removeCookie(key,path) {
		if(!path){
			path = '/';
		}
		var rc = key + "=; path=" + path + "; expires=Thu, 28 Jun 2001 00:00:00 UTC";
		document.cookie = rc;
	}
}
var cookieObj = new class_cookielib();



