﻿$(function(){
	$(".popup-content").find("table tr:first").css("background-color", "#F1F1F1");
	if(target == "products" || target== "ajax_products") {
		if(target == "products"){
		
		$(".product-thumb-container").multipleElementsCycle({
			container: '.product-thumb-container',
			prev: '.prev-btn',
			next: '.next-btn'
		});
		}
		$("a.fancyProductDetail").fancybox({
			width			: 630,
			height			: 510,
			autoSize		: false,
			closeClick		: false,
			openEffect		: 'none',
			closeEffect		: 'none',
			revealEffect	: 'none',
			hideEffect		: 'none',
			beforeLoad      : function(){$("#fancybox-overlay").remove();
										$("html").css("overflow","hidden");},
			afterClose		:function(){$("html").css("overflow-y","scroll");},
			beforeShow		: function(){show_product_content(1);}
		});
		$("a#zoom-product").fancybox({
			beforeShow : function(){
			$("#fancybox-overlay").remove();
			}
		});
		
		$(".related-product").click(function(){
			var img_src = $(this).attr("href").replace(site_path,'');
			$(".related-product").removeClass("selected");
			$(this).addClass("selected");
			$("#product-detail-left").children(":first-child").attr("src", '/img/imagecache/155x130_'+img_src.replace('/img/upload/',''));
			$("#zoom-product").attr('href', img_src);
			return false;
		});	
		
		$(".product-thumb-container").find("a").click(function() {
			return false;
		});
	}else if(target == "health" || target == "media") {
		if(target == "health") {
			$("a.fancyHealthDetail").fancybox({
				width			: 660,
				height			: 578,
				autoSize		: false,
				closeClick		: false,
				openEffect		: 'none',
				closeEffect		: 'none',
				revealEffect	: 'none',
				hideEffect		: 'none',
				beforeLoad      :function(){$("#fancybox-overlay").remove();
										$("html").css("overflow","hidden");},
				afterClose		:function(){$("html").css("overflow-y","scroll");}
			});
		}
		$(".video-thumb-container").multipleElementsCycle({
			container: '.video-thumb-container',
            prev: '.prev-btn',
            next: '.next-btn'
		});
		$(".video-thumb-container").find("a").click(function() {
			return false;
		});
	} else if(target =="product_take") {
		$("#step-1 .step-detail-container").show();
		$(".symptoms-btn").click(function(){	
			var id = $(this).attr("alt");
			$(this).addClass("selected");
			$("input[name=diagnosis]").attr("checked",false);
			$(".checkbox").removeClass('selected');
			$(".diagnosis-table-holder").hide();
			$(".step-title").find("span").removeClass("selected");
			$("#step-2").find(".step-title>span").addClass("selected");
			$(".symptoms-btn").removeClass("selected");
			$(".step-detail-container").hide();
			$("#step-1 .step-detail-container").show();
			$("#diagnosis"+ id).show();
			$("#step-2 .step-detail-container").slideDown("slow");
			$("#diagnosis-title").find("span").html($(this).find("span").html());
			$("#symptoms-value").val(id);
			$("html").scrollTo( "+=300px" , 800 );
		});	
		$("#step-3-btn").click(function(){
			var ChkBoxVal = $("input[name=diagnosis]:checked").map(function () {return this.value;}).get().join(",");
			var Symptoms = $("#symptoms-value").val();
			$("#step-3 .step-detail-container").hide();
			if(ChkBoxVal.length == 0) {
				$(".no-record").show();
			} else {
				$(".no-record").hide();
				$(".step-title").find("span").removeClass("selected");
				$("#step-3").find(".step-title>span").addClass("selected");
				$("#step-3 .step-detail-container").slideDown("slow");
				checkProduct(Symptoms, ChkBoxVal);		
				$("html").scrollTo( "+=300px" , 800 );	
			}
		});
		$('.checkbox').click(function() {
			$(this).toggleClass("selected");
			if ($(this).parent().find('input[type=checkbox]').is(':checked')){
				$(this).parent().find(':checkbox').attr('checked', false); 
			}else{
				$(this).parent().find(':checkbox').attr('checked', true); 
			}
		});
	} else {
	$("a.fancybox_china_news_and_event").fancybox({
			width			: 730,
			height			: 510,
			autoSize		: false,
			closeClick		: false,
			mouseWheel		: false,			
			openEffect		: 'none',
			closeEffect		: 'none',
			revealEffect	: 'none',
			hideEffect		: 'none',
			beforeLoad      :function(){$("#fancybox-overlay").remove();
										$("html").css("overflow","hidden");},
			afterClose		:function(){$("html").css("overflow-y","scroll");}
		});
	}
});
function checkProduct(Symptoms, ChkBoxVal) {
	$("#recommendation-table").html("");
	var btn_name = (langCompare == "en_us")? "Product Detail" : (langCompare == "zh_hk")? "產品詳情" : "产品详情";
	var img_source_list = '';
	var product_id_list = '';
	switch(Symptoms) {
		case "1" : 
			img_source_list = (ChkBoxVal.indexOf("6") != "-1")? "1070-8" : (ChkBoxVal.indexOf("5") != "-1")? "1080-8" : (ChkBoxVal.indexOf("4") != "-1")? "1020-08" : (ChkBoxVal.indexOf("3") != "-1")? "1010-12" : "1090-12";
			product_id_list = (ChkBoxVal.indexOf("6") != "-1")? "3" : (ChkBoxVal.indexOf("5") != "-1")? "4" : (ChkBoxVal.indexOf("4") != "-1")? "2" : (ChkBoxVal.indexOf("3") != "-1")? "1" : "5";	 
		break;
		case "2" : 
			img_source_list = (ChkBoxVal.indexOf("3") != "-1")? "1290" : (ChkBoxVal.indexOf("2") != "-1")? "1280-12" : "1260-12";
			product_id_list = (ChkBoxVal.indexOf("3") != "-1")? "9" : (ChkBoxVal.indexOf("2") != "-1")? "8" : "7";	
		break;
		case "3" : 
			img_source_list = (ChkBoxVal.indexOf("1") != "-1")? (ChkBoxVal.indexOf("3") != "-1")? "3050,3030" : (ChkBoxVal.indexOf("2") != "-1")? "3010,3030" : "3030" : (ChkBoxVal.indexOf("3") != "-1")? "3050" : "3010";
			product_id_list = (ChkBoxVal.indexOf("1") != "-1")? (ChkBoxVal.indexOf("3") != "-1")? "16,15" : (ChkBoxVal.indexOf("2") != "-1")? "13,15" : "15" : (ChkBoxVal.indexOf("3") != "-1")? "16" : "13";
		break;
		case "4" : 
			img_source_list = (ChkBoxVal.indexOf("3") != "-1")? "2010" : (ChkBoxVal.indexOf("2") != "-1")? "2030" : "2020";
			product_id_list = (ChkBoxVal.indexOf("3") != "-1")? "10" : (ChkBoxVal.indexOf("2") != "-1")? "12" : "11";	
		break;
		case "5" : 
			img_source_list = 'nofrozic,6030,6040';
			product_id_list = '18,19,20';
		break;
		case "6" : 
			img_source_list = "6010";
			product_id_list = "17";
		break;
		case "7" : 
			img_source_list = (ChkBoxVal.indexOf("2") != "-1")? "5020" : "5010";
			product_id_list = (ChkBoxVal.indexOf("2") != "-1")? "32" : "31";
		break;	 
	}
	var img_src = new Array();
	var product_href = new Array();
	var img_source = img_source_list.split(',');
	var product_id = product_id_list.split(',');
	for(i=0; i<img_source.length;i++){
		img_src[i] = $('<td></td>').append($('<img/>').attr('src','../../img/product/large/'+img_source[i]+'.jpg'));
		product_href[i] = $('<td></td>').append($('<a class="blue_btn product_to_take_id"/>').attr('href', '../../'+lang+'/Products/Index/'+product_id[i]).html(btn_name+'&nbsp;&nbsp;&nbsp;>'));
		$("#recommendation-table").append($('<tr></tr>').append(img_src[i]).append(product_href[i]));	
	}
	$("input[name=diagnosis]").attr("checked",false);	
}
function cleartext(value) {
	
	if ($("#faq-question").val() == value) {
		$("#faq-question").val("");
		$("#faq-question").css("color", "#323231");
	} else if($("#faq-question").val() == ""){
		$("#faq-question").val(value);
		$("#faq-question").css("color", "#787878");
	}
}
function changeVideo(type) {
	$("#youtube-video-holder").find("iframe").attr("src", "http://www.youtube.com/embed/"+type);
}
function changeProduct(product_id, country_id) {
$.ajax({
  type: "POST",
  url : site_path+"/"+lang+"/Products/getAjaxProduct/",
  data: {id : product_id, Country_id : country_id},
  success: function(data){
    $("#ajax_product_holder").html(data);		
  }
});
}
