/*
 * jcommon.js 1.01
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2008-05-14
 *
 */



var ary = location.pathname.split('/');


var l=0;var isLinkAry=new Array;for(i=0;i<=ary.length-1;i++){isLinkAry[i]=ary.slice(i,i+1);isLinkAry[i]=isLinkAry[i].join('/');isLinkAry[i]=isLinkAry[i].replace(/index.*$/,"")}for(k=i+1;k<=i+ary.length;k++){isLinkAry[k]=ary.slice(0,ary.length-l);isLinkAry[k]=isLinkAry[k].join('/');isLinkAry[k]=isLinkAry[k].replace(/^\//,"");isLinkAry[k]=isLinkAry[k].replace(/index.*$/,"");l++}isLinkAry[0]=isLinkAry[0].replace(/\#.*$/,"");var jcommon={preloader:{loadedImages:[],load:function(url){var img=this.loadedImages;var l=img.length;img[l]=new Image();img[l].src=url}},URI:function(path){path=path.replace(/^https[^a-z]*/,"");path=path.replace(/^http[^a-z]*/,"");path=path.replace(document.domain,"");path=path.replace(/^[^a-z]*/,"");path=path.replace(/index.*$/,"");path=path.replace(/\/$/,"");this.absolutePath=path;this.len=isLinkAry.length;this.isSelfLink=false;while(this.len--){this.isSelfLink=this.isSelfLink||(this.absolutePath==isLinkAry[this.len])}}};

/*ロールオーバー*/			$.fn.addRollOver=function(add){$(this).each(function(){this.originalSrc=$(this).attr('src');this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");jcommon.preloader.load(this.rolloverSrc)}).hover(function(){$(this).attr('src',this.rolloverSrc)},function(){$(this).attr('src',this.originalSrc)})}
/*現在のページへのリンク(img)*/	$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(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)})}})}

$(function(){


	//ロールオーバー
	$('a img.btn,#globalNav li a img').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://www.jiseido.co.jp"])').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;
	})

	//ポップアップ 
	$('a.popup').each(function(){
		this.param = $(this).attr("href");
		this.param = this.param.split('?');
		this.param[1] = this.param[1].split('&');
		this.param[1] = this.param[1].join(',')
		$(this).attr("href","");
	}).click(function(){
		this.pu = window.open(this.param[0], 'popup', "toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,"+this.param[1]);
		return false;
	});

	//するするアニメーション 
	$('a[href^="#"]').each(function(){
		this.target = $(this).attr('href');
	}).click(function(){
		$.scrollTo( this.target, {speed:800} );
		return false;
	});

	//ulのliにoddとevenを追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});

	//:first-child(x) :連番nxxxをクラスとして追加
	$('body#flow #mainContent ol li:nth-child(1),#mainContent #cardList li:nth-child(1)').addClass('n001');
	$('body#flow #mainContent ol li:nth-child(2),#mainContent #cardList li:nth-child(2)').addClass('n002');
	$('body#flow #mainContent ol li:nth-child(3),#mainContent #cardList li:nth-child(3)').addClass('n003');
	$('body#flow #mainContent ol li:nth-child(4),#mainContent #cardList li:nth-child(4)').addClass('n004');
	$('body#flow #mainContent ol li:nth-child(5),#mainContent #cardList li:nth-child(5)').addClass('n005');
	$('body#flow #mainContent ol li:nth-child(6),#mainContent #cardList li:nth-child(6)').addClass('n006');
	$('body#flow #mainContent ol li:nth-child(7),#mainContent #cardList li:nth-child(7)').addClass('n007');
	$('body#flow #mainContent ol li:nth-child(8),#mainContent #cardList li:nth-child(8)').addClass('n008');

	//マウスーバー時、画像を半透明にする
	$('a img.alpha').hover(function(){
		$(this).fadeTo(100,0.7);
	},function(){
		$(this).fadeTo(100,1.0);
	});
	
	$('#home #mainContent #newsList').load('http://www.jiseido.co.jp/news/indexlist.html');
	$('#home #mainContent #contL #chirashi').load('http://www.jiseido.co.jp/chirashi/chirashi.html');
});