/*
 * jcommon.js 1.2
 * Copyright (c) 2010 C.M.A. Co.,Ltd.
 *
 * Last Added: 2010-07-09
 *
 */

//GoogleAnalytics
var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-23753845-1']); 
_gaq.push(['_setDomainName', 'none']); 
_gaq.push(['_setAllowLinker', true]); 
_gaq.push(['_trackPageview']);
(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();

//Utility
var absPath,sharePath = '/shared',isIE='\v'=='v',isIE6=(navigator.userAgent.indexOf("MSIE 6")>=0)?true:false,isWebKit = navigator.userAgent.match(/WebKit/),isLinkAry = location.pathname.split('/').slice(1),jcommon={preloader:{loadedImages:[],load:function(a){var b=this.loadedImages,c=b.length;b[c]=new Image;b[c].src=a}},URIExp:new RegExp("^[https]*[^a-z]*"+document.domain),URI:function(a){this.absolutePath=a.replace(jcommon.URIExp,"").replace(/^[^a-z]*/,"").replace(/index.*$/,"").replace(/\/$/,"");this.len=isLinkAry.length;for(this.isSelfLink=false;this.len--&&!this.isSelfLink;)this.isSelfLink=this.isSelfLink||this.absolutePath==isLinkAry[this.len]},addLinkAry:function(){for(var a=0,b=isLinkAry.length;a<
b;)isLinkAry.push(isLinkAry.slice(0,++a).join("/").replace(/^\//,"").replace(/index.*$/,""))}};jcommon.addLinkAry();switch(true){case location.host.split('.')[1]===('apkisndov'+40*50).replace(/[p-z]/g,''):absPath = '/'+(location.pathname.split('/')[1]);var isBeta = true;break;case location.protocol==='file:':absPath = (isIE?'':'/')+('IYK:M/HOtMdoNcRs/X').replace(/[I-X]/g,'')+(location.pathname.split('/')[3])+'/www/\u4f5c\u696d\u7528';var isBeta = true;break; default:absPath = '';break;}

//ロールオーバー
$.fn.addRollOver=function(add){$(this).filter('img').each(function(){$(this).runRollOver(add,$(this));}).end().not('img').each(function(){$(this).runRollOver(add,$(this).find('img'));});};
$.fn.runRollOver=function(add,target){$(this).each(function(num){this.originalSrc=String(target.attr('src'));this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");}).hover(function(){target.attr('src',this.rolloverSrc);},function(){target.attr('src',this.originalSrc);});};
//現在のページへのリンク
$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(this).unbind('mouseenter');$(this).unbind('mouseleave');$(this).find('img').each(function(){$(this).unbind('mouseenter');$(this).unbind('mouseleave');this.currentSrc=this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/,add+"$1");$(this).attr('src',this.currentSrc)});}});};	
//ページ全体にリンク
$.fn.groupLink=function(){$(this).css({cursor:'pointer'}).hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){location.href=$(this).find('a:last').attr('href');return false})}

$(function(){

	//IE6のPNG
	if(isIE6){
		DD_belatedPNG.fix('#flowNum,.interview .entry,.interview .box');
	}
	
	//beta
	if(isBeta){
		$('a[href^="/"]').each(function(){var url = $(this).attr('href');$(this).attr('href',absPath+url);});
		$('img[src^="/"]').each(function(){var url = $(this).attr('src');$(this).attr('src',absPath+url);});
	}
	
	//ロールオーバー
	$('a img.btn,a.btn,#globalNav li a,#tabControl li a,#bnrContact a').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://117.104.148.195"],[href^="http://www2.akindo2000.net/sato-kogyo/"],[href^="http://www.skfloor.com/"],[href^="https://skflo352.securesites.com/"],[href^="http://www2.akindo2000.net/sato-kogyo/"])').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	});
	//oddとevenを追加
	$('li, #polIndex .infoTable tr, .products .infoTable tr').filter(':odd').addClass('even').end().filter(':even').addClass('odd');
	//連番nxxxをクラスとして追加
	$('body#proIndividual #main .section .photoArea dd ul li').each(function(num){
		$(this).addClass('n'+(++num));
	});
	$('body#proIndex #main .section li').each(function(num){
		$(this).addClass('n'+(++num));
	});
	//ブログ読み込み
	if($('body#home').length){
		$('dl','#hNews').load(absPath + '/shared/module/news_index.html');		
	}
	if($('body#supIndex').length){
		$('ul','#flooring').load(absPath + '/shared/module/news_flooring.html');
		$('ul','#sickhouse').load(absPath + '/shared/module/news_sickhouse.html');
	}
	//全体にリンク
	
	//タブ
	$('#hSearch,#hSearch2').each(function(){
		var tabWrapper = $(this);
		var targetTab = location.hash;
		var i = 0;
		var len = $('#tabControl>li').length;
		while(i<len){
			if($('body[class*="cat0'+(i+1)+'"]').length) targetTab = '#tab0'+(i+1);
			i++;
		}
		$(this).find('.tab').hide();
		if(targetTab == ''||targetTab == '#top'||targetTab == '#content'){
			targetTab = $(this).find('.selected a').attr('href');
		}else{
			window.scrollTo(0,0); 
			$(this)
				.find('#tabControl li').removeClass('selected')
				.find('a[href="'+targetTab+'"]').parent().addClass('selected');
		}
		$(targetTab).show();
		$(this).find('#tabControl a').click(function() {
			targetTab = $(this).attr('href');
			tabWrapper.find('.tab').hide();
			tabWrapper.find('#tabControl li').removeClass('selected');
			$(this).parent().addClass('selected');
			$(targetTab).show();
			return false;
		});
	});
	//親要素全部リンク
	$('body#proIndex #main .section .tree li a').each(function(){
	var Href = $(this).attr('href');
	var section = $(this).parent().parent();
	$(section).css('cursor','pointer');
	$(section).click(function() {
    window.open(Href,'_top');
    return false;
				
	});
	});
	$('body#proIndex #main .section .tree li').hover(function(){
    $(this).addClass('hover');
	},function(){
    $(this).removeClass('hover');
	});

});
