// ****************************************************************
//   
//   汎用スクリプト
//   
// ****************************************************************



/* *
/* easingの追加
 */
jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};


jQuery(function($){

	/* *
	/* フローティング機能のIE6用調整
	 */
	$('#bottom_features_floating').exFixed({
		baseNode : '#wrapper',
		bottom : 0,
		right : 0,
		baseY : false
	});
	
	/* *
	/* 別ウィンドウを開く
	 */
	$("a.newwin").click(function(){
		window.open(this.href,'_blank');
		return false;
	});
	
	/* * 
	/* ターゲットTOPを開く
	 */
	$("a.topwin").click(function(){
		window.open(this.href,'_top');
		return false;
	});


	/* * 
	/* thickboxの初期設定
	 */
	//$("a.thickbox").thickbox();


	/* *
	/* <a href="#***">の場合、スクロール処理を追加
	 */
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 900, 'quart');
				return false;
			}
		}
	});
	
	
	/* *
	/* グローバルメニューのプルダウン処理
	 */
	$('#ope_submenu').hide();
	$('#surgery_info_submenu').hide();
	
	setGlobalPullDown('ope_submenu_op','ope_submenu');
	setGlobalPullDown('surgery_info_submenu_op','surgery_info_submenu');
	
	function setGlobalPullDown(id,s){
		$('#wrapper_global #' + id).hover(
			function(){
				$('#' + s).show();
			},
			function(){
				$('#' + s).hide();
			}
		);
	}
	
	
	/* *
	/* フッターメニューの展開
	 */
	$('#fmenu_open').toggle(
		function(){
			$('#fmenu_open img').attr("src","/images/common/btn_footer_menu_close.gif");
			$('#fmenu_contents').slideDown(300);
			var targetOffset = $('#fmenu_open').offset().top;
			$('html,body').animate({ scrollTop: targetOffset }, 300);
			return false;
		},
		function(){
			$('#fmenu_open img').attr("src","/images/common/btn_footer_menu.gif");
			$('#fmenu_contents').slideUp(300);
		}
	);
	
	
	/**
	/* 右メニューの開閉処理
	 */

	//id+「-area」のDIV内にある ulを指定件数以上の時に展開可能とする
	
	ExpandInit("expand-soc",2);//学会活動
	ExpandInit("expand-ex" ,3);//体験談
//	ExpandInit("expand-ope",3);//おすすめ施術
	ExpandInit("society-eyes" ,5);//学会：目もと
	ExpandInit("society-nose" ,5);//学会：鼻
	ExpandInit("society-mouth" ,5);//学会：口
	ExpandInit("society-face" ,5);//学会：輪郭
	ExpandInit("society-bust" ,5);//学会：バスト
	ExpandInit("society-liposuction" ,5);//学会：脂肪吸引
	ExpandInit("society-bustup" ,5);//学会：豊胸
	ExpandInit("society-smallface" ,5);//学会：小顔
	ExpandInit("society-petit" ,5);//学会：プチ整形
	ExpandInit("society-slim" ,5);//学会：痩身
	ExpandInit("society-aging" ,5);//学会：エイジングケア
	ExpandInit("society-skincare" ,5);//学会：スキンケア
	ExpandInit("society-other" ,5);//学会：その他
	ExpandInit("society-publish" ,5);//学会：その他の発表
	
	function ExpandInit(exid,num){
		var n = num-1;
		var l = $("#" + exid + "-area > ul > li").length;
		if(l > n){
			$("#" + exid + "-area > ul > li:gt("+n+")").css("display", "none");
			$("#"+exid).toggle(
				function (){
					$(this).text("閉じる");
					$("#" + exid + "-area > ul > li:gt("+n+")").show();
				},
				function (){
					$(this).text("すべて見る");
					$("#" + exid + "-area > ul > li:gt("+n+")").hide();
				}
			);
		}else{
			$("#"+exid).hide();
		}
	}


	/* *
	/*  コンテンツ内の空DIV削除
	 */
	$("div#ope_detail_area_ins .ope_detail_area_box:empty").remove(); //施術全般	
	$("div#exp_detail_area_left .user_handwriting:empty").remove();//体験談詳細：直筆体験談
	$("div#exp_detail_area_right .user_video .user_before_video:empty").remove();//体験談詳細：術前動画
	$("div#exp_detail_area_right .user_video .user_after_video:empty").remove();//体験談詳細：術後動画
	
	/* *
	/*　右メニューのライン消し
	 */
	
	$('#body_right_menu .manu_box:last').css({backgroundImage:'none', paddingBottom:0});
	$('#body_right_menu .exp_list ul:last').css({backgroundImage:'none', paddingBottom:0});	
	
	
	/* *
	/*　体験談のBAが<br />だけの場合は削除
	 */
	var url=document.URL;
	if(url.indexOf("/exp/") > 1 || url.indexOf("exp.php") > 1){
		$(".ex-list-doctor dd").each(function(){
			var html = $(this).html().replace(/\s+$/,"");
			if(html == "<br>" || html == "<BR>"){
				$(this).parent().hide();
			}
		});
	}


});


/**
/*  フォントサイズの変更
 */
$(function(){

	//フォントサイズの指定
	var fs_small  = '93%';
	var fs_middle = '100%';
	var fs_large  = '123%';
	
	//初期値
	var fs_default = 'middle';

	//クッキーが食べたい！
	if($.cookie('fs_cookie')) fs_default = $.cookie('fs_cookie');	
	
	//フォントサイズの変更
	var fontSizeSet = function(size){
		
		if(size == 'small'){
			$('#contentsarea').css('font-size', fs_small);
		}
		if(size == 'middle'){
			$('#contentsarea').css('font-size', fs_middle);
		}
		if(size == 'large'){
			$('#contentsarea').css('font-size', fs_large);
		}
		$('#bottom_features_floating_ins .fontsize a span').removeAttr('class');
		$('#bottom_features_floating_ins .fontsize a.'+ size +' span').attr('class', 'active');
		
		$.cookie('fs_cookie', size); //cookieをセット

	}
	
	//ハンドラ
	$('#bottom_features_floating_ins .fontsize a').click(function(){
		var fontsize_class = $(this).attr('class');
		fontSizeSet(fontsize_class);
	});
	
	//初期値の実行
	fontSizeSet(fs_default);
	
});



$(function(){
	$('#features_print').click(
		function(){
			//$('#contentsarea').print();
			//return( false );
			window.print();
		}
	);
});



/**
/*  ヘッダーのコンバージョンswf配置
 */
 
function setCvSwf(p){
	var flashvars={p_color:p};
	var params={menu:'false',wmode:'transparent'};
	var attributes={};
	swfobject.embedSWF("/common/swf/cv_header.swf","conversion_link","240","310","8",false,flashvars,params,attributes);
}


/**
/*  ポップアップ
 */
 
 function popup(sLocation,sWindowName,sWidth,sHeight,sScroll){
	var setMenubar = "no";
	var setToolbar = "no";
	var setLocation = "yes";
	var setDirectories = "no";
	var setStatus = "yes";
	var setResizable = "yes";
	
	var setScrollbars;
	
	if(sScroll == 0){
		setScrollbars = "no";
	}else if(sScroll == 1){
		setScrollbars = "yes";
	}
	

	//var setCondition = "width=" + sWidth + ",height=" + sHeight + ",left=" + sLeft + ",top=" + sTop + ",menubar=" + setMenubar + ",toolbar=" + setToolbar + ",location=" + setLocation + ",directories=" + setDirectories + ",status=" + setStatus + ",scrollbars=" + setScrollbars + ",resizable=" + setResizable;
	
	var setCondition = "width=" + sWidth + ",height=" + sHeight + ",menubar=" + setMenubar + ",toolbar=" + setToolbar + ",location=" + setLocation + ",directories=" + setDirectories + ",status=" + setStatus + ",scrollbars=" + setScrollbars + ",resizable=" + setResizable;
	
	var setWindow = window.open(sLocation, sWindowName, setCondition);
	setWindow.focus();
	return false;
}

