//欧亚指数
$(document).ready(function(){
	//定时刷新
	setInterval("window.location.reload();",1000*60*5);
	
	$("td:empty").html("&nbsp;");
	
	//选择赔率公司限制
	$("#contrastTable :checkbox").click(function(){
		if ($("#contrastTable :checkbox:checked").length > 5) {
			alert("最多选择五家公司");
			return false;
		}
	});
	
	$('.bluebtn a').click(function(){
		$(this).next('div').slideDown('slow');
	});
	
	//即时完场按钮
	var btactive = $("#hiddenop").val();
	switch (btactive) {
		case "jszs":
			$("#indexTab li").removeClass("active");
			$("#indexTab li:first").addClass("active");
			break;
		case "wchc":
			$("#indexTab li").removeClass("active");
			$("#indexTab li:first").next("li").addClass("active");
			break;
	}
	
	$('#show_hidden').click(function(){
		$("tr[match]").show();
		$('#todayMatch').find("input[type='checkbox']").attr('checked','chedked');
		$('#hidden_count').text(0);
	});
	
	$('#button').click(function(){
		var companies = new Array();
		$.each( $(this).parents('.textLeft').find("input:checked"),function(){
			companies.push($(this).attr('name'));
		});
		companies = companies.join(",");
		$(this).parents('.textLeft').find("input[name='company']").attr('value',companies);
	});
		
	
	$('#hiden_count').click(function(){
		$("tr[match]").show();
		$('.popping table').find("input[type='checkbox']").attr('checked','chedked');
		$(this).children().text(0);
	});
	
	$('.popping table td.bottom .alignRight').click(function(){
		$(this).parents('.popping').slideUp('slow');
	});

	$("input[name='checkbox10']").click(function(){
		var count=parseInt($('#hidden_count').text());
		var match=$(this).attr('match');
		$("tr[match='"+match+"']").hide();
		//$('#hiden_count').text(count+1);
		$('#hidden_count').text(count+1);
		$(this).attr('checked','checked');
	});
	
	$('.popping table td.bottom input#checkall').click(function(){
		$.each($(this).parents('.popping').find("input[type='checkbox']"),function(){			
				$(this).attr("checked","checked");				
		});
	});
	
	$('.popping table td.bottom input#uncheck').click(function(){
		
		$.each($(this).parents('.popping').find("input[type='checkbox']"),function(){			
			if($(this).attr('checked')){
				$(this).removeAttr("checked");
			}else{
				$(this).attr("checked","checked");
			}		
		});
		
	});
	
	$('.popping table td.bottom input#yes').click(function(){
		var count=parseInt($('#hidden_count').text());
		$.each($(this).parents('.popping').find("input[type='checkbox']"),function(){			
				var val=$(this).attr('value');
			    if($(this).attr('checked')){
				    // $("tbody tr[league='"+val+"']").show();
			    	$.each($("tbody tr[league='"+val+"']"),function(){
			    		if(!$(this).is(":visible")){
			    			$(this).show();	
			    			if($(this).find("input[type='checkbox']").size()>0 ){
			    			    count--;   
			    			}
			    		}
			    	})			    
			    }		    
			    else{
			    	$.each($("tbody tr[league='"+val+"']"),function(){
			    		if($(this).is(":visible")){
			    			$(this).hide();
			    			if($(this).find("input[type='checkbox']").size()>0 ){
			    			    count++;   
			    			}
			    		}
			    	})
			    	
			    }
		});
		$('#hidden_count').text(count);
		$(this).parents('.popping').slideUp('quick');
	
	});
	
	//点击弹出层
	$('.popdiv a').click(function(){
		$(this).parents('.popdiv').hide();
	});
	
	$("#oddsTables td[@odds_type]").click(function(){
		var agalist_id = $(this).attr("odds_match");
		var company_id = $(this).attr("odds_company");
		var odds_type  = $(this).attr("odds_type");
		switch (odds_type) {
			case "europe":
				var type = 1;
				break;
			case "asian":
				var type = 2;
				break;
			case "dxq":
				var type = 3;
				break;
		}
		$('.popdiv').show();
		var iwidth = $(this).offset().left;
		var iheight = $(this).offset().top;
		var popWidth = iwidth + 10;
		var popHeight = iheight + 10;
		$('.popdiv').css('left', popWidth);
		$('.popdiv').css('top', popHeight);
		$("iframe").attr("src","../match/show_odds.php?aid="+agalist_id+"&cid="+company_id+"&type="+type);
	});
});
