/* CSSハック用 */
/* ----------------------------------------------------- */
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

/* ----------------------------------------------------- */
/* jquery ロード*/
/* ----------------------------------------------------- */
$(function(){

	/* グローバルナビ　カレントページのボタン変更（ロールオーバー部分の前に記載する） */
	/* ----------------------------------------------------- */
	var activeObj ='#g-'+ $('body').attr('id');
	if($('#header .gnav li').filter(activeObj).size()==1){
		$(activeObj).addClass('current');
		$activeObj = $(activeObj).find('a:first img');
		var src = $activeObj.attr('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace(ftype, '_a'+ftype);
		$activeObj.attr('src', hsrc);
	}

	/* マップ　ロールオーバー*/
	/* ----------------------------------------------------- */
	$('.recruit-message area').mouseover(function(){
		var objSrc = $(this).parent('map').attr("id");	
		objSrc = $('#'+objSrc.split('-')[0]);
		Rollover(objSrc,objSrc.attr('src'));	
	});	
	$('.recruit-message area').mouseout(function(){
		var objSrc = $(this).parent('map').attr("id");	
		objSrc = $('#'+objSrc.split('-')[0]);
		Rollover(objSrc,objSrc.attr('src'));	
	});	

	/* 関数Call */
	/* ----------------------------------------------------- */
	lnavActive('#side dl.lnav');
	if($('.recruit-message area').size()>0){
		$('.recruit-message area').lightBox();
	}
	
	/* ロールオーバー */
	/* ----------------------------------------------------- */
	$("a img").not('[src*="_a."],img.no-hover,#header .gnav img,:animated, #home-wrap div.hw-l ul.bnr01 img').hover(function()
	{
		$(this).animate({ opacity: 0.7 }, 300);
	},function() {
		$(this).animate({ opacity: 1.0 }, 300);
	});

	/* ロールオーバー（オーバー画像に差し替えVer) */
	/* ----------------------------------------------------- */
	$('#header .gnav li.no-child img,#home-wrap div.hw-l ul.bnr01 img,div.hiromaz-square .over').not('[src*="_a."]').hover(function()
	{
		Rollover($(this),$(this).attr('src'));	
	},function() {
		Rollover($(this),$(this).attr('src'));	
	});	

	/* グローバルナビプルダウン */
	/* ----------------------------------------------------- */
	$('#header .gnav > li').each(function(){
		var pullChild = $('div.pull-nav',this);
		if(pullChild.size()!==0){
			var imgChild = $('img',this);
			if(!$(this).hasClass('current')){
				$(this).hover(function()
				{
					Rollover(imgChild,imgChild.attr('src'));	
					pullChild.slideDown(100);
				},function() {
					Rollover(imgChild,imgChild.attr('src'));	
					pullChild.slideUp(100);	
				});	
			}
			else{
				$(this).hover(function()
				{
					var imgChildSrc = imgChild.attr('src');
					var ftype = imgChildSrc.substring(imgChildSrc.lastIndexOf('_a.'), imgChildSrc.length);
					var ftype02 = imgChildSrc.split('_a')[1];
					imgChildSrc = imgChildSrc.replace(ftype, ftype02);	
					Rollover(imgChild,imgChildSrc);	
					pullChild.slideDown(300);
				},function() {
					var imgChildSrc = imgChild.attr('src');
					var ftype = imgChildSrc.substring(imgChildSrc.lastIndexOf('_o.'), imgChildSrc.length);
					var ftype02 = imgChildSrc.split('_o')[1];
					imgChildSrc = imgChildSrc.replace(ftype, '_o'+ftype02+'_a');	
					Rollover(imgChild,imgChildSrc);	
					pullChild.slideUp(300);	
				});	
			}
		}
	});

	/* IE6 PNG表示対策 */
	/* ----------------------------------------------------- */
	if(!jQuery.support.opacity){
		if(!jQuery.support.style){
			if (typeof document.documentElement.style.maxHeight == "undefined") {
				$("#header ul.gnav div,#header ul.gnav ul").fixPng();
			}
		}
	}
	
	/* プリント*/
	/* ----------------------------------------------------- */
	$('#main div.dealer-detail li.print').click(function(){
			window.print();
			return false;
	});

	/* ページ内スクロール */
	/* ----------------------------------------------------- */
  $('a[href^=#]').click(function(event) {
    var hash = this.hash;
		if(hash!==''){
			var tarPosition = $(hash).offset().top;
			if(undefined !== window.opera && "function" === typeof window.opera.version){ // opera
				$('html').animate({scrollTop: tarPosition}, 400, 'easeOutQuad'); 
			}
			else{
				$('html, body').animate({scrollTop: tarPosition}, 400, 'easeOutQuad');
			}
			return false;
		}
  });

	/* 職場の雰囲気 */
	/* ----------------------------------------------------- */
	if($('.staff-article').size()>0){
		var mood = $('.staff-article .pic ul').moodular({
			auto : false,
			speed : 800,
			callbacks: [checkNum],
			api : true
		});	
	
	}
	
	$('.staff-article .next').bind('click', function () { mood.next(); return false; });
	$('.staff-article .prev').bind('click', function () { mood.prev(); return false; });

	function checkNum(moodular){
		var num01 = $('.staff-article .pic li').size()/2; 
		var num02 = moodular.current+1;
		if(num02>1){
			$('.staff-article .next').removeClass('no-disp')
			$('.staff-article .prev').removeClass('no-disp')
		}
		if(num01===num02){
			$('.staff-article .next').addClass('no-disp')
		}
		if(num02===1){
			$('.staff-article .prev').addClass('no-disp')
		}
	}

	$('.staff-article .next,.staff-article .prev').hover(function()
	{
		$(this).animate({ opacity: 0.7 }, 300);
	},function() {
		$(this).animate({ opacity: 1.0 }, 300);
	});
	
	/* addclass */
	/* ----------------------------------------------------- */
	$('#side dl.lnav li:last-child').addClass('last-c');
	$('#main .table-s01 th:first-child').addClass('first-c');
	$('#main .table-s01 tr td:last-child').addClass('last-c');
	$('#main .table-s01 tr:even').addClass('even');
	$('#main .table-s04 tr:even').addClass('even');
	$('#main .table-s04 tr:even').addClass('even');

	if($('#side').size()===1){
		if($('#side').height()>$('#main').height()){
			$('#main').height($('#side').height()-14);
		}
	}

	if(!jQuery.support.opacity){
		if(!jQuery.support.style){
			if (typeof document.documentElement.style.maxHeight == "undefined") {
				var totTop = $('#totop')
				$('#footer .copy-wrap').after(totTop);
			}
		}
	}

});

/* ----------------------------------------------------- */
/*　ページ内スクロール用　*/
/* ----------------------------------------------------- */
jQuery.easing.easeOutQuad = function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
};

/* ----------------------------------------------------- */
/* ローカルナビアクティブ */
/* ----------------------------------------------------- */
var lnavActive = function(obj){
	/* hrefを取得 */
	var showObj = location.href;
	var myData = showObj.split('/');
	myData = myData[myData.length-1];
	re = new RegExp('#');
	if(myData.match(re)){
		myData = myData.split('#')[0];
	}

	var hrefList =[];
	$('a',obj).each(function(i){
		hrefList[i] = $(this).attr('href');
	});
	
	for (var i = 0; i < hrefList.length; i++) {
		if(hrefList[i]===myData){
			var activeObj = $('a',obj).eq(i);
			var activeObjParent = activeObj.parents('li');
			activeObj.addClass('active');
			if(activeObjParent.hasClass('has-child')){
				activeObjParent.removeClass('has-child');
			}
		}
	}
}

/* ----------------------------------------------------- */
/*　ロールオーバー（オーバー画像に差し替えVer)　*/
/* ----------------------------------------------------- */
var Rollover = function(obj,thisSrc) {
	/* 変数宣言 */
	re = new RegExp('_o[\.]');
	re02 = new RegExp('_a');

	var sTempSrc = thisSrc;
	var ftype = thisSrc.substring(thisSrc.lastIndexOf('.'), thisSrc.length);
	var hsrc = thisSrc.replace(ftype, '_o'+ftype);	
	var aPreLoad = new Image();

	/* プリロード */
	aPreLoad.src = hsrc;
	
	if(!sTempSrc.match(re)){
		$(obj).attr('src', hsrc);
	}
	
	if (sTempSrc.match(re)) {
		if(ftype.match(re02)){
			ftype02 = ftype.split('_a')[0];
			sTempSrc = $(obj).attr('src').replace('_o'+ftype02,  '_a' +ftype02);
		}else{
			sTempSrc = $(obj).attr('src').replace('_o'+ftype, ftype);
		}
		$(obj).attr('src', sTempSrc);
	}
}
