$(document).ready(function() {
	$(".lineup").show();
	$(".cbox1").show();
	
	var c_url = 'http://www.okuchiesthe.jp/';
	
	//fancybox--------------------
	$(".cbox1").fancybox();
	
	//透過キャンバス追加
	function addContainer(){
		var bodyHeight = $("#wrapper").height();
		if($.browser.opera){
			//$("body").css({"overflow-x":"hidden"});
		}
		if($.browser.msie && $.browser.version == 7){
			//$("body").css({"overflow-x":"hidden"});
		}
		
		$("#container_top").before('<div id="container"></div>');
		$("#container").css({
			opacity: 0,
			"height": bodyHeight
		});
		bodyHeight -= 55;
		$("#menu").css({"height": bodyHeight});
	}
	
	function resizeContainer(){
		var bodyHeight = $("#wrapper").height();
		$("#container").css({"height": bodyHeight});
		$("#menu").css({"height": bodyHeight});
	}
	
	$(window).bind("load", addContainer);
	$(window).bind("resize", resizeContainer);
	
	
	//ラインナップ--------------------
	var ocflag = 0;
	var speed = 300;
	
	$('.lineup').click(function() {
		if(ocflag == 0){
			$("#container_top").stop(true, false).animate({
				paddingLeft: "950px"
			}, speed );
			
			$("#container").stop(true, false).animate({ 
				opacity: 0.9
			}, speed ).css({zIndex:'8'});
			
			
			$("#container").hover(function(){
				//$(this).stop(true, false).fadeTo("fast", 0.5);
				$(this).css({"opacity": "0.85"});
			},function(){
				//$(this).stop(true, false).fadeTo("normal", 0.1);
				$(this).css({"opacity": "0.9"});
			});
			
			$("#lineup_in").stop(true, false).animate({ 
				marginLeft: "0px"
			}, speed );
			$("#lineup").css({zIndex:'9'});
			$(this).html('<img src="'+c_url+'icons/commons/btn_lineupclose_off.gif" alt="製品ラインアップ" width="202" height="25" />');
			ocflag = 1;
			
			$("#container").addClass('cous1');
			
			
			$("#container").click(function() {
				if(ocflag == 1){
					$("#container_top").stop(true, false).animate({ 
						//opacity: 1,
						paddingLeft: "210px"
					}, speed );
					$("#container").stop(true, false).animate({ 
						opacity: 0
					}, speed ).css({zIndex:'4'});
					$("#lineup_in").stop(true, false).animate({ 
						marginLeft: "-740px"
					}, speed );
					$("#lineup").css({zIndex:'5'});
					$('.lineup').html('<img src="'+c_url+'icons/commons/btn_lineup_off.gif" alt="製品ラインアップ" width="202" height="25" />');
					ocflag = 0;
			
					$("#container").removeClass('cous1');
					$("#container").unbind("mouseenter").unbind("mouseleave").unbind("click");
			
					smartRollover();
				}
		
				return false;
			});
			
			
			
		} else {
			$("#container_top").stop(true, false).animate({ 
				paddingLeft: "210px"
			}, speed );
			$("#container").stop(true, false).animate({ 
				opacity: 0
			}, speed ).css({zIndex:'4'});
			$("#lineup_in").stop(true, false).animate({ 
				marginLeft: "-740px"
			}, speed );
			$("#lineup").css({zIndex:'5'});
			$(this).html('<img src="'+c_url+'icons/commons/btn_lineup_off.gif" alt="製品ラインアップ" width="202" height="25" />');
			ocflag = 0;
			
			$("#container").removeClass('cous1');
			$("#container").unbind("mouseenter").unbind("mouseleave").unbind("click");
			
		}
		smartRollover();
		return false;
	});
	
	$('.cous1').click(function() {
		if(ocflag == 1){
			$("#container_top").stop(true, false).animate({ 
				//opacity: 1,
				paddingLeft: "210px"
			}, speed );
			$("#container").stop(true, false).animate({ 
				opacity: 0
			}, speed ).css({zIndex:'4'});
			$("#lineup_in").stop(true, false).animate({ 
				marginLeft: "-740px"
			}, speed );
			$("#lineup").css({zIndex:'5'});
			$('.lineup').html('<img src="'+c_url+'icons/commons/btn_lineup_off.gif" alt="製品ラインアップ" width="202" height="25" />');
			ocflag = 0;
			
			$("#container").removeClass('cous1');
			$("#container").unbind("mouseenter").unbind("mouseleave").unbind("click");
			
			smartRollover();
		}
		
		return false;
	});
	
	
	$('.lineuplink').click(function() {
		if(ocflag == 0){
			$("#container_top").stop(true, false).animate({
				paddingLeft: "950px"
			}, speed );
			
			$("#container").stop(true, false).animate({ 
				opacity: 0.9
			}, speed ).css({zIndex:'8'});
			
			
			$("#container").hover(function(){
				$(this).css({"opacity": "0.85"});
			},function(){
				$(this).css({"opacity": "0.9"});
			});
			
			$("#lineup_in").stop(true, false).animate({ 
				marginLeft: "0px"
			}, speed );
			$("#lineup").css({zIndex:'9'});
			$('.lineup').html('<img src="'+c_url+'icons/commons/btn_lineupclose_off.gif" alt="製品ラインアップ" width="202" height="25" />');
			ocflag = 1;
			
			$("#container").addClass('cous1');
			
			
			$("#container").click(function() {
				if(ocflag == 1){
					$("#container_top").stop(true, false).animate({ 
						paddingLeft: "210px"
					}, speed );
					$("#container").stop(true, false).animate({ 
						opacity: 0
					}, speed ).css({zIndex:'4'});
					$("#lineup_in").stop(true, false).animate({ 
						marginLeft: "-740px"
					}, speed );
					$("#lineup").css({zIndex:'5'});
					$('.lineup').html('<img src="'+c_url+'icons/commons/btn_lineup_off.gif" alt="製品ラインアップ" width="202" height="25" />');
					ocflag = 0;
			
					$("#container").removeClass('cous1');
					$("#container").unbind("mouseenter").unbind("mouseleave").unbind("click");
			
					smartRollover();
				}
		
				return false;
			});
			
			
			
		}
		smartRollover();
		return false;
	});
	
	
	
	//ニュース--------------------------
	$('.cous2').toggle(function(){
		$('.ocnews').css({'height': '140px', 'overflow': 'auto'});
		$('#main').css("background-image","url('../icons/top/bg_news_open.jpg')");
		$(this).attr({"src": "../icons/top/btn_allclose_off.gif", "alt": "一覧を閉じる" });
		addContainer();
	},function(){
		$('.ocnews').css({'height': '20px', 'overflow': 'hidden'});
		$('#main').css("background-image","url('../icons/top/bg_news_close.jpg')");
		$(this).attr({"src": "../icons/top/btn_allopen_off.gif", "alt": "すべてを表示" });
		addContainer();
	});
	
	//アコーディオン--------------------
	var lochref = $(location).attr('href');
	var basic = c_url + 'basic-plus.html';
	var whitening = c_url + 'whitening.html';
	var treatment = c_url + 'treatment.html';
	$('.accordion').each(function(){
		if(lochref == basic || lochref == whitening || lochref == treatment){
			$(this).show();
			$('.accordion_toggle').parent().addClass('current');
		} else {
			$(this).hide();
		}
	});
	
	$('.accordion_toggle').click(function() {
		$('.accordion_toggle').siblings('ul').stop(true, true);
		if($(this).parent().hasClass('current')) {
			$(this).siblings('ul').slideUp('fast');
			$(this).parent().removeClass('current');
		} else {
			$('.accordion').each(function(){
				$(this).slideUp('fast');
				$('.accordion_toggle').parent().removeClass('current');
			});
			$('.accordion_toggle').parent().each(function(){
				$(this).removeClass('current');
			});
			$(this).siblings('ul').slideToggle('fast');
			$(this).parent().toggleClass('current');
		}
		return false;
	});
	
	
	//スライドショー--------------------------
	var total = 0;
	var num = 0;
	var backnum = 0;
	var baf = 0;
	
	$('.slideImg', this.group).each(function(){
		$(this).hide();
		$(this).css({"z-index": "0"});
		total++;
	}).filter(':eq(0)').css({"z-index": "1"}).fadeIn("slow");
	
	if(total > 1){
		setInterval(newsF,6500);
		var html = '<ul id="num">';
		for (var i = 1; i < total+1; i++){
			html += '<li class="'+i+'">0'+i+'</li>';
		}
		html += '</ul>';
		
		$('#slideimg').append(html);
	}
	
	
	$('#num > li', this.group).each(function(){
		$(this).click(function() {
			
			$('.slideImg', this.group).each(function(){
				$(this).hide();
			});
			
			$('#num > li', this.group).each(function(){
				$(this).css({
					'color': '#d3001e',
					'background-color': '#fff',
					'border': '1px solid #e5e5e5'
				});
			});
			
			num = ~~$(this).attr('class');
			num--;
			if( num == total ){
				num = 0;
			}
			
			if(num == 0){
				backnum = (total-1);
			} else {
				backnum = (num-1);
			}
			
			$('.slideImg', this.group).each(function(){
					$(this).css({"z-index": "0"});
			});
			$('.slideImg', this.group).filter(':eq('+num+')').css({"z-index": "1"});
			$('.slideImg', this.group).filter(':eq('+num+')').stop(false, true).fadeIn();
			
			$('#num > li', this.group).filter(':eq('+num+')').css({
				'color': '#fff',
				'background-color': '#d3001e',
				'border': '1px solid #d3001e'
			});
			
		});
		
	}).filter(':eq(0)').css({
		'color': '#fff',
		'background-color': '#d3001e',
		'border': '1px solid #d3001e'
	});
	
	
	function newsF(){
	
		if( num < (total - 1)){
			num++;
		} else {
			num = 0;
		}
		
		if(num == 0){
			backnum = (total-1);
			
		} else {
			backnum = (num-1);
		}
		
		$('.slideImg', this.group).filter(':eq('+backnum+')').css({"z-index": "1"});
		$('.slideImg', this.group).filter(':eq('+num+')').css({"z-index": "0"});
		
		
		$('.slideImg', this.group).each(function(){
			//$(this).hide();
		}).filter(':eq('+num+')').fadeIn(1500, function(){
			$('.slideImg', this.group).filter(':eq('+backnum+')').fadeOut(1500);
			
			
			$('#num > li', this.group).filter(':eq('+backnum+')').css({
				'color': '#d3001e',
				'background-color': '#fff',
				'border': '1px solid #e5e5e5'
			});
			$('#num > li', this.group).filter(':eq('+num+')').css({
				'color': '#fff',
				'background-color': '#d3001e',
				'border': '1px solid #d3001e'
			});
		});
		
	
	
	}
	
	
	//ツールチップ--------------------
	
	$(".tool > img").hover(function(){
		if($.browser.msie){
			$(this).next('div').show().stop(true, false).animate({ 
				top: "-53px"
			}, 100 );
		}else{
			$(this).next('div').fadeIn().stop(true, false).animate({ 
				opacity: 1,
				top: "-53px"
			}, 100 );
		}
	},function(){
		if($.browser.msie){
			$(this).next('div').hide().stop(true, false).animate({ 
				top: "-49px"
			}, 100 );
		}else{
			$(this).next('div').fadeOut().stop(true, false).animate({ 
				opacity: 0,
				top: "-49px"
			}, 100 );
		}
	});
	
	
	//ポップアップ--------------------
	$(".popup").click(function(){
		window.open(this.href, "iconimg","width=455,height=411,location=no, menubar=yes, resizable=yes, scrollbars=yes, status=yes");
		return false;
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
});
