jQuery(document).ready(function() {
	jQuery('#container-1').tabs();
	
	jQuery("#destinations").bind("change", function() {
		if (jQuery("#destinations").val() != "none") {
			var destination_file = jQuery("#dest_to_file_"+jQuery("#destinations").val()).val();
			jQuery.ajax({
				url: "/html/china/"+destination_file,
				cache: false,
				success: function(html){
					
					// clear last text
					jQuery("#destination").html("");
					
					// insert current tex
					jQuery("#destination").append(html);
					
					// create accordion
					jQuery('#ladmarks_accor').accordion({
						autoheight: false,
						active: true
					});
					
					// activate value none in select box landmarks
					jQuery("option[@value = 'none']", "select#landmarks").attr("selected","selected");
				}
			});
		}
		else {
			jQuery("#destination").html("");
			jQuery("option[@value = 'none']", "select#landmarks").attr("selected","selected");
		}
	});
	
	//Bind event to landmarks dropdown
	jQuery("#landmarks").bind("change", function() {
		if (jQuery("#landmarks").val() != "none") {
			var landmark_id = jQuery("#landmarks").val();
			//alert(landmark_id);
			var destination_id = jQuery("#land_to_dest_" + landmark_id).val();
			var destination_file = jQuery("#dest_to_file_" + destination_id).val();
			
			//Retrieve destination html file and update page in it.
			jQuery.ajax({
				url: "/html/china/"+destination_file,
				cache: false,
				success: function(html){
					
					// clear last text
					jQuery("#destination").html("");
					
					// insert current text
					jQuery("#destination").append(html);
					
					// search index of choosed landmark
					var a = jQuery('#ladmarks_accor').children("a");
					var index = 0;
					for (var i = 0; i < a.length; i++) {
						if (jQuery(a[i]).attr("id") == "landmark"+landmark_id) {
							index = i;
							break;
						}
						//alert(index);
					}					
					
					// create accordion
					jQuery('#ladmarks_accor').accordion({
						autoheight: false
					});
					
					// activate wanted landmark
					
					//var jump = "landmark"+index;
					//alert(jump);
					jQuery('#ladmarks_accor').accordion("activate", index);
					//wizard.changeAccordion("activate",index);
					
					//select destination where is wanted landmark
					jQuery("option[@value = '"+destination_id+"']", "select#destinations").attr("selected","selected");
				}
			});
		}
		else {
			jQuery("#destination").html("");
			jQuery("option[@value = 'none']", "select#destinations").attr("selected","selected");
		}
	});
	
	jQuery("#regions").bind("change", function() {
		if (jQuery("#regions").val() != "none") {
			var destination_id = jQuery("#regions").val();
			var weather_file = jQuery("#dest_to_reg_" + destination_id).val();
			jQuery("#weather").html('<img src="/images/china-microsite/'+weather_file+'" />');
		}
		else {
			jQuery("#weather").html("");
		}
	});
});