// JavaScript Document

	
$(document).ready(function() {
		
	
	var imgdesc=new Array();
	imgdesc[1]="";
	imgdesc[2]="<span><i>Baishao</i> (White Peony): The root of this plant is beneficial for headache, dizziness, abdominal pain, spasmodic pain, and anemia. (Photo credit <a href='http://www.flickr.com/photos/geishaboy500/532278344/' target='_blank'>Gieshaboy500<a></span>)";
	imgdesc[3]="<span><i>Shu Di Huang</i> (Chinese Foxglove): The root of this plant tonifies blood, regulate menses and promotes production of body fluid.(Photo credit <a href='http://www.flickr.com/photos/alanvernon/3051354514/' target='_blank'>Alan Vernon<a></span>)";
	imgdesc[4]="<span><i>Yu Jin</i> (Tumeric): The root of this plant  is beneficial for epilepsy, seizures, and pricking pain in the chest and abdomen.(Photo credit <a href='http://www.flickr.com/photos/12054917@N05/2733768051' target='_blank'>Aruna Radhakrishnan<a></span>)";
	imgdesc[5]="<span><i>Tian Hua Fen</i> (Snake Gourd): The dried root of this plant promotes production of body fluid and is beneficial for cough due to lung heat , and diabetes. (Photo credit <a href='http://www.flickr.com/photos/28481088@N00/761675623/' target='_blank'>tanakawho)</a></span>";
	imgdesc[6]="<span><i>Dan Shen</i> (Salvia): The root of this plant is beneficial for menstrual disorders, pain in acute arthritis, and  angina pectoris.(Photo credit <a href='http://www.flickr.com/photos/43322816@N08/4678373193' target='_blank'>Laura Perlick / USFWS</a>)</span>";
	
	$("#FAQlink").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
		
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	$("#page1").fadeIn(150);
	
	$('#babyslideshow').slideshow({
				timeout: 2500,
				fadetime: 2000,
				type: 'random'
			});
			

	var colorstring=new Array();
	colorstring[1]="#dea663";
	colorstring[2]="#ebc248";
	colorstring[3]="#dbb76d";
	colorstring[4]="#c8d0a0";
	colorstring[5]="#ee9065";
	colorstring[6]="#a4d264";

		for (i=1;i<=6;i++){
				$("#menu"+i+" .centermenu").css("background-color",colorstring[i]);
	}
	$("#menubar div").click( function() {
		
		var clickedmenu=parseInt($(this).attr("id").charAt(4));
		for (i=1;i<=6;i++){	
				if ($("#menu"+i).hasClass("active")==1) {
					var activemenu=i;
				}	
				$("#page"+i).fadeOut(0,function(){
						$("#page"+clickedmenu).fadeIn(0);
				});

			}
			
			
			
		if ($(this).hasClass("active")==0) {
			
			$("#menubar div .centermenu .menutitle").removeClass("passive_r");
			$("#menubar div .centermenu .menutitle").removeClass("passive_l");
			$("#menubar div .centermenu .menutitle").removeClass("active");
			
			for (j=1; j<clickedmenu; j++) {	
				$("#menu"+j+" .centermenu .menutitle").addClass("passive_l");
			}
			$("#menu"+clickedmenu+" .centermenu .menutitle").addClass("active");			
			
			for(j=clickedmenu+1; j<=6; j++) {
				$("#menu"+j+" .centermenu .menutitle").addClass("passive_r");
			}
			
			$(this).css("z-index","6");
			for (j=-6;j<=6;j++) {
				var i=clickedmenu+j;
				var dist=6-Math.abs(j);
				if (j!=0) {$("#menu"+i).css("z-index",dist);}
			}
			$("#onesheet").css("background-color",colorstring[clickedmenu]);
			$("#middle_right #image").css("background","url(media/images/image_"+clickedmenu+".png) no-repeat center bottom");
			$("#middle_right #desc_copyright").html(imgdesc[clickedmenu]);


		}
	});
	
	$("form input.text, form textarea").focus( function() {
		if ($(this).attr('value') == $(this).attr('name')) {
			$(this).attr('value','');
		}
	});
	$("form input.text, form textarea").blur( function() {
		if ($(this).attr('value') == "") {
			$(this).attr('value',$(this).attr("name"));
		}
	});
	
	$("form input.submit").bind('click', function(){
	if ($("#namefield").val() == "Name") {
        $(".errormessage").text("Please enter your name.").show();
      }
	
	else if ($("#emailfield").val() == "Email" || $("#emailfield").val().indexOf('@') == -1 || $("#emailfield").val().indexOf('.') == -1) {
        $(".errormessage").text("Please enter a valid email address.").show();
      }
	  
	  else if ($("#messagefield").val() == "Message") {
        $(".errormessage").text("Please write us a few line.").show();
      }/*
      $("span").text("Not valid!").show().fadeOut(1000);
      return false;
    });*/

		else {$.post("submit.php", $("#contactform").serialize(), function() {
			$("form").fadeOut(function() {
				$(".thankyou").fadeIn();
			});
		})};
	});


$("#thumbnailrow img").click( function() {
		if ($(this).hasClass('(.active)')==0) {
			var thumbsource = $(this).attr("src");
			var source=thumbsource.replace("_th.jpg",".jpg");
			$("#officeimagewrapper").fadeOut(500, function(){
				$("#officeimagewrapper").css("background-image", "url("+source+")");
				$("#officeimagewrapper").fadeIn(500);
			});
					
			$("#thumbnailrow img").removeClass("active");
			$(this).addClass("active");
		}
	});
	
	testimoni=document.getElementById("page5_testi");
$("#page5_silhs div").click( function() {
		if ($(this).hasClass('(.active)')==0) {
			var testiIDstring = $(this).attr("id").substring(5,7);
			//alert(testiIDstring.substring(5,7));
			if (testiIDstring.charAt(0)=='0'){
				var testiIDInt=parseInt(testiIDstring.substring(1,2));
			} else {
				var testiIDInt=parseInt(testiIDstring.substring(0,2));
			}
			$("#page5_testi").fadeOut(500, function(){
				testimoni.innerHTML='<span id="page5_testi_inside">"'+testimonials[testiIDInt]+'"</span>';
				//$("#page5_testi p").addClass("active_"+testiIDstring);
				testimoni.innerHTML+="<h4>"+testimonials_name[testiIDInt]+"</h4>";
				$("#page5_testi").fadeIn(500, function(){
						var newfontsize=parseInt($("#page5_testi_inside").css('font-size').substring(0,2));
						do {
					//alert($("#page5_testi_inside").height());
				
				$("#page5_testi_inside").css('font-size',newfontsize.toString()+"px");
				newfontsize--;
			}while($("#page5_testi_inside").height()+40>$("#page5_testi").height());
				});
				
			});
			$("#page5_silhs div").removeClass("active");
			$(this).addClass("active");
			
		}
	
					
	});
	
$("#bottons img").click( function() {
			
			var direction = $(this).attr("id");
			var currectleft=$("#page5_silhs img").position().left;
			//alert();
			if (direction=="next" && currectleft+1125>835){
				$("#page5_silhs img").css("left",(currectleft-33).toString()+"px");
					i=Math.round(-currectleft/33+1);
					if (i<10) {num="0"+i.toString()} else {num=i.toString()}
					//alert(i);
					$("#page5_silhs #silh_"+num).addClass("passive");
					//alert("#page5_silhs silh_"+num);
			}
			
			if (direction=="previous" && currectleft<0){
				$("#page5_silhs img").css("left",(currectleft+33).toString()+"px");
					i=Math.round(-currectleft/33);
					if (i<10) {num="0"+i.toString()} else {num=i.toString()}
					$("#page5_silhs #silh_"+num).removeClass("passive");
					//alert("#page5_silhs silh_"+num);
			
			}
			


	});
	
});



