/*
Livescore Widget Main Class
*/
if(c$===undefined){var c$ = function(selector){return $(selector);}}
if($().cfind===undefined){$.fn.cfind = function(selector) {return this.find(selector);}}

$('iframe').attr('src','');

function argilzar_debug(obj){
	try{
		if(typeof(console) == 'object'){
			if(typeof(console.info) == 'function'){
				console.debug(obj);
			}
		}
	}catch(e){
		
	}
}

var Widget_livescore = Widget.extend(widget_extend_me);

Widget_livescore = Widget_livescore.extend({
	
	init: function(id, settings){
		this._super(id, settings);
	}
	,
	is_ipad: function(){
		return /iPad;.U/.test(navigator.userAgent);
	}
	,
	is_iphone: function(){
		return /iPhone;.U/.test(navigator.userAgent);
	}
	,
	js_working: function(is_working){
		if(!this.is_ipad()){return false;}
		if(is_working){
			$('#js_working').css({
				'top': $(window).height()/2-60,
				'left': $(window).width()/2-125 
			}).fadeIn('fast');
		}else{
			$('#js_working').fadeOut('fast');
		}
	}
	,
	settings:{
		'update_interval':	5000, /*time between udpates*/
		'update_timeout':	5000, /*If update request takes longer than this it will fail and resume update interval*/
		'update_type':			'm',
		'update_init':			true,
		'update_url':			'/static/default/livescore/master.[sportFK].json',
		'master_update_url':	'/static/default/livescore/master.[sportFK].json',
		'refresh_update_url'	:'/static/default/livescore/update.[sportFK].json',
		'stats_onclick_bind': true,
		'stats_onclick_bind_target': "popup",
		'date_format':		'd/m H:i',
		'do_flags':			false,
		'do_blanks':		true,
		'do_of_wrapper':	false,
		'fixtures':			true
	}
	,
	/*Container for the JSON data recieved from update*/
	data:false
	,
	/*Filter Helper*/
	filter_data:{}
	,
	/*XMLHttpRequest object used for update*/
	update_XMLHttpRequest: false
	,
	/*Update livescore data*/
	update: function(){
		/* argilzar_debug("Do update"); */
		if(!this.settings.update_on){return false;}
		var me = this;
		$.ajax({
			'timeout':		me.settings.update_timeout,
			'global': 		false,
			'cache': 		true,
			'dataType': 	'json',
			'url': 			me.settings_replace(me.settings.update_url) + '?id=' + Math.random().toString().replace('.',''),
			'beforeSend':	function(XMLHttpRequest){me.update_beforeSend(XMLHttpRequest);},
			'success': 		function(data, textStatus, XMLHttpRequest){me.update_success(data, textStatus, XMLHttpRequest);},
			'error': 		function(XMLHttpRequest, textStatus, errorThrown){me.update_error(XMLHttpRequest, textStatus, errorThrown);},
			'complete': 	function(XMLHttpRequest, textStatus){me.update_complete(XMLHttpRequest, textStatus);}
		});
	}
	,
	/*This function is executed when initializing the XMLHttpRequest*/
	update_beforeSend: function(XMLHttpRequest){
		/*this.update_XMLHttpRequest = XMLHttpRequest;*/
	}
	,
	/*This function is executed if the ajax request fails (Invalid json and such)*/
	update_error: function(XMLHttpRequest, textStatus, errorThrown){
		/*nothing*/
	}
	,
	/*Function is executed on ajax request success*/
	update_success: function(data, textStatus, XMLHttpRequest){
		/* argilzar_debug("update_success"); */
		this.update_data(data);
		/* argilzar_debug("update_success update_data"); */
	}
	,
	/*This function is executed after the rquest is done (is executed even if the request fails for some reason)*/
	update_complete: function(XMLHttpRequest, textStatus){
		XMLHttpRequest = null;
		var me = this;
		if(me.settings.tmp_interval){
			$.doTimeout(this.UID + '_update', me.settings.tmp_interval, function(){me.update();});
		}else{
			$.doTimeout(this.UID + '_update', me.settings.update_interval, function(){me.update();});
		}
	}
	,
	/*Function to stop the update proccess*/
	update_stop: function(){
		/*if(typeof(this.update_XMLHttpRequest)==='object'){
			if(typeof(this.update_XMLHttpRequest.abort)==='function'){
				this.update_XMLHttpRequest.abort();
			}
		}*/
		$.doTimeout(this.UID + '_update');
	}
	,
	update_data_new: function(data, init){
		//init = false;
		var filterme = false;
		try{
			for(var eventFK in data){
				/*Event Row DOM*/
				var event_row = c$('#e_' + eventFK);
				/*Only Proceed If Event Row Exists*/
				if(event_row.length){
					/*New Event Data*/
					var val = data[eventFK];
					/*Old Event Data*/
					var old = livescore_data[eventFK];
					/*Check if sound is turned on and if event row is visible*/
					var snd_on = c$('#audio_chooser').hasClass('active') && event_row.is(':visible');
					/*Check if sound is on PER row (soccerstand)*/
					if(c$('#audio_' + val.tsid).hasClass('active')){snd_on = true;}
				
					/*Update status (only if changed or init)*/
					if(init || val.stid !== old.stid){
						
						
						
						/*Update status Class on row*/
						event_row.removeClass('inprogress finished notstarted interrupted cancelled postponed').addClass(val.st);
					
						if(val.st === 'notstarted'){
							
							if( Number( val.stid ) == 5 ){								
								event_row.find('td.status').html('<b>' + enet_labels.get_label('status_desc_5','Postponed') + '</b>');
							}else{/*Format event_date*/
								val.sd = (val.sd).replace(/-/g, '/');
								val.sd = $.PHPDate(this.settings.date_format, new Date(val.sd));
								event_row.find('.status').html(val.sd);
							}	
						}else{
							var status_text = enet_labels.get_label('status_desc_' + ((val.stid) ? val.stid : '0'),'');
							if(status_text){
								event_row.find('td.status').html(status_text);
							}else{
								if(val.st === 'finished'){
									event_row.find('td.status').html(enet_labels.get_label('status_desc_6', 'Finished'));
								}else if(val.st === 'inprogress'){
									event_row.find('td.status').html( enet_labels.get_label('status_desc_45','Started') );
								}else if(val.st === 'cancelled'){
									event_row.find('td.status').html('<b>' + enet_labels.get_label('status_desc_106','Cancelled') + '</b>');
								}else if(val.st === 'interrupted'){
									event_row.find('td.status').html('<b>' + enet_labels.get_label('status_desc_12','Interrupted') + '</b><br/>' + val.sd);
								}else if(val.st === 'postponed'){
									event_row.find('td.status').html('<b>' + enet_labels.get_label('status_desc_5','Postponed') + '</b>');
								}
							}
							
							if(val.stid != old.stid && !init){
								this.highlight(event_row.find('td.status'), 10000, 'status_' + eventFK);
								filterme = true;
							}
							if(val.ip != old.ip && !init){
								filterme = true;
							}
						}
						if(val.st==='finished'){
							event_row.find('.team1, .team2').removeClass('winner').end().find('.team' + val.w).addClass('winner');
							if(val.wc){
								event_row.find('td.status').html(event_row.find('td.status').html() + '<br/><em>' + val.wc + '</em>');
							}
						}
					}/*End (init || val.stid !== old.stid)*/
					
					/*Run update per sport*/
					this.update_data_each(eventFK, val, old, event_row, init, snd_on);
						
				}/*End if(event_row)*/
			}/*End foreach eventFK in data*/
		}catch(e){
			if(typeof(console) == 'object'){
				if(typeof(console.info) == 'function'){
					console.info(e);
				}
			}
		}
		return filterme;
	}
	,
	/*check the livescore data and update dom*/
	update_data: function(data){
		/*Wrap update in a try/catch to prevent js error halts*/
		this.debug_info('update_data', true);
		try{
			/*Check if this is the first of updates (if this.data = false)*/
			
			if(this.settings.new_update){
				//livescore_data
			}
			
			var init = (!this.data) ? true : false;
			if(init){
				this.data = data;
				this.settings.update_url = this.settings.refresh_update_url;
				this.settings.update_ts = data['ts'];
				this.settings.update_type = 'u';
				this.settings.update_init = true;
				this.settings.tmp_interval = 100;
			}else{
				init = this.settings.update_init;
				this.settings.update_init = false;
				this.settings.tmp_interval = false;
				
				var me = this;
					
				/*Save server date to var*/
			
				if(typeof(session) != 'undefined'){
					var now_date = new Date(session.time.year, session.time.month-1, session.time.day, session.time.hour, session.time.minute, session.time.second);
				}else{
					var now_date = false;
				}
				
				var filterme = false;
				
				for(var eventFK in data){
					if(eventFK.match('^(0|[1-9][0-9]*)$')){
						var val = data[eventFK];
						
						var old = me.data[eventFK];
						if(!old){old = val;}
						
						/*if init then update matches that are close to starttime*/
						var updateme = false;
						if(init && val.st === 'inprogress'){
							updateme = true;
						}else if(old.h !== val.h){
							updateme = true;
						}else if(init && now_date){
							var diff = Math.abs(Math.round((now_date - (new Date((val.sd).replace(/\-/g,'/'))))/1000/60));
							if(val.st === 'notstarted' && diff < 31){
								updateme = true;
							}else if(val.st === 'finished' && diff < 121){
								updateme = true;
							}
						}
						
						
						
						var event_row = $('#e_' + eventFK);
						var snd_on = 	$('#audio_chooser').hasClass('active') && event_row.is(':visible');
						
						/*Only perform update if hash has changed or if it's the first of updates (if event_row does not exist then the match is not in the DOM. *Do nothing)*/
						if(updateme===true){
							if(!document.getElementById('e_' + eventFK)){
								/*Row does not exist*/
							}else{
								
								if($('#audio_' + val.tsid + '.active').length){snd_on = true;}
								
								var event_row = $('#e_' + eventFK);
								
								/*set eventFK data in row if initializing*/
								if(init){event_row.data('eventFK', eventFK);}
								
								/*Check if sound is on*/
								
								
								/*Format Date*/
								val.sd = (val.sd).replace(/-/g, '/');
								val.sd = $.PHPDate(me.settings.date_format, new Date(val.sd));
					
								/*Update status Class on row*/
								event_row.removeClass('inprogress finished notstarted interrupted cancelled postponed').addClass(val.st);
							
								/*Update status (only if changed or init)*/
								if(init || val.stid !== old.stid){
								
									if(val.st === 'notstarted'){
										event_row.find('.status').html(val.sd);
									}else{
										var status_text = enet_labels.get_label('status_desc_' + ((val.stid) ? val.stid : '0'),'');
										if(status_text){
											event_row.find('.status').html(status_text);
										}else{
											if(val.st === 'finished'){
												event_row.find('.status').html(enet_labels.get_label('status_desc_6', 'Finished'));
											}else if(val.st === 'inprogress'){
												event_row.find('.status').html( enet_labels.get_label('status_desc_45','Started') );
											}else if(val.st === 'cancelled'){
												event_row.find('.status').html('<b>' + enet_labels.get_label('status_desc_106','Cancelled') + '</b>');
											}else if(val.st === 'interrupted'){
												event_row.find('.status').html('<b>' + enet_labels.get_label('status_desc_12','Interrupted') + '</b><br/>' + val.sd);
											}else if(val.st === 'postponed'){
												event_row.find('.status').html('<b>' + enet_labels.get_label('status_desc_5','Postponed') + '</b>');
											}
										}
										
										if(val.stid != old.stid){
											me.highlight(event_row.find('.status'), 10000, 'status_' + eventFK);
											filterme = true;
											
										}
									}
									if(val.st==='finished'){
										event_row.find('.team1, .team2').removeClass('winner').end().find('.team' + val.w).addClass('winner');
										if(val.wc){
											event_row.find('.status').html(event_row.find('.status').html() + '<br/><em>' + val.wc + '</em>');
										}
									}
								}
								
								/*Update sport specific*/
								me.update_data_each(eventFK, val, old, event_row, init, snd_on);
							}
						}
						this.data[eventFK] = data[eventFK];
					}/*End check eventFK */
				}/*End For Loop*/
				
				
	
				if(init && this.settings.update_type === 'm'){
					this.settings.update_url = this.settings.refresh_update_url;
					this.settings.update_ts = data['ts'];
					this.settings.update_type = 'u';
					
					/* argilzar_debug('Go update'); */
				}else if(init && this.settings.update_type === 'u'){
					
					/* argilzar_debug('Go update'); */
				}else{
					if(data['ts'] != this.settings.update_ts){
						/* argilzar_debug("Master Timestamp has changed:" + this.settings.update_ts); */
						this.settings.update_url = this.settings.master_update_url;
						this.settings.update_type = 'm';
						this.settings.update_ts = data['ts'];
					}else if(this.settings.update_type == 'm'){
						/* Resume update */
						/* argilzar_debug("Resume update"); */
						this.settings.update_url = this.settings.refresh_update_url;
						this.settings.update_type = 'u';
						this.settings.update_ts = data['ts'];						
					}
					
					
					/*}else{
						this.settings.update_url = this.settings.master_update_url;*/	
					/*}else if(this.data['t'] == 'm'){
						this.settings.update_url = this.settings.refresh_update_url;
						argilzar_debug('Go update');							
					}*/
				}				
				data = null;
				/*this.data['ts'] = data['ts'];
				this.data['t'] = data['t'];*/
				/*This is not nessesary !
				this.data = data;*/
				
				/*Filter events if status change is present*/
				if(filterme){
					me.filter_events();
				}
			}
		}catch(e){
			if(typeof(console) == 'object'){
				if(typeof(console.info) == 'function'){
					console.info(e);
				}
			}
		}
		this.debug_info('update_data', false);
	}
	,
	/*Function to override on each sport for sport specific update*/
	update_data_each: function(eventFK, val, old, event_row, init, sound){ }
	,
	binds:{
		'.sprite17.audio':{
			'click':function(){$(this).toggleClass('active'); return false;}
		},
		'.view_standings:not(.popup)':{
			'click': function(e){
				var click_obj = this;
				var leagueFK = $(this).parents('div.LeagueContainer').attr('id').replace('l_','');
				e.data.me.popup_box({
					'url':'/data/standingpop/' + leagueFK, 
					'title': enet_labels.get_label('LOADING','&nbsp;'), 
					'obj': click_obj,
					'process': e.data.me.populate_popup_standings,
					'banner': e.data.me.settings.banner_standings
				});
				return false;
			}
		},
		'td .odds':{
			'click': function(e){
				var eventFK = $(this).parents('tr').attr('id').replace('e_','');
				if( $(this).parents('tr').hasClass('video') && $(this).parents('tr').hasClass('finished') && e.data.me.settings.sport_name == 'soccer'){
					window.location = '/video/soccer/' + eventFK;
				}else{
					var click_obj = this;
					e.data.me.popup_box({
						'url':'/data/oddspop/' + $(this).parents('tr').attr('id').replace('e_',''), 
						'title': enet_labels.get_label('LOADING','&nbsp;'), 
						'obj': click_obj,
						'process': e.data.me.populate_popup_odds,
						'banner': e.data.me.settings.banner_odds
					});
				}
				return false;
				
			}
		},
		'td .star':{
			'click': function(e){
				if($(this).hasClass('active')){
					$(this).removeClass('active');
					e.data.me.filter_data[$(this).parents('tr').attr('id')] = null;
				}else{
					$(this).addClass('active');
					e.data.me.filter_data[$(this).parents('tr').attr('id')] = true;
				}
				return false;
				
			}
		},
		/*Statistics (h2h) button*/
		'td .stats':{
			'click': function(e){
				var _settings = e.data.me.settings;
				if(_settings.stats_onclick_bind){
					switch(_settings.stats_onclick_bind_target){
					case "self":
						location.href = "/h2h/" + _settings.sport_name + "/" + $(this).parents('tr').attr('id').replace('e_','');
						return;
						break;
					case "popup":
					default:
						window.open('/h2h/' + _settings.sport_name + '/' + $(this).parents('tr').attr('id').replace('e_',''), 'stats','height=550,width=875,status=no,resizable=no,location=no,menubar=no,scrollbars=yes');
						break;		
					}
					return false;
				}else{
					//There should be a link 
					return true;
				}
				
			}
		},
		/*link label clicks on checkbox*/
		'label':{
			'click': function(){ $('#img_' + $(this).attr('for')).trigger(((me.is_ipad())?'touchend':'click')); return false; }
		},
		/*Filter events when checkbox is clicked*/
		'img.cfilter':{
			'click': function(e){e.data.me.filter_events(); return false;}
		},
		'.filter_button':{
			'click': function(e){
				e.data.me.js_working(true);
				if(e.data.me.settings.oldstyle_filter_buttons){
					
					if($(this).hasClass('active')){return false;};
					$('.filter_button, .filter_button_special', '#'+e.data.me.UID).removeClass('active');
					$(this).addClass('active');
					//$(this).parent().parent().find('.filter_button').removeClass('active').end().end().addClass('active');
				}else{
					
					if($(this).hasClass('disabled')){return false;};
					$(this).toggleClass('active');
					
					if( !$('.filter_button.active', '#' + e.data.me.UID).length ){
						$('#filter_button_all').addClass('active');
					}else{
						$('#filter_button_all').removeClass('active');
					}
				}
				e.data.me.filter_events();
				e.data.me.js_working(false);
				return false;
			}
		},
		'#filter_button_all':{
			'click': function(e){
				if($(this).hasClass('active')){return false;};
				$('.filter_button', '#' + e.data.me.UID).removeClass('active');
				$(this).addClass('active');
				e.data.me.filter_events();
				return false;
			}
		},
		'#audio_chooser':{
			'click': function(e){
				if($(this).hasClass('disabled')){return false;};
				$(this).toggleClass('active');
				return false;
			}
		}
	}
	,
	onready:{
		/*'livescore_resize': function(me){
			if(me.settings.livescore_auto_resize){
				$(window).bind('resize', function(){
					$('#livescore_auto_resize').css('height', $(window).height() - me.settings.livescore_auto_resize);
				});
				$(window).trigger('resize');
			}
		},*/
		'start_update': function(me){
				$('#fixture_link_d'+PAGE_days).addClass('orange');
				if(PAGE_days != 0){
					me.update_stop();
					me.settings.update_on = false;
					if(PAGE_client_name === 'soccerstand'){
						$('#filter_buttons').css('visibility','hidden');
					}else{
						$('#' + me.UID).find('.filter_button').addClass('disabled').end().find('#audio_chooser').css('opacity','0').end().find('.star').addClass('hidden');
					}
				}else{
					if(typeof(queryString)==='function'){
						if(queryString('v2')==='true'){
							me.settings.new_update = true;
						}
						
						if(typeof(PAGE_client_name)==='undefined'){var PAGE_client_name = '';}
						
						me.settings.new_update = true;
						
						
						if(queryString('noupdate')==='true'){
							me.settings.update_on = false;
						}
					}
					if(me.settings.update_on && me.settings.new_update){
						start_update(me.settings.update_interval);
					}else if(me.settings.update_on){
						me.update();
					}
				}
			
		},
		'odd_rows': function(me){
			if(me.settings.odd_rows){
				$('table.default tbody tr.event_row:odd', '#' + me.UID).addClass('odd');
			}
		},
		'snd_player':function(){
			/*only sound on soccer*/
		},
		'other_countries': function(me){
			$('input.cfilter[type=checkbox]', '#' + me.UID).attr('checked','')
			.each(function(){
				var match_count = $('.LeagueContainer.do_other.c' + $(this).val()).removeClass('do_other').length;
				if(match_count === 0 && $(this).val() != 0){
					$(this).addClass('no_match').next('label').addClass('no_match').attr('title', 'Ingen kampe');
				};
			});
			$('.LeagueContainer.do_other', '#' + me.UID).removeClass('do_other').addClass('c0');
		},
		'checkboxes': function(me){
			$('input[type=checkbox]', '#' + me.UID).each(function(){
				var no_match = $(this).hasClass('no_match');
				//if( $(this).attr('id') == '' ){$(this).random_id('checkbox');}
				var tmp = $('<img>').attr({'id':'img_' + $(this).attr('id')}).css('cursor','pointer')
				.addClass($(this).attr('class') + ' blank sprite15 checkbox' + (($(this).attr('checked'))?' checked':'') )
				.bind(((me.is_ipad())?'touchend':'click'), function(){
					var checkbox = 	$(this).prev('input[type=checkbox]');
					if(checkbox.attr('checked')){
						$(this).removeClass('checked');
						checkbox.attr('checked',null);
					}else{
						$(this).addClass('checked');
						checkbox.attr('checked','checked');
					}
				})
				.doBlank();
				$(this).hide().after(tmp).bind(((me.is_ipad())?'touchend':'click'), function(){return false;});
			});
		},
		'draggable': function(me){
			$('.draggable', '#' + me.UID).draggable({
				containment: 'body', scroll: false, handle: '.draggable_handle'
			});
		},
		'date_chooser': function(me){
			me.do_dates();
			$('#date_chooser').bind(((me.is_ipad())?'touchend':'click'), {'me': me}, function(e){
				if($('#date_chooser_dates').is(':visible')){
					$('#date_chooser_dates').slideUp('fast');
				}else{
					$('#date_chooser_dates').css({
						'width': $('#date_chooser').outerWidth(),
						'left': $('#date_chooser').position().left,
						'top': $('#date_chooser').position().top + $('#date_chooser').outerHeight()
					}).slideDown('fast');
				}
			});
		}
	}
	,
	/*Highlight Dom node*/
	highlight: function(domnode, timeout, id){
		id = (id) ? id : 'highlight';
		$.doTimeout(id);
		timeout = (timeout) ? timeout : 10000;
		$(domnode).addClass('highlight');
		$.doTimeout(id, timeout, function(){ $(domnode).removeClass('highlight'); });
	}
	,
	/*Play a sound (Silently fails if flash is not ready)*/
	play_sound: function(snd){
		try{
			$('#' + this.UID + '_snd_player').get(0).play_flash_sound(snd);
		}catch(e){
			/*Sound is not ready yet*/
		}
	}
	,
	/*Filter events based on checkboxes and status buttons*/
	filter_events: function(){
		var me = this;
		me.js_working(true);
		var league_array = [];
		var status_array = [];
		/*$('input.cfilter[type=checkbox]').each(function(){
			if($(this).attr('checked')){
				league_array[league_array.length] = $(this).val();
			}
		});*/
		
		if(c$('#filter_button_livestats').hasClass('active')){status_array[status_array.length] = 'livestats';}
		if(c$('#filter_button_selected').hasClass('active')){status_array[status_array.length] = 'selected';}
		if(c$('#filter_button_inprogress').hasClass('active')){status_array[status_array.length] = 'inprogress';}
		if(c$('#filter_button_finished').hasClass('active')){status_array[status_array.length] = 'finished';}
		if(c$('#filter_button_notstarted').hasClass('active')){
			status_array[status_array.length] = 'notstarted'; 
			status_array[status_array.length] = 'interrupted'; 
			status_array[status_array.length] = 'postponed'; 
		}
		
		
		var tmp_data = (me.settings.new_update) ? livescore_data : this.data;
		
		$.each(tmp_data, function(eventFK, val){
			if(status_array.length === 0 || String(status_array).indexOf(val.st) > -1 || (String(status_array).indexOf('inprogress') > -1 && val.ip) || (String(status_array).indexOf('livestats') > -1 && val.ls) || (String(status_array).indexOf('selected') > -1 && me.filter_data['e_' + eventFK])){
				c$('#e_' + eventFK).show();
			}else{
				c$('#e_' + eventFK).hide();
			}
		});
		
		if(league_array.length === 0){
			$('#' + this.UID + ' .LeagueContainer').show();
		}else{
			$('#' + this.UID + ' .LeagueContainer').hide();
			$.each(league_array, function(k,val){
				$('#' + me.UID + ' .LeagueContainer.c'+val).show();
			});
		}
		
		$('#' + this.UID + ' .LeagueContainer:visible').each(function(){
			if($(this).find('tbody tr.event_row:visible').length === 0){
				$(this).hide();
			}
		});
		
		if(me.settings.odd_rows_filter){
			c$('table.default tbody', '#' + me.UID).find('tr.event_row').removeClass('odd').end().find('tr.event_row:visible:odd').addClass('odd');
		}
		me.resize_iframe();
		me.js_working(false);
	}
	,
	/*Add flash sound player to dom*/
	add_sound_player: function(){
		$('<div>').attr('id', this.UID + '_snd_player').appendTo('#' + this.UID);
		var swf_flashvars = {files:"/snd/default/card.mp3|/snd/default/goal.mp3|/snd/default/startEnd.mp3"};
		var swf_params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "always",
			bgcolor: "#FFFFFF"
		};
		var swf_attributes = { id: this.UID + "_snd_player", name: "the_snd_player" };
		swfobject.embedSWF("/flash/default/soundplayer.swf", this.UID + '_snd_player', "1", "1", "9.0.0", "/flash/default/expressInstall.swf", swf_flashvars, swf_params, swf_attributes);
	},
	/*Do Date Chooser*/
	do_dates: function(){
		var me = this;
		if(!me.settings.days_links){me.settings.days_links = '/livescore/[PAGE_sport]/d[day]';}
		
		$('#date_chooser_dates_content').empty();
		for(var x=-3; x<=3; x=x+1){
			var the_date = new Date();
			var the_date = new Date(the_date.setDate(the_date.getDate() + x));
			var the_date = $.PHPDate('d.m.Y', the_date);
			
			var url = (me.settings.days_links).replace('[PAGE_sport]', PAGE_sport).replace('[day]', x);
			if(x == PAGE_days){
				$('<a>').addClass('active').attr('href',url).html(the_date).appendTo('#date_chooser_dates_content');
				$('#date_chooser').find('span').remove().end().prepend( $('<span>').html(the_date));
			}else{
				$('<a>').attr('href',url).html(the_date).appendTo('#date_chooser_dates_content');
			}
		}
		
	}
	,
	remove_widget: function(){
		this._super();
		this.update_stop();
	}
});
