$(function() {
	var pathname= location.pathname;
	var target = pathname.match("^/(.+)/$"); 
	if(target) {
		var localTarget = target[1].match("([a-z0-9]+)$");
		var src = $('#gnavi .parent .' + target[1] + ' a img').attr('src');
		var localSrc = $('#sub .local .' + localTarget[1] + ' a img').attr('src');
		if(src) {
			$('#gnavi .' + target[1] + ' a img').attr('src', src.replace(/\.jpg/, "_on.jpg"));
		}
		if(localSrc) {
			$('#sub .local .' + localTarget[1] + ' a img').attr('src', localSrc.replace(/\.jpg/, "_on.jpg"));
		}
	}
	
	target = pathname.match("^/(products)/.*$");
	if(target) {
		// tab
		$('#tab a img').each(function() {
			$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_cur$2"));
		});
		if($('#tab').size() > 0){
			$('.section#contents01').show();
			$('#tab a img').rollover();
			$('#tab a:first img').attr('src', $('#tab a:first img').attr('src').replace(/(_on)?\.jpg/, "_cur.jpg"));
			$('#tab a:first img').unbind('mouseenter').unbind('mouseleave');
			$('#tab a').each(function() {
				$(this).click(function() {
					$('.section').hide();
					$('#tab a').each(function() {
						$('img', this).attr('src', $('img', this).attr('src').replace(/_cur\.jpg/, ".jpg"));
						$('#tab a img').rollover();
					})
	
					$($(this).attr('href')).show();
					$('img', this).attr('src', $('img', this).attr('src').replace(/(_on)?\.jpg/, "_cur.jpg"));
					$('img', this).unbind('mouseenter').unbind('mouseleave');
					return false;
				});
			});
		}
	}
	
	$("#gnavi a img[src*='on']").rollover();
	$('.btn a img').rollover();
    $('form input:image').rollover();
	$("#sub .local a img").rollover();
	$("#sub .products a img").rollover();
	$("#products .product a img").rollover();
	$("#right .block .banner a img").rollover();
	$(".pagetop a img").rollover();
	
	//gnavi dropdown menu
	$('#gnavi .products, #gnavi .company, #gnavi .recruit').hover(
		function() {
			$('.childs', this).show();
		},
		function() {
			$('.childs', this).hide();
		}
	);
	
	//MighySPD baloon
	target = pathname.match("^/products/(04_spd)/.*$");
	if(target) {
		if(target[1] == '04_spd') {
			$('.imageWrapper li img').each(function() {
				$(this).hover(
					function() {
						$(this).css('opacity', '0.5');
						$('.baloon li').hide();
						var index = $('.imageWrapper li img').index(this);
						$('.baloon li:eq(' + index + ')').show();
						return false;
					},
					function() {
						$(this).css('opacity', '1');
						$('.baloon li').hide();
						return false;
					}
				);
			});
		}
	}
	
	//clicable image 
	$('#Map area').click(function() {
		//他システム連携
		if($(this).attr('href') == '#contents04') {
			$('.section').hide();
			$('#tab a img[src*=\'cur\']').attr('src', $('#tab a img[src*=\'cur\']').attr('src').replace(/_cur\.jpg/, ".jpg"));
			$('a[href=#contents04] img').attr('src', $('a[href=#contents04] img').attr('src').replace(/\.jpg/, "_cur.jpg"));
			$('.section#contents04').show();
			$('#tab a img').rollover();
			$('#tab a img[src*=\'cur\']').unbind('mouseenter').unbind('mouseleave');
		}
		//経営改善支援機能付
		if($(this).attr('href') == '#contents03') {
			$('.section').hide();
			$('#tab a img[src*=\'cur\']').attr('src', $('#tab a img[src*=\'cur\']').attr('src').replace(/_cur\.jpg/, ".jpg"));
			$('a[href=#contents03] img').attr('src', $('a[href=#contents03] img').attr('src').replace(/\.jpg/, "_cur.jpg"));
			$('.section#contents03').show();
			$('#tab a img').rollover();
			$('#tab a img[src*=\'cur\']').unbind('mouseenter').unbind('mouseleave');
		}
		//Mighty SPD
		if($(this).attr('href') == '#contents02') {
			$('.section').hide();
			$('#tab a img[src*=\'cur\']').attr('src', $('#tab a img[src*=\'cur\']').attr('src').replace(/_cur\.jpg/, ".jpg"));
			$('a[href=#contents02] img').attr('src', $('a[href=#contents02] img').attr('src').replace(/\.jpg/, "_cur.jpg"));
			$('.section#contents02').show();
			$('#tab a img').rollover();
			$('#tab a img[src*=\'cur\']').unbind('mouseenter').unbind('mouseleave');
		}
	});
	

	
	//DPC PDF disable
	target = pathname.match("^/products/10_mcdpc/.*$");
	if(target) {
		$('#pamphletPdf').remove();
		$('#productsContact').css('float', 'none');
		$('#productsContact').css('margin', '0 auto');
	}
});

