// JavaScript Document
var Widget_livescore_main = Widget_livescore.extend({
	
	
	onready:{
		'remove_buttons': function(){$('#audio_chooser').css('opacity','0');}
	}
	,
	binds: {}
	,
	update_data_each: function(eventFK, val, old, event_row, init, sound){
		var me = this;
		/*Update Result*/
		if(val.st === 'finished' || val.st === 'inprogress' || val.st === 'interrupted'){
			
			event_row.find('.serv').removeClass('serv0 serv1 serv2 serv3').addClass('serv' + val.serv);
			
			/*Update Result*/
			for(var t=1;t<=2;t=t+1){
				for(var s=1;s<=5;s=s+1){
					/*set score*/
					if(typeof(val['p'+t]['s'+s]) != 'undefined'){
						$(event_row.find('.rs_cell .team_'+t+'_rs td').get(s-1)).html(val['p'+t]['s'+s]);
						/*Highlight*/
						if( val['p'+t]['s'+s] > old['p'+t]['s'+s] && !init){
							me.highlight($(event_row.find('.rs_cell .team_'+t+'_rs td').get(s-1)), 4000, 'set_' + eventFK);
						}
					}
					/*tiebreak*/
					if(typeof(val['p'+t]['t'+s]) != 'undefined'){
						$(event_row.find('.rs_cell .team_'+t+'_rs td').get(s-1)).append('<span class="sup">' + val['p'+t]['t'+s] + '</span>');
						/*Highlight*/
						if( val['p'+t]['t'+s] > old['p'+t]['t'+s] && !init){
							me.highlight($(event_row.find('.rs_cell .team_'+t+'_rs td').get(s-1)), 4000, 'tb_' + eventFK);
						}
					}
					
					
				}
				/*Gamescore*/
				var gs1 = gs2 = old_gs1 = old_gs2 = 0;
				gs1 = (val.p1.gamescore) ? val.p1.gamescore : 0; old_gs1 = (old.p1.gamescore) ? old.p1.gamescore : 0;
				gs2 = (val.p2.gamescore) ? val.p2.gamescore : 0; old_gs2 = (old.p2.gamescore) ? old.p2.gamescore : 0;
				
				if(typeof(val.p1.gamescore) != 'undefined' && typeof(val.p2.gamescore) != 'undefined'){
					event_row.find('.gamescore .team_1_rs td').html(gs1);
					event_row.find('.gamescore .team_2_rs td').html(gs2);
				}else{
					event_row.find('.gamescore .team_1_rs td').html('&nbsp;');
					event_row.find('.gamescore .team_2_rs td').html('&nbsp;');
				}
				
				
				if(gs1 != old_gs1 && !init){
					me.highlight(event_row.find('.gamescore .team_1_rs td'), 4000, 'gs_1_' + eventFK);
				}
				if(gs2 != old_gs2 && !init){
					me.highlight(event_row.find('.gamescore .team_2_rs td'), 4000, 'gs_2_' + eventFK);
				}
				
				/*Update Score*/
				var rs1 = rs2 = old_rs1 = old_rs2 = 0;
				rs1 = (val.p1.sw) ? val.p1.sw : 0; old_rs1 = (old.p1.sw) ? old.p1.sw : 0;
				rs2 = (val.p2.sw) ? val.p2.sw : 0; old_rs2 = (old.p2.sw) ? old.p2.sw : 0;
				event_row.find('.set_score .team_1_rs td').html(rs1);
				event_row.find('.set_score .team_2_rs td').html(rs2);
				if(rs1>old_rs1 && !init){
					me.highlight(event_row.find('.set_score .team_1_rs td'), 10000, 'rs_1_' + eventFK);
				}
				if(rs2>old_rs2 && !init){
					me.highlight(event_row.find('.set_score .team_2_rs td'), 10000, 'rs_2_' + eventFK);
				}
			}
		}
		/*Highlight Serv Change*/
		if(val.serv != old.serv && !init){
			me.highlight(event_row.find('.serv'), 3000, 'serv_' + eventFK);
		}
		
	}
	
});
