jQuery.noConflict();
var j$ = jQuery;


// General purpose


// Rollover
/*function imageRollover( className, suffix ){
	this.init( className, suffix );
}

imageRollover.prototype = {

	init : function( className, suffix ){
		if(!document.getElementById || !document.images || !className) return;

		// 
		this.targetClassName = className;
		this.suffix = suffix || 'on';
		this.buttons = [];

		// 
		var _this  = this;
		var imgs   = [];
		var inputs = [];
		var rolloverObj    = [];

		j$("." + this.targetClassName ).each(function(i){
			var el = j$(this);
			if( el.attr("class") == _this.targetClassName && (this.tagName=="IMG" || this.tagName=="INPUT") ){
				rolloverObj.push(this);
			}
		});

		j$.each(rolloverObj, function(i){ _this.registButton(this); });
		this.preloadImages();
	},

	registButton : function( el ){
		var _this = this;
		var btn = new Object();
		btn.src = el.src;
		btn.filetype = btn.src.substring(btn.src.lastIndexOf('.'));
		btn.basename = btn.src.substring(0, btn.src.length-btn.filetype.length);
		btn.onsrc = btn.basename + this.suffix + btn.filetype;

		el.offsrc = btn.src;
		el.onsrc  = btn.onsrc;
		
		this.buttons.push( el );

		j$(el).bind( 'mouseover', function(){ _this.swapImage( el, 'on' ); } );
		j$(el).bind( 'mouseout',  function(){ _this.swapImage( el, 'off'); } );
		if(el.parentNode && el.parentNode.tagName=="A"){
			var p = el.parentNode;
			j$(p).bind( 'focus', function(){ _this.swapImage( el, 'on' ); } );
			j$(p).bind( 'blur',  function(){ _this.swapImage( el, 'off'); } );
		}
	},

	preloadImages : function(){
		var ret = [];
		for( var i=0; i<this.buttons.length; i++ ){
			(new Image()).src = this.buttons[i].onsrc;
			ret[ret.length] = this.buttons[i].onsrc;
		}
	},

	swapImage : function( obj, status ){
		if( !obj || !obj[status+"src"] ) return;
		obj.src = obj[status+"src"];
	}
}


// Execution
/*
j$(function(){
	new imageRollover('rollover','_on');
});
*/



function initRollovers(){
	if (!document.getElementById) return

	var aPreLoad = new Array();
	var sTempSrc;
	
	var inputs = document.getElementsByTagName('input');
	var images=  document.getElementsByTagName('img');
	
	var i;
	
	var aImages=new Array();
	
	for(i=0; i<images.length; i++){
		aImages.push(images[i]);			
	}
	
	for(i=0; i<inputs.length; i++){
		if(inputs[i].getAttribute('type')=='image'){
			aImages.push(inputs[i]);
		}
	}
	
	for ( i = 0; i < aImages.length; i++) { 
		if (aImages[i].className == 'rollover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);

			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;

			aImages[i].onmouseover = function() {
			sTempSrc = this.getAttribute('src');
			this.setAttribute('src', this.getAttribute('hsrc'));
			} 

			aImages[i].onmouseout = function() {
			if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
			this.setAttribute('src', sTempSrc);
			}
		}
	}
}
Event.observe(window, "load", initRollovers, false);




//subNavi activeImage
function setActiveSubNavi(category,page){
	var active=getActiveSubNavi(category,page);

	if(active!=false && active.length>0 ){
		for(var i=0; i<active.length; i++){
			setActiveImg(active[i]);
		}
	}
}

function setActiveImg(idName){
	
	if(!$(idName)){
		return;
	}
	
	var tImages=$(idName).getElementsByTagName('img');
	
	for(var i=0; i<tImages.length; i++){
		
		if(tImages[i].className.indexOf('rollover')!=-1){
			Element.removeClassName(tImages[i],'rollover');
			
			var src = tImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_act'+ftype);
			tImages[i].src=hsrc;
		}
	}
}


function getActiveSubNavi(category,page){

	if(!$('subNaviWrapper') || category=='' || page==''){
		return false;
	}
	
	category=''+category;
	page=''+page;
	
	var activeImages=new Array();

	if(category=='01') category='skincare';
	else if(category=='02') category='basemakeup';
	else if(category=='03') category='colormakeup';
	else if(category=='04') category='suncare_a';
	else if(category=='05') category='others';
	else if(category=='07') category='fragrance';
	else if(category=='08') category='mens';
	else if(category=='09') category='about';
	else if(category=='10') category='faq';
	else if(category=='0004') category='bioperformance';
	else if(category=='0003') category='benefiance';
	else if(category=='0009') category='futuresolution';
	else if(category=='0021') category='whitelucent';
	else if(category=='0020') category='whitelucency';
	else if(category=='0019') category='theskincare';
	else if(category=='0014') category='pureness';
	else if(category=='0008') category='eudermine';
	else if(category=='0025') category='revital';
	else if(category=='0012') category='makeup';
	else if(category=='0018') category='suncare';
	else if(category=='0022') category='zen';
	else if(category=='0023') category='relaxingenergizing';
	else if(category=='0017') category='men';
	else if(category=='0005') category='bodycreator';
	else if(category=='0001') category='adenogen';

	switch(category){
		case 'skincare':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				
				case 'BeautyMethod':
					activeImages.push('linkContenstListBeautyMethod');
				break;
				
				case 'ChooseLines':
					activeImages.push('linkContenstListChooseLines');
				break;
			}
		break;
		case 'basemakeup':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				
				case '11':
					activeImages.push('itemList11');
				break;
				case '42':
					activeImages.push('itemList42');
				break;
				case '45':
					activeImages.push('itemList45');
				break;
				case '46':
					activeImages.push('itemList46');
				break;
				case '47':
					activeImages.push('itemList47');
				break;
				case '43':
					activeImages.push('itemList43');
				break;
				case '12':
					activeImages.push('itemList12');
				break;
				case '13':
					activeImages.push('itemList13');
				break;
			}
		break;
		case 'colormakeup':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'ANewLipstick':
					activeImages.push('linkContenstListANewLipstick');
				break;
				
				case '14':
					activeImages.push('itemList14');
				break;
				case '15':
					activeImages.push('itemList15');
				break;
				case '16':
					activeImages.push('itemList16');
				break;
				case '17':
					activeImages.push('itemList17');
				break;
				case '18':
					activeImages.push('itemList18');
				break;
				case '19':
					activeImages.push('itemList19');
				break;
				case '20':
					activeImages.push('itemList20');
				break;
				case '21':
					activeImages.push('itemList21');
				break;
				case '22':
					activeImages.push('itemList22');
				break;
			}
		break;
		
		case 'suncare_a':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'WhatYouShouldKnowAboutUVRays':
					activeImages.push('linkContenstListWhatYouShouldKnowAboutUVRays');
				break;
				case 'SunSafetyTips':
					activeImages.push('linkContenstListSunSafetyTips');
				break;
				case 'AboutSPFPA':
					activeImages.push('linkContenstListAboutSPFPA');
				break;
				
				case '23':
					activeImages.push('itemList23');
				break;
				case '24':
					activeImages.push('itemList24');
				break;
				case '25':
					activeImages.push('itemList25');
				break;
				case '11':
					activeImages.push('itemList11');
				break;
				case '42':
					activeImages.push('itemList42');
				break;
				case '46':
					activeImages.push('itemList46');
				break;
				case '43':
					activeImages.push('itemList43');
				break;
				
			}
		break;
		
		case 'fragrance':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
			}
		break;
		
		case 'mens':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
			}
		break;
		
		case 'about':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
			}
		break;
		
		case 'faq':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
			}
		break;		
		
		case 'others':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				
				case '26':
					activeImages.push('itemList26');
				break;
				case '27':
					activeImages.push('itemList27');
				break;
				case '28':
					activeImages.push('itemList28');
				break;
				case '29':
					activeImages.push('itemList29');
				break;
				case '30':
					activeImages.push('itemList30');
				break;
				case '31':
					activeImages.push('itemList31');
				break;
				case '32':
					activeImages.push('itemList32');
				break;
				case '33':
					activeImages.push('itemList33');
				break;
			}
		break;
		case 'bioperformance':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				
				case '05':
					activeImages.push('itemList05');
				break;
				case '06':
					activeImages.push('itemList06');
				break;
				case '08':
					activeImages.push('itemList08');
				break;
				case '10':
					activeImages.push('itemList10');
				break;
			}
		break;
		
		case 'benefiance':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'NewProduct':
					activeImages.push('linkContenstListNewProduct');
				break;
				case 'NutriPerfect':
					activeImages.push('linkContenstListNutriperfect');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'SkincareProgram':
					activeImages.push('linkContenstListSkincareProgram');
				break;
				
				
				case '01':
					activeImages.push('itemList01');
				break;
				case '02':
					activeImages.push('itemList02');
				break;
				case '03':
					activeImages.push('itemList03');
				break;
				case '05':
					activeImages.push('itemList05');
				break;
				case '06':
					activeImages.push('itemList06');
				break;
				case '07':
					activeImages.push('itemList07');
				break;
				case '08':
					activeImages.push('itemList08');
				break;
				case '09':
					activeImages.push('itemList09');
				break;
				
				
				case '11':
					activeImages.push('itemList11');
				break;
				case '42':
					activeImages.push('itemList42');
				break;
				case '12':
					activeImages.push('itemList12');
				break;
				case '45':
					activeImages.push('itemList45');
				break;
			}
		break;
		
		case 'futuresolution':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				
				case '05':
					activeImages.push('itemList05');
				break;
				case '06':
					activeImages.push('itemList06');
				break;
			}
		break;
		
		case 'whitelucent':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'SkincareProgram':
					activeImages.push('linkContenstListSkincareProgram');
				break;
				case 'NewProduct':
					activeImages.push('linkContenstListNewProduct');
				break;

				case '01':
					activeImages.push('itemList01');
				break;
				case '02':
					activeImages.push('itemList02');
				break;
				case '03':
					activeImages.push('itemList03');
				break;
				case '04':
					activeImages.push('itemList04');
				break;
				case '06':
					activeImages.push('itemList06');
				break;
				case '07':
					activeImages.push('itemList07');
				break;
				case '08':
					activeImages.push('itemList08');
				break;
				case '09':
					activeImages.push('itemList09');
				break;
				case '10':
					activeImages.push('itemList10');
				break;
				case '42':
					activeImages.push('itemList42');
				break;
				case '12':
					activeImages.push('itemList12');
				break;
			}
		break;
		
		case 'theskincare':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'SkincareProgram':
					activeImages.push('linkContenstListSkincareProgram');
				break;
				
				case '01':
					activeImages.push('itemList01');
				break;
				case '02':
					activeImages.push('itemList02');
				break;
				case '03':
					activeImages.push('itemList03');
				break;
				case '04':
					activeImages.push('itemList04');
				break;
				case '06':
					activeImages.push('itemList06');
				break;
				case '07':
					activeImages.push('itemList07');
				break;
				case '09':
					activeImages.push('itemList09');
				break;
				case '10':
					activeImages.push('itemList10');
				break;
			}
		break;
		
		case 'pureness':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'SkincareProgram':
					activeImages.push('linkContenstListSkincareProgram');
				break;
				
				case '01':
					activeImages.push('itemList01');
				break;
				
				case '02':
					activeImages.push('itemList02');
				break;
				
				case '03':
					activeImages.push('itemList03');
				break;
				
				case '04':
					activeImages.push('itemList04');
				break;
				
				case '10':
					activeImages.push('itemList10');
				break;
				
				case '42':
					activeImages.push('itemList42');
				break;
			}
		break;
		
		case 'eudermine':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'History':
					activeImages.push('linkContenstListHistory');
				break;
				
				case '10':
					activeImages.push('itemList10');
				break;
			}
		break;
		
				case 'revital':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'NewProduct':
					activeImages.push('linkContenstListNewProduct');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'SkincareProgram':
					activeImages.push('linkContenstListSkincareProgram');
				break;
				
				
				case '01':
					activeImages.push('itemList01');
				break;
				case '02':
					activeImages.push('itemList02');
				break;
				case '03':
					activeImages.push('itemList03');
				break;
				case '04':
					activeImages.push('itemList04');
				break;
				case '05':
					activeImages.push('itemList05');
				break;
				case '06':
					activeImages.push('itemList06');
				break;
				case '07':
					activeImages.push('itemList07');
				break;
				case '08':
					activeImages.push('itemList08');
				break;
				case '09':
					activeImages.push('itemList09');
				break;
				case '10':
					activeImages.push('itemList09');
				break;

			}
		break;
		
		case 'suncare':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'WhatYouShouldKnowAboutUVRays':
					activeImages.push('linkContenstListWhatYouShouldKnowAboutUVRays');
				break;
				case 'SunSafetyTips':
					activeImages.push('linkContenstListSunSafetyTips');
				break;
				case 'AboutSPFPA':
					activeImages.push('linkContenstListAboutSPFPA');
				break;
				
				case '23':
					activeImages.push('itemList23');
				break;
				case '24':
					activeImages.push('itemList24');
				break;
				case '25':
					activeImages.push('itemList25');
				break;
				case '11':
					activeImages.push('itemList11');
				break;
				case '42':
					activeImages.push('itemList42');
				break;
				case '46':
					activeImages.push('itemList46');
				break;
				case '43':
					activeImages.push('itemList43');
				break;
			}
		break;
		
		case 'zen':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				case 'Fragrance':
					activeImages.push('linkContenstListFragrance');
				break;
				case 'ThePerfumer':
					activeImages.push('linkContenstListThePerfumer');
				break;
				case 'TheEvaluator':
					activeImages.push('linkContenstListTheEvaluator');
				break;
				case 'VisualMovie':
					activeImages.push('linkContenstListVisualMovie');
				break;
				case 'NewProduct':
					activeImages.push('linkContenstListNewProduct');
				break;
				
				case '34':
					activeImages.push('itemList34');
				break;
				case '48':
					activeImages.push('itemList48');
				break;
			}
		break;
		case 'relaxingenergizing':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				
				case '34':
					activeImages.push('itemList34');
				break;
				case '48':
					activeImages.push('itemList48');
				break;
				case '26':
					activeImages.push('itemList26');
				break;
				case '27':
					activeImages.push('itemList27');
				break;
				case '31':
					activeImages.push('itemList31');
				break;
			}
		break;
		
		case 'bodycreator':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				
				case '26':
					activeImages.push('itemList26');
				break;
				case '28':
					activeImages.push('itemList28');
				break;
				case '29':
					activeImages.push('itemList29');
				break;
			}
		break;
		
		case 'adenogen':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case '33':
					activeImages.push('itemList33');
				break;
			}
		break;
		case 'makeup':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'ANewLipstick':
					activeImages.push('linkContenstListANewLipstick');
				break;
				
				case '11':
					activeImages.push('itemList11');
				break;
				case '42':
					activeImages.push('itemList42');
				break;
				case '45':
					activeImages.push('itemList45');
				break;
				case '46':
					activeImages.push('itemList46');
				break;
				case '47':
					activeImages.push('itemList47');
				break;
				case '43':
					activeImages.push('itemList43');
				break;
				case '12':
					activeImages.push('itemList12');
				break;
				case '13':
					activeImages.push('itemList13');

				break;
				case '14':
					activeImages.push('itemList14');
				break;
				case '15':
					activeImages.push('itemList15');
				break;
				case '16':
					activeImages.push('itemList16');
				break;
				case '17':
					activeImages.push('itemList17');
				break;
				case '18':
					activeImages.push('itemList18');
				break;
				case '19':
					activeImages.push('itemList19');
				break;
				case '20':
					activeImages.push('itemList20');
				break;
				case '21':
					activeImages.push('itemList21');
				break;
				case '22':
					activeImages.push('itemList22');
				break;
			}
		break;
		
		case 'men':
			switch(page){
				case 'Top':
					activeImages.push('linkContenstListTop');
				break;
				case 'NewProduct':
					activeImages.push('linkContenstListNewProduct');
				break;
				case 'Introduction':
					activeImages.push('linkContenstListIntroduction');
				break;
				
				case '39':
					activeImages.push('itemList39');
				break;
				case '40':
					activeImages.push('itemList40');
				break;
				case '41':
					activeImages.push('itemList41');
				break;
			}
		break;
	}
	
	return activeImages;
	
}



//Product finder list

Event.observe(window, "load", function(){productFinderClass.setProductFinderInit();}, false);


var productFinderClass={

	setProductFinderInit:function(){
		var msec = (new Date()).getTime();
		var listXML='/zcom/productfinderlist.xml';
		
		new Ajax.Request(listXML,{parameters:"cache="+msec,method:'get',onSuccess:function(req){productFinderClass.setProductFinder(req)},onFailure :function(req){productFinderClass.errorXML()}});
		
	},
	
	categoryBList:[[['------------','']]],
	
	setProductFinder:function(req){
		if($('ProductFinderWrapper') ||$('bottomProductFinderWrapper')){
			var xml=req.responseXML;
			var categoryA=xml.getElementsByTagName('category_a');
			
			var i;
			for(i=0; i<categoryA.length; i++){
				

				var categoryAText=categoryA[i].getElementsByTagName('category_a_text')[0].childNodes[0].nodeValue;
				var categoryACode=categoryA[i].getElementsByTagName('category_a_code')[0].childNodes[0].nodeValue;
				
				var newOption=document.createElement('option');
				new Insertion.Bottom(newOption,categoryAText);
				
				newOption.value=categoryACode;
				new Insertion.Bottom('productFinderAList',newOption);
					
				
				
				var categoryBTmp=productFinderClass.getProductFinderNodeValue(categoryA[i]);
				
				productFinderClass.categoryBList.push(categoryBTmp);
			}
			$('productFinderAList').disabled=false;
			$('productFinderBList').disabled=false;
			productFinderClass.changeProductFinder();
			
		}
		
	},
	getProductFinderNodeValue:function(pNode){
		
		var categoryB=pNode.getElementsByTagName('category_b');
		
		
		var categoryBTmp=new Array();
		
		var i;
		
		for(i=0; i<categoryB.length; i++){
			
			var categoryBText=categoryB[i].getElementsByTagName('category_b_text')[0].childNodes[0].nodeValue;
			var categoryBCode=categoryB[i].getElementsByTagName('category_b_code')[0].childNodes[0].nodeValue;

			categoryBTmp.push([categoryBText,categoryBCode]);
		}
		
		return categoryBTmp
		
	},
	
	changeProductFinder:function(){
		
		
		var cateA=$('productFinderAList').selectedIndex;
		var cateB=$('productFinderBList');
		
		cateB.innerHTML="";


		var newList=productFinderClass.categoryBList[cateA];

		
		for(var i=0; i<newList.length; i++){
			
			var newOption=document.createElement('option');
			
			newOption.value=newList[i][1];
			new Insertion.Bottom(newOption, newList[i][0]);
			new Insertion.Bottom(cateB,newOption);
		}

		
	},
	errorXML:function(){
		void(0);
		/*alert('error');*/
	}
	
}


function productFinderSubmit(){
	$('productFinderForm').submit();
}





//about Faq 以外にlightwindowをセット
function setEffectJS(){
	var urlText=location.href;
	var setEfectFlag=0;
	

	if(urlText.indexOf('/about/')!=-1){
		setEfectFlag++;
	}
	if(urlText.indexOf('/faq/')!=-1){
		setEfectFlag++;
	}

	if(setEfectFlag==0){
		document.write('<script type="text/javascript" src="/com/js/scriptaculous/scriptaculous.js"></script>');
		document.write('<script type="text/javascript" src="/com/js/scriptaculous/effects.js"></script>');
		document.write('<script type="text/javascript" src="/com/js/lightwindow/lightwindowaddlist.js"></script>');
		document.write('<script type="text/javascript" src="/com/js/lightwindow/lightwindow.js"></script>');
	}
}
setEffectJS();



/******************************
top  news events
******************************/

topNewsEvents={
	openMoreEvents:function(){
		Effect.toggle($('moreList'), 'blind',{duration:0.5,afterFinish: function() {Element.hide('moreBtnOff');Element.show('moreBtnOn');new Effect.ScrollTo('moreBtnOn',{duration:1});}});
	},
	
	closeMoreEvents:function(){
		Effect.toggle($('moreList'), 'blind',{duration:0.5,afterFinish: function() {Element.hide('moreBtnOn');Element.show('moreBtnOff');}});
	}
}


