$(document).ready(function(){ 
						   
	$(".content_data").scroll(function(){
		//alert($(this).scrollLeft());
		$(this).parent().parent().find("div.col_title").scrollLeft($(this).scrollLeft());
		$(this).parent().parent().find("div.row_title").scrollTop($(this).scrollTop());
	});
	
	var max_bld = 10;
	var max_kid = 25;
	/*for the select that not select all items*/
	$("#select_one, .arrow_select_normal, .arrow_select_bld, .arrow_select_kid").click(function(){
		//alert($("#all_selectors .color_blue").length);
		//alert($('#result_box tr').length + $("#all_selectors .color_blue").length);
		var msg = "Please select at least one "+$("#label_type").val()+".";
		var select_content = $("#all_selectors .color_blue").html();
		//alert('1');
		if(select_content){
			$("#all_selectors .color_blue").each(function(i){
			$("<tr>"+$(this).parent().html()+"</tr>").appendTo("#result_box")
			});
			$("#all_selectors .color_blue").addClass('color_grey');
			$('table tr td').removeClass('color_blue');
			return false;
		}else{
			alert(msg);
			return false;
			}
	});
	
	/*for the indicator select for BLD
	$("#select_one_bld, .arrow_select_bld").click(function(){
		if(($('#result_box tr').length + $("#all_selectors .color_blue").length) <= max_bld){
			var select_content = $(".color_blue").html();
			if(select_content){
				$(".color_blue").each(function(i){
				$("<tr>"+$(this).parent().html()+"</tr>").appendTo("#result_box")
				});
				$("#all_selectors .color_blue").addClass('color_grey');
				$('table tr td').removeClass('color_blue');
				return false;
			}else{
				alert("Please select at least one item.");
				return false;
				}
		}else{
			alert("you chose more than "+ max_bld +", can not chose more");
			$('table tr td').removeClass('color_blue');
			return false;
		}
	});*/
	/*for the indicator select for KID
	$("#select_one_kid, .arrow_select_kid").click(function(){
		if(($('#result_box tr').length + $("#all_selectors .color_blue").length) <= max_kid){
			var select_content = $(".color_blue").html();
			if(select_content){
				$(".color_blue").each(function(i){
				$("<tr>"+$(this).parent().html()+"</tr>").appendTo("#result_box")
				});
				$("#all_selectors .color_blue").addClass('color_grey');
				$('table tr td').removeClass('color_blue');
				return false;
			}else{
				alert("Please select at least one item.");
				return false;
				}
		}else{
			alert("you chose more than "+ max_kid +", can not chose more");
			$('table tr td').removeClass('color_blue');
			return false;
		}
	});*/
	
	/*for the select that select all items*/
	$("#select_all").click(function(){
		$('#all_selectors tr td').removeClass('color_blue').removeClass('color_grey');
		 //alert();
		 $("#result_box tbody").remove();
		$("#all_selectors tbody tr:not(.inc_title)").clone().appendTo($("#result_box"));
		$('#all_selectors tr td').addClass('color_grey');
		return false;
	});
	
	$("#remove_one, .step_arrow_back").click(function(){
		var msg = "Please select at least one "+$("#label_type").val()+".";											  	
		if($('#result_box td.color_blue').html()){
			/*when you remove one,should put this one in the select box*/
			$('#result_box td.color_blue').each(function(i){
				var remove_one = $(this).html();
				//alert(remove_one);
				$('#all_selectors td.color_grey').each(function(i){
					if($(this).html() == remove_one){
						$(this).removeClass('color_grey');
					}else{}
				});
			});
			$('#result_box td.color_blue').parent().removeClass('color_blue').remove();
			return false;
		}else{
			alert(msg);
			return false;
		}
	});
	
	$("#remove_all").click(function(){
		$("#result_box").html('');
		$('#all_selectors tr td').removeClass('color_grey');
		return false;
	});
	
	/*the icon in the result page beside tabs*/
	$(".tab_next").click(function(){
		$("#tab_ul").stop();
		var total_width = 0;
		$("#tab_ul li").each(function(){
			total_width += ($(this).width()+5) ;// 5 is the margin
		});
		//alert(total_width);
		var each_step = -100;
		//var max_left = -( $("#tab_ul").width() - $(".scroll_tab").width());
		var max_left = -( total_width +200 - $(".scroll_tab").width());// total_width 710 is the biggest with no need slide, but scroll_tab is 890
		//alert(max_left);
		var current_pos = parseFloat($("#tab_ul").css('left'));
		//alert(current_pos);
		
		if((current_pos > max_left) && (total_width > 710)){
			//$("#tab_ul").css('left',current_pos+each_step+'px');
			//var real_pos = current_pos+each_step+'';
			$("#tab_ul").animate({"left": "-=100px"}, "slow");
		}else{}
	});
	
	$(".tab_prev").click(function(){
		$("#tab_ul").stop();
		//alert($("#tab_ul").width());
		var each_step = 100;
		var min_left =0;
		//alert(max_left);
		var current_pos = parseFloat($("#tab_ul").css('left'));
		//alert(current_pos);
		if(current_pos < min_left){
			//$("#tab_ul").css('left',current_pos+each_step+'px');
			//var real_pos = current_pos+each_step+'';
			$("#tab_ul").animate({"left": "+=100px"}, "slow");
		}else{$("#tab_ul").css({"left": 0});}
		//judge one more time the postion of the position
		if(current_pos > min_left){
			$("#tab_ul").css({"left": 0})
		}
	});
	
	//indicator index
	$(".indicator_category_list span.bold, .indicator_category_list p.bold, .expand_icon").click(
	function(){
		
		if($(this).parent().find('.detail').css('display') == 'none'){
			$(this).parent().find('.detail').show();
			$(this).parent().find('.expand_icon').addClass('expand_icon2');
		}else{
			$(this).parent().find('.detail').hide();
			$(this).parent().find('.expand_icon').removeClass('expand_icon2');
		}
	});
		

});

//add for list view hide show
function scroll_result_list(this_obj){
	
	if($(this_obj).hasClass("icon_closed")){
			$(this_obj).removeClass("icon_closed");
			var the_id = $(this_obj).attr('rel');
			$(the_id).show('');
			return false;
		}else{
			$(this_obj).addClass("icon_closed");
			var the_id = $(this_obj).attr('rel');
			$(the_id).hide('');
			return false;			
		}
}

function hightlight(elem){
	if(elem.hasClass('color_grey')){
		alert("You have already selected that "+$("#label_type").val()+".");
	}else if(elem.hasClass('color_blue')){
		elem.removeClass('color_blue');
	}else{
		//elem.parent().parent().find('td').removeClass('color_blue');
		elem.addClass('color_blue');
	}
}
