$(document).ready(function(){

//インデックス お悩み高さ合わせ
$("#index #troublelist li dl dd ul .second").each(function(){
	var $second = $(this);
	var $second_h = $second.height();

	var $first = $(this).prev();
	var $first_h = $first.height();

	if($first_h > $second_h){
		$second.css("height" , $first_h);
	}
	else if($first_h < $second_h){
		$first.css("height" , $second_h - 1);
	}
});

//診療内容 お悩み 高さ合わせ
$("#contents #troublelist .third").each(function(){
	var $third = $(this);
	var $third_h = $third.height();

	var $second = $(this).prev();
	var $second_h = $second.height();

	var $first = $(this).prev().prev();
	var $first_h = $first.height();

	if($first_h > $second_h){
		var $higher = $first_h;
	} else {
		var $higher = $second_h;
	}

	if($higher > $third_h){
		var $highest = $higher;
	} else {
		var $highest = $third_h;
	}

	if($highest != undefined){
		$first.css("height" , $highest);
		$second.css("height" , $highest);
		$third.css("height" , $highest);
	}
});

$("#sitemap #troublelist .third").each(function(){
	var $third = $(this);
	var $third_h = $third.height();

	var $second = $(this).prev();
	var $second_h = $second.height();

	var $first = $(this).prev().prev();
	var $first_h = $first.height();

	if($first_h > $second_h){
		var $higher = $first_h;
	} else {
		var $higher = $second_h;
	}

	if($higher > $third_h){
		var $highest = $higher;
	} else {
		var $highest = $third_h;
	}

	if($highest != undefined){
		$first.css("height" , $highest);
		$second.css("height" , $highest);
		$third.css("height" , $highest);
	}
});

//アコーディオン初期設定
$("#troublelist li dl dd").hide();
$id = $("body").attr("id");
$target = $("body");
$target.removeClass("service");
$target.removeClass("two");

if($id != "index"){
if($target.attr("class") == "condition"){
$id = $target.attr("id");
$target.toggleClass("two");
}
else if($target.attr("id") == "concept" || $target.attr("id") == "contents" || $target.attr("id") == "price" || $target.attr("id") == "prepaiedservice" || $target.attr("id") == "doctor" || $target.attr("id") == "access" || $target.attr("id") == "consultation" || $target.attr("id") == "reservation" || $target.attr("id") == "inquiry" || $target.attr("id") == "sitemap" || $target.attr("id") == "privacypolicy" ){
$target.toggleClass("two");
}
else {
$id = $target.attr("class");
$target.toggleClass("service");
$target.toggleClass("two");
}
}

if($id != ''){
$("li."+$id).addClass("selected");
}

//アコーディオンアニメーション
$acordion = function(){
$("#troublelist li dl dt").removeClass("selected");
$("#troublelist li dl dd:visible").slideUp("slow");
$(this).next().slideDown("slow");
$(this).addClass("selected");
}

//アコーディオン表示ページ設定
$selected = function($genre){
if($genre == "bodydesign"){
$("#troublelist .bodydesign dl dt a").addClass("selected");
}
if($genre == "antiaging"){
$("#troublelist .antiaging dl dt a").addClass("selected");
}
if($genre == "skincare"){
$("#troublelist .skincare dl dt a").addClass("selected");
}
if($genre == "facedesign"){
$("#troublelist .facedesign dl dt a").addClass("selected");
}
if($genre == "others"){
$("#troublelist .others dl dt a").addClass("selected");
}
}

if($id == "diet" ||$id == "arms-thinning" || $id == "breast-augmentation" || $id == "breast-reduction-lift" || $id == "gynecomastia" || $id == "back-flab" || $id == "waist-slender" || $id == "hip-small" || $id == "hip-up" || $id == "thigh-thinning" || $id == "legs-slimming" || $id == "knee-around" || $id == "foot-slimming" || $id == "waist-around" || $id == "two-pack-stomach" || $id == "six-pack-stomach" || $id == "modification"){
$("#troublelist #bodydesign dl dt").addClass("selected");
$("#troublelist #bodydesign dl dd").show();
$("#troublelist li dl dt").click($acordion);
}
else if($id == "forehead-wrinkles" || $id == "forehead-depression" || $id == "glabella-wrinkles" || $id == "eye-sunken" || $id == "sp-sagging" || $id == "ip-sagging" || $id == "eyes-sagging" || $id == "crowsfeet" || $id == "eyes-wrinkles" || $id == "temple-depression" || $id == "cheek-sagging" || $id == "cheek-thinning" || $id == "nasolabial-fold" || $id == "mouth-wrinkles" || $id == "chin-double" || $id == "neck-sagging" || $id == "hand-p-w" || $id == "internal-rejuvenation"){
$("#troublelist #antiaging dl dt").addClass("selected");
$("#troublelist #antiaging dl dd").show();
$("#troublelist li dl dt").click($acordion);
}
else if($id == "pigmentation" || $id == "melasma" || $id == "wrinkle" || $id == "elasticity-complexion" || $id == "texture" || $id == "pore" || $id == "acne" || $id == "acne-scar-redness" || $id == "acne-scar-depression" || $id == "skin-darkish" || $id == "redness" || $id == "traumatic-scars" || $id == "nevus-warts" || $id == "eye-darkcircle"){
$("#troublelist #skincare dl dt").addClass("selected");
$("#troublelist #skincare dl dd").show();
$("#troublelist li dl dt").click($acordion);
}
else if($id == "palpebra-design" || $id == "nose-design" || $id == "mouth-design" || $id == "lip-design" || $id == "jaw-design" || $id == "faceline-design"){
$("#troublelist #facedesign dl dt").addClass("selected");
$("#troublelist #facedesign dl dd").show();
$("#troublelist li dl dt").click($acordion);
}
else if($id == "mammillaplasty" || $id == "vagina-plasticsurgery" || $id == "protrudingear-surgery" || $id == "dimpling" || $id == "protrudingnavel-surgery" || $id == "stretchmarks" || $id == "axillary-osmidrosis" || $id == "hair-removal" || $id == "hair-growth" || $id == "circulation"){
$("#troublelist #others dl dt").addClass("selected");
$("#troublelist #others dl dd").show();
$("#troublelist li dl dt").click($acordion);
}
else {
$("#troublelist li dl dd").show();
}

//アンカーリンクスライドアニメーション
$("#pagetop a").click(function() {
$("#container").ScrollTo(700, 'easeout');
return false;
});

$(".cnavi .trouble a").click(function(){
$("#trouble").ScrollTo(500, 'easeout');
return false;
});

$(".cnavi .service a").click(function(){
$("#service").ScrollTo(700, 'easeout');
return false;
});

$(".cnavi .yamakawa a").click(function(){
$("#yamakawa").ScrollTo(700, 'easeout');
return false;
});

$(".cnavi .ohashi").click(function(){
$("#ohashi").ScrollTo(500, 'easeout');
return false;
});

$(".cnavi .fukuoka").click(function(){
$("#fukuoka").ScrollTo(500, 'easeout');
return false;
});

$(".cnavi .tokyo").click(function(){
$("#tokyo").ScrollTo(700, 'easeout');
return false;
});

//リンク新規ウィンドウ表示
$(".blank").click(function(){
	window.open(this.href, '_blank');
	return false;
});

//無料ドクターメール相談
$('.blank2').click(function(){
var ua = $.browser;

if(ua.msie){
window.open($(this).attr('href') , '' , 'width=579 , height=771 , resizable=no , scrollbars=yes');
}
else {
window.open($(this).attr('href') , '' , 'width=577 , height=771 , resizable=no , scrollbars=yes');
}
return false;
});

//モニター
$('.blank3').click(function(){
var ua = $.browser;

if(ua.msie){
window.open($(this).attr('href') , '' , 'width=579 , height=922 , resizable=no , scrollbars=yes');
}
else {
window.open($(this).attr('href') , '' , 'width=577 , height=922 , resizable=no , scrollbars=yes');
}
return false;
});

//マップポップアップ
$('a.map').click(function(){
var ua = $.browser;

if(ua.msie){
window.open($(this).attr('href') , '' , 'width=722 , height=810 , resizable=no , scrollbars=yes');
}
else {
window.open($(this).attr('href') , '' , 'width=720 , height=810 , resizable=no , scrollbars=yes');
}
return false;
});

$("ul[id$='list'] li dl a").mouseover(function(){
$target = $(this);
$target.addClass("select");
$target.parent().siblings().children().addClass("select");
});

$("ul[id$='list'] li dl a").mouseout(function(){
$target = $(this);
$target.removeClass("select");
$target.parent().siblings().children().removeClass("select");
});

/*
$("#servicelist li dl a").mouseover(function(){
$target = $(this);
$target.addClass("select");
$target.parent().siblings().children().addClass("select");
});
$("#servicelist li dl dt a").mouseout(function(){
$target = $(this);
$target.removeClass("select");
$target.parent().siblings().children().removeClass("select");
});
$("#servicelist li dl dd a").mouseover(function(){
$target = $(this);
$target.addClass("select");
$target.parent().siblings().children().addClass("select");
});
$("#servicelist li dl dd a").mouseout(function(){
$target = $(this);
$target.removeClass("select");
$target.parent().siblings().children().removeClass("select");
});
*/

//ベイザーハイデフ BMI測定
$("#vaserhidef #bmi #button #submit").click(function(){

if($("#vaserhidef #bmi #height_input").attr("value") !== undefined){

var $height = $("#vaserhidef #bmi #height_input").attr("value");

if($height.match(/^([0-9]{3}|[0-9]{3}\.[0-9]+)$/)){}
else {
var $error = 1;
var $height_text = "身長は半角数字のみ入力可能です。";
}

}

if($("#vaserhidef #bmi #weight_input").attr("value") !== undefined){
var $weight = $("#vaserhidef #bmi #weight_input").attr("value");

if($weight.match(/^([0-9]{2,3}|[0-9]{2,3}\.[0-9]+)$/)){}
else {
var $error = 1;
var $weight_text = "体重は半角数字のみ入力可能です。";
}

}

if($error == 1){
$text = "エラー\n"
if($height_text != undefined){
$text += "\n"+$height_text;
}
if($weight_text != undefined){
$text += "\n"+$weight_text;
}
alert($text);
}

function bmi($weight , $height){
$height = $height / 100;

$bmi = $weight / ($height * $height);

return $bmi;

}

if($weight != undefined && $height != undefined && $error != 1){

$result = bmi($weight , $height);
$result = Math.round($result);

$("#vaserhidef #bmi #message").remove();

$("#vaserhidef #bmi #bmiform").after('<div id="message"></div>');

$("#vaserhidef #bmi #message").append('<p>あなたのBMIは<span>'+$result+'</span>です</p>');

if($result >= 28){
$("#vaserhidef #bmi #message").append('<p>ダイエットやワークアウトをするか、ベイザーで徹底的に脂肪を吸引することを検討してください。</p>');
}
else if($result < 28 && $result >= 23){
$("#vaserhidef #bmi #message").append('<p>あなたのカラダにはベイザーハイデフを施すことで、目に見えた結果がでます。今、決意すれば、10年後の人生は大きく変わっていることでしょう。</p>');
}
else if($result <= 22 && $result >= 20){
$("#vaserhidef #bmi #message").append('<p>あなたのカラダは、ベイザーハイデフを行う価値が最も高いグループです。ベイザーハイデフで最高のBODY Value (ボディバリュー)を生み出しましょう。</p>');
}
else if($result <= 19 && $result >= 18){
$("#vaserhidef #bmi #message").append('<p>あなたのカラダに単純な痩身施術は不要です。脂肪吸引は受けないでください。ベイザーハイデフならあなたの脂肪をバストなど最適な位置へ再配置することができます。</p>');
}
else if($result <= 17){
$("#vaserhidef #bmi #message").append('<p>この状態が続くと危険です。あなたは健康的な社会生活を行うために体重を増やす必要があります。</p>');
}

}

});

$("#vaserhidef #bmi #button #retry").click(function(){
$("#vaserhidef #bmi #height_input").attr("value" ,"");
$("#vaserhidef #bmi #weight_input").attr("value" ,"");
$("#vaserhidef #bmi #message").remove();
});

$('#recruit #pics ul li a').mouseover(function(){

$('#picdisp img').removeClass('after');
$('#picdisp img').addClass('before');

$target = $(this).attr('href');
$alt = $(this).children().attr('alt');

$('#picdisp').append('<img class="after" src="'+$target+'" alt="'+$alt+'" />');

$('#picdisp .before').fadeOut("slow",function(){
	$(this).remove();
});

});
$('#recruit #pics ul li a').click(function(){
return false;
});

//セルリバイブポップアップ表示
if($("body").attr("id") == "cellrevive"){
$("#cellrevive #popup a").lightBox();
}

if($("body").attr("id") == "access"){
var flashvars = {clinic:'tokyo'};
var params = {};
params.wmode = "transparent";
var attributes = {};
swfobject.embedSWF("../swf/clinic.swf", "swfdisp", "530", "350", "9.0.0", false, flashvars, params, attributes);
}

if($("body").attr("id") == "index"){
var flashvars = {};
var params = {};
params.wmode = "transparent";
var attributes = {};
swfobject.embedSWF("swf/TCT_footer.swf", "index_swfdisp", "174", "149", "9.0.0", false, flashvars, params, attributes);
}

if($("body").attr("id") == 'index' && $("body").attr("class") == 'three'){
var params = {};
params.wmode = "transparent";
var attributes = {};
swfobject.embedSWF("swf/seminar.swf", "swfdisp", "366", "222", "9.0.0", false, flashvars, params, attributes);
}

});

