	/** Utimate Ajax Object
	 * http://www.hunlock.com/blogs/The_Ultimate_Ajax_Object
	 */
	function ajaxObject(url, callbackFunction, actionTrigger)
	{
		var that = this;
		this.updating = false;
		this.aborting = false;
		this.ajax_async = true;
		this.container = null;

		this.abort = function()
		{
			if(that.updating)
			{
				that.updating = false;
				that.aborting = true;
				that.AJAX.abort();
				that.AJAX = null;
			}
		};

		this.async = function(val)
		{
			that.ajax_async = val ? true : false;
		};

		this.update = function(passData, postMethod)
		{
			if(that.updating)
				return false;

			that.AJAX = null;

			if(window.XMLHttpRequest)
				that.AJAX = new XMLHttpRequest();
			else
				that.AJAX = new ActiveXObject("Microsoft.XMLHTTP");

			if (that.AJAX == null)
				return false;
			else
			{
				that.AJAX.onreadystatechange = function()
				{
					try
					{
						if (that.AJAX.readyState == 4)
						{
							that.updating = false;
							if(!that.aborting)
								if(that.AJAX.status == 200 || that.AJAX.status == 304 || that.AJAX.status == 204 || that.AJAX.status == 1223 || that.AJAX.status == 0)
									that.callback(that.AJAX.status, that.AJAX.getAllResponseHeaders(), that.AJAX.responseText, actionTrigger);
							that.AJAX = null;
						}
					}

					catch(e) {}
				};

				if(typeof passData == 'undefined')
					passData = '';
				that.updating = new Date();

				if (/post/i.test(postMethod))
				{
					var uri = urlCall;
					that.AJAX.open("POST", uri, that.ajax_async);
					if(typeof callbackFunction != 'undefined' && !webkit)
						that.AJAX.setRequestHeader('User-Agent', 'core' + (ie6 ? '/ie6' : ''));
					that.AJAX.setRequestHeader('Accept-Language', '*');
					that.AJAX.setRequestHeader('Accept', '*/*');
					that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					that.AJAX.setRequestHeader("Content-Length", passData.length);
					that.AJAX.send(passData);
				}
				else
				{
					var uri = urlCall + (passData == '' ? '' : ('?' + passData));
					that.AJAX.open("GET", uri, that.ajax_async);
					if(typeof callbackFunction != 'undefined' && !webkit)
						that.AJAX.setRequestHeader('User-Agent', 'core' + (ie6 ? '/ie6' : ''));
					that.AJAX.setRequestHeader('Accept-Language', '*');
					that.AJAX.setRequestHeader('Accept', '*/*');
					that.AJAX.send(null);
				}

				if(!that.ajax_async && that.AJAX != null)
				{
					if(that.AJAX.status == 200 || that.AJAX.status == 304 || that.AJAX.status == 204 || that.AJAX.status == 1223 || that.AJAX.status == 0)
					{
						that.callback(that.AJAX.status, that.AJAX.getAllResponseHeaders(), that.AJAX.responseText, actionTrigger);
						that.AJAX = null;
					}
				}

				return true;
			}
		};

		var urlCall = url;
		this.callback = callbackFunction || function () {};
	};

	/** Set a cookie
	* @param	string	c_name			cookie neme
	* @param	string	value			cookie value
	* @param	integer	expiredays		cookie expires after given days
	* @param	string	[origin = 'self']	document origin, can be ('self'|'parent')
	* @param	string	[path = null]	set document path, default (if null) set current page
	*/
	function cookie_set(c_name, value, expiredays, origin, path, domain)
	{
		if(typeof iframe_external != 'undefined' && iframe_external)
		{
			var url = 'http://www.livesport.cz/x/cookie/write';

			// msie cache/gzip bug
			if(ie)
			{
				var pom = page_utime + '';
				url += '~' + pom.substr(6, 4);
			}

			var ae_cookie = new ajaxObject(url);
			ae_cookie.async(false);
			ae_cookie.update('write=1&' + c_name + '=' + value, 'POST');
		}

		else
		{
			if(typeof origin != 'undefined' && origin == 'parent' && parent)
				var mydoc = parent.document;
			else
				var mydoc = document;

			var exdate = new Date();

			if(value === '')
				expiredays = -365;

			exdate.setDate(exdate.getDate() + expiredays);
			var cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());

			if(typeof path != 'undefined' && path != null)
				cookie += ';path=' + path;

			if(typeof domain != 'undefined' && domain != null)
				cookie += ';domain=' + domain;

			mydoc.cookie = cookie;
		}
	};

	/** Get a cookie
	* @param	string	c_name			cookie name
	* @param	string	[origin = self]	document origin, can be (self|parent)
	* @return	string					cookie value or null if cookie has not been found
	*/
	function cookie_get(c_name, origin)
	{
		if(typeof iframe_external != 'undefined' && iframe_external)
		{
			if(c_name == 'fs_tza')
				return null;

			var url = 'http://www.livesport.cz/x/cookie/read';

			// msie cache/gzip bug
			if(ie)
			{
				var pom = page_utime + '';
				url += '~' + pom.substr(6, 4);
			}

			var ae_cookie = new ajaxObject(url, cookie_get_remote_response, c_name);
			ae_cookie.async(false);
			ae_cookie.update('read=1&' + c_name + '=1', 'POST');

			if(ae_cookie.container == '-' || ae_cookie.container == '')
				return null;
			else
				return ae_cookie.container;
		}

		else
		{
			if(typeof origin != 'undefined' && origin == 'parent' && parent)
				var mydoc = parent.document;
			else
				var mydoc = document;

			if (mydoc.cookie.length > 0)
			{
				c_start = mydoc.cookie.indexOf(c_name + "=");

				if (c_start != -1)
				{
					c_start = c_start + c_name.length+1;
					c_end = mydoc.cookie.indexOf(";", c_start);

					if (c_end == -1)
						c_end = mydoc.cookie.length;

					return unescape(mydoc.cookie.substring(c_start, c_end));
				}
			}

			return null;
		}
	};

	/** Get remote cookie response
	*/
	function cookie_get_remote_response(r_status, r_headers, r_content, r_trigger)
	{
		if (r_content.length > 0)
			this.container = r_content;
		else
			this.container = '';

	};

	/** Get an attribute of an element
	 * @param	element	an element to set an atribute for
	 * @param	name	the attribute name
	 */
	function get_attr(element, name)
	{
		var attr = '';

		if(element)
		{
			if(ie)
			{
				switch(name)
				{
					default:
						break;

					case 'class':
						attr = element.className;
						break;

					case 'id':
						attr = element.id;
						break;

					case 'rowspan':
						attr = element.rowSpan;
						break;

					case 'colspan':
						attr = element.colSpan;
						break;
				}
			}
			else
				attr = element.getAttribute(name);
		}

		if(!attr)
			attr = '';

		return attr.toString();
	};

	/** Set an attribute of an element
	 * @param	element	an element to set an atribute for
	 * @param	name	the attribute name
	 * @param	content	content of the attribute
	 */
	function set_attr(element, name, content)
	{
		if(ie)
		{
			switch(name)
			{
				default:
					break;

				case 'class':
					element.className = content;
					break;

				case 'rowspan':
					element.rowSpan = content;
					break;

				case 'colspan':
					element.colSpan = content;
					break;
				case 'id':
					element.id = content;
					break;
				
				case 'title':
					element.title = content;
					break;

				case 'type':
					element.type = content;
					break;

				case 'name':
					element.name = content;
					break;
			}
		}
		else
			element.setAttribute(name, content);
	};

	/** Remove attribute on element
	 * @param	object	element	an object element e.g. TD, TR, ...
	 * @param	string	attr	attribute to be removed
	 */
	function rem_attr(element, attr)
	{
		if(ie)
			set_attr(element, attr, '');
		else
			element.removeAttribute(attr);
	};

	function text_append(text, append, unique, last)
	{
		var unique = (typeof unique == 'undefined' || unique == true) ? true : false;
		var last = (typeof last == 'undefined' || last == true) ? true : false;

		var tmp_text = text.toLowerCase();
		var tmp_append = append.toLowerCase();

		if(!tmp_text.match(tmp_append) && tmp_append.indexOf(' ') == 0)
			tmp_append = tmp_append.substr(1);

		if(text.length == 0)
		{
			return append;
		}
		else if(!unique || (unique && tmp_text.match(tmp_append) == null))
		{
			if(last)
				return text + append;
			else
				return append + text;
		}

		return text;
	};

	/** String prototype: Append text (case insensitive)
	* @param	string	append	an append part
	* @param	bool 	[unique = true] append only if append part is not allready included in text
	* @param	bool	[last = true]	if true append last, false append before
	* @return	string	string after to be appended
	*/
	String.prototype.append = function(append, unique, last)
	{
		var unique = (typeof unique == 'undefined' || unique == true) ? true : false;
		var last = (typeof last == 'undefined' || last == true) ? true : false;

		var tmp_text = this.toLowerCase();
		var tmp_append = append.toLowerCase();

		if(!tmp_text.match(tmp_append) && tmp_append.indexOf(' ') == 0)
			tmp_append = tmp_append.substr(1);

		if(this.length == 0)
		{
			return append;
		}
		else if(!unique || (unique && tmp_text.match(tmp_append) == null))
		{
			if(last)
				return this + append;
			else
				return append + this;
		}
	};

	/* Remove text (case insensitive)
	* @param	string	text	a text to be removed from
	* @param	string	remove	a part to be removed
	* @return	string	text	after to be removed
	*/
	function text_remove(text, remove)
	{
		var tmp_text = text.toLowerCase();
		var tmp_remove = remove.toLowerCase();

		// try to remove leading gap
		if(tmp_text.match(tmp_remove) == null && tmp_remove.indexOf(' ') == 0)
			tmp_remove = tmp_remove.substr(1);

		if(tmp_text.match(tmp_remove))
		{
			var index_start = tmp_text.indexOf(tmp_remove);
			var index_stop = tmp_remove.length;

			tmp_remove = text.substr(index_start, index_stop);

			if(tmp_remove.length > 0)
				text = text.replace(tmp_remove, '');
		}

		return text;
	};

	/** fill begining zero if number is less then 10
	* @param	integer	num	number to be corrected
	*/
	function fill_zero(num)
	{
		if(num < 10)
			return '0' + num;
		else
			return num;
	};

	/** Test if element is in array checked by its key
	* @param	array	sa		source array
	* @param	var		key		key to be checked
	* @return	bool	true if element is in array, false otherwise
	*/
	function test_array_key(sa, key)
	{
		if(typeof sa == 'undefined' || typeof sa[key] == 'undefined')
			return false;

		return true;
	};

	/** Test if value exist in array
	 * @param	array	sa		source array
	 * @param	string	val		value to be checked
	 * @return	bool	true if value is in array, false otherwise
	 */
	function test_array_val(sa, val)
	{
		for(var i in sa)
		{
			if(sa[i] == val)
				return true;
		}

		return false;
	};

	/** Try to find value and return its key
	 * @param	array 	sa		source array
	 * @param	string	val		value to be checked
	 * @return	var		key if value is found, false otherwise
	 */
	function get_array_key(sa, val)
	{
		for(var i in sa)
		{
			if(sa[i] == val)
				return i.to_number();
		}

		return false;
	};

	/** Try to find value and return its string key
	 * @param	array 	sa		source array
	 * @param	string	val		value to be checked
	 * @return	var		key if value is found, false otherwise
	 */
	function get_array_string_key(sa, val)
	{
		for(var i in sa)
		{
			if(sa[i] == val)
				return i;
		}

		return false;
	};

	/** Remove an element from array by its key
	* @param	array	sa		source array
	* @param	var		key		remove array key
	* @return	array	affected array
	*/
	function remove_array_key(sa, key)
	{
		var tmp_sa = new Array();
		for(var i in sa)
			if(i != key)
				tmp_sa[i] = sa[i];

		return tmp_sa;
	};

	/** Window prototype: Open help window
	* @url		string	url		url of window
	*/
	window.open_help = function(url)
	{
		var id = Math.floor(Math.random() * 1000);
		return this.open( url, id, 'hotkeys=no, resizable=no, toolbar=no, status=no, dependent=yes, scrollbars=1, width=520, height=500' );
	};

	/** Number prototype: Convert string to number
	* @return	number
	*/
	Number.prototype.to_number = function()
	{
		return this;
	};

	/** String prototype: Convert string to number
	* @return	number
	*/
	String.prototype.to_number = function()
	{
		var pom = this - 0;

		if(isNaN(pom))
			return this;
		else
			return pom;
	};

	/** Convert utime to dbdate
	* @param	integer	utime	unix timestamp
	* @return	string	date in db format (YYYY-MM-DD)
	*/
	function utime2dbdate(utime)
	{
		var tmp = new Date();
		tmp.setTime(utime * 1000);

		return tmp.getFullYear() + '-' + fill_zero((tmp.getMonth() + 1)) + '-' + fill_zero(tmp.getDate());
	};

	/** Convert utime to GMT dbdate
	* @param	integer	utime	unix timestamp
	* @return	string	GMT date in db format (YYYY-MM-DD)
	*/
	function utime2gmt_dbdate(utime)
	{
		var tmp = new Date();
		tmp.setTime(utime * 1000);

		return tmp.getUTCFullYear() + '-' + fill_zero((tmp.getUTCMonth() + 1)) + '-' + fill_zero(tmp.getUTCDate());
	};

	/** Convert dbdate to utime
	* @param	string	date in db format (YYYY-MM-DD)
	* @return	integer	utime
	*/
	function dbdate2utime(dbdate)
	{
		var tmp = new Date();
		dbdate = dbdate.split('-');

		if(dbdate.length == 3)
		{
			tmp.setFullYear(dbdate[0]);
			tmp.setMonth((dbdate[1] - 1));
			tmp.setDate(dbdate[2]);
			tmp.setHours(0);
			tmp.setMinutes(0);
			tmp.setSeconds(0);
			tmp.setMilliseconds(0);

			return tmp.getTime() / 1000;
		}

		return 0;
	};

	/** Convert utime to human time
	* @param	integer utime				unix timestamp
	* @param	integer	offset				gmt offset
	* @param	bool	[time_only = true]	display only time
	* @param	bool	[full_date = false]	display full date DD.MM.YYYY
	* @param	bool	[no_year = false]	do not display year if full date is set
	*
	* @return	string	formated date/time
	*/
	function utime2time(utime, offset, time_only, full_date, no_year)
	{
		var service_time	= new Date(); // for service use

		time_only = (typeof time_only == 'undefined' || time_only) ? true : false;
		full_date = (typeof full_date == 'undefined' || !full_date) ? false : true;
		no_year = (typeof no_year == 'undefined' || !no_year) ? false : true;

		var time = '';

		utime = utime.to_number();
		offset = offset.to_number();

		service_time.setTime((utime + (service_time.getTimezoneOffset() * 60) - offset) * 1000);

		if(!time_only)
			time += fill_zero(service_time.getDate()) + '.' + fill_zero(service_time.getMonth().to_number() + 1) + '.' + (no_year ? '' : (full_date ? service_time.getFullYear() : '')) + ' ';

		time += fill_zero(service_time.getHours()) + ':' + fill_zero(service_time.getMinutes());

		return time;
	};

	/** Odds format
	* @param	float	odds number
	*
	* @return	return formated odds number
	*/
	function odds_format(odds)
	{
		if(odds < 10)
			return odds.toPrecision(3);
		else if(odds < 100)
			return odds.toPrecision(4);
		else
			return odds.toPrecision(5);
	};

	/** Replace parenthesis for Hebrew version
	*
	* @param	string	str string to be converted
	*
	* @return	string	converted string
	*/
	function fix_entities(str)
	{
		return str.replace(/\(/g, "&rlm;(");
	};

	/** Detect client browser
	 * @param	string	browser schortcat (ie|ff)
	 * @return	bool	true|false true if browser match the shortcut
	 */
	function browser_detect(type)
	{
		if(type == 'ie' && navigator.userAgent.match(/MSIE/))
			return true;
		else if(type == 'ie6' && navigator.userAgent.match(/MSIE 6/))
			return true;
		else if(type == 'ie7' && navigator.userAgent.match(/MSIE 7/))
			return true;
		else if(type == 'ff' && navigator.userAgent.match(/Gecko/))
			return true;
		else if(type == 'webkit' && navigator.userAgent.match(/WebKit/))
			return true;

		return false;
	};

	var ie = browser_detect('ie');
	var ie6 = browser_detect('ie6');
	var ie7 = browser_detect('ie7');
	var ff = browser_detect('ff');
	var webkit = browser_detect('webkit');

	var bench_result_start = null;
	var bench_result_stop = null;

	function bench_start(pom)
	{
		return; 
		var tmp_date = new Date();
		typeof pom == 'undefined' ? pom = 'debug' : '';

		if($('body div#bdebug').length == 0)
		{
			$('body').append('<div id="bdebug" style="position: absolute; right: 5px; top: 5px"></div>');
		}

		$('body div#bdebug').append('<div style="debug" id="debug-' + pom + '"></div>');

		bench_result_start = tmp_date.getTime();
	};

	function bench_stop(pom)
	{
		return; 
		var tmp_date = new Date();
		typeof pom == 'undefined' ? pom = 'debug' : '';

		bench_result_stop = tmp_date.getTime();

		$('body div#bdebug div#debug-' + pom).html(pom + ' - time: ' + (bench_result_stop - bench_result_start) + ' [ms]');
	};

	function log(text)
	{
		return;		if($('body div#bdebug').length == 0)
		{
			$('body').append('<div id="bdebug" style="position: absolute; right: 5px; top: 5px"></div>');
		}

		$('body div#bdebug').append('<div style="debug">' + text + '</div>');
	};
	
	function replace_query_string( url, param, value ) 
	{
		var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
		if (url.match(re))
	  		return url.replace(re,'$1' + param + "=" + value + '$2');
		else if (url.indexOf("?") == -1)
	  	return url + '?' + param + "=" + value;
		else
	  	return url + '&' + param + "=" + value;
	};

	function close_lang_box()
	{
		var elm = document.getElementById('lang-box');
		if(elm)
		{
			elm.style.display = 'none';	
			setTimeout('cookie_set( \'lang_box\', 0, 7, \'self\', \'/\' )', 100);
		}
	};

	function close_caption_box(element_ident, cookie_ident, expiredays)
	{
		var elm = document.getElementById(element_ident);
		if(elm)
		{
			elm.style.display = 'none';	
			setTimeout( 'cookie_set( \'' + cookie_ident + '\', 0, ' + expiredays + ', \'self\', \'/\' )', 100);
		}
	};
	
	/** Display/Hide element (calendar)
	*/
	function display_hide(id)
	{
		var element = document.getElementById(id);

		if(element)
			$(element).remove();
		else
			$("#ifmenu-calendar span").append(date_calendar());
	};

	/** Display/Hide element
	*/
	function display_hide_element(id)
	{
		var element = document.getElementById(id);

		if(element)
		{
			if(element.style.display == 'block')
				element.style.display = 'none';
			else
				element.style.display = 'block';
		}
	};

	function get_scrollbar_width() {
		var div = $('<div style="width:50px;height:50px;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
		// Append our div, do our calculation and then remove it
		$('body').append(div);
		var w1 = $('div', div).innerWidth();
		div.css('overflow-y', 'scroll');
		var w2 = $('div', div).innerWidth();
		$(div).remove();
		return (w1 - w2);
	};
	function tooltip(div_input_id, ident)
	{
		this.max_width = 400;
		this.is_init = false;
		this.div = null;
		this.div_content = null;
		this.td_parent = null;
		this.tr_parent = null;
		this.td_parent_title = '';
		this.tr_parent_title = '';

		this.div_id = (typeof div_input_id == 'undefined') ? 'fsbody' : div_input_id;
		this.ident = (typeof ident == 'undefined') ? 1 : ident;
		this.container_id = 'tooltip-' + this.ident;

		this.init = function()
		{
			if(this.is_init) return;

			var div_element = null;
			div_element = document.getElementById(this.div_id);

			if(!div_element)
				return;

			this.div = document.createElement('div');
			set_attr(this.div, 'id', this.container_id);
			set_attr(this.div, 'class', 'tooltip');

			this.div_content = document.createElement('span');
			this.div.appendChild(this.div_content);

			var div_lt = document.createElement('div');
			set_attr(div_lt, 'id', this.container_id + '-lt');
			set_attr(div_lt, 'class', 'tooltip-lt');
			this.div.appendChild(div_lt);

			var div_rt = document.createElement('div');
			set_attr(div_rt, 'id', this.container_id + '-rt');
			set_attr(div_rt, 'class', 'tooltip-rt');
			this.div.appendChild(div_rt);

			var div_lb = document.createElement('div');
			set_attr(div_lb, 'id', this.container_id + '-lb');
			set_attr(div_lb, 'class', 'tooltip-lb');
			this.div.appendChild(div_lb);

			var div_cb = document.createElement('div');
			set_attr(div_cb, 'id', this.container_id + '-cb');
			set_attr(div_cb, 'class', 'tooltip-cb');
			this.div.appendChild(div_cb);

			var div_rb = document.createElement('div');
			set_attr(div_rb, 'id', this.container_id + '-rb');
			set_attr(div_rb, 'class', 'tooltip-rb');
			this.div.appendChild(div_rb);

			div_element.appendChild(this.div);

			this.is_init = true;
		};

		this.show = function(elm, elm_event, opposite_direction)
		{
			if(typeof opposite_direction == 'undefined')
				opposite_direction = 0;
			
			if(!this.is_init) return;

			var title = elm.title;
			var title_length  = title.length;

			// formating
			title = title.replace(/\[b\]/i, '<strong>', title);
			title = title.replace(/\[\/b\]/i, '</strong>', title);
		   title = title.replace(/\[br\]/ig, '<br />', title);
			title = title.replace(/\[u\]/i, ' &raquo; ', title);
			title = title.replace(/\[d\]/i, ' &raquo; ', title);

			if(title_length > 0)
			{
				var x = parseInt(elm_event.clientX);
				var y = parseInt(elm_event.clientY);

				if(typeof window.pageYOffset != 'undefined')
				{
					var window_top = window.pageYOffset;
					var window_left = window.pageXOffset;
				}
				else
				{
					var window_top = document.documentElement.scrollTop;
					var window_left = document.documentElement.scrollLeft;
				}

				this.div_content.innerHTML = title.replace(/\n/g, "<br \/>");
				elm.title = '';

				var span_parent = elm.parentNode;

				this.td_parent = span_parent.parentNode;
				this.td_parent_title = this.td_parent.title;
				this.td_parent.title = '';

				this.tr_parent = this.td_parent.parentNode;
				this.tr_parent_title = this.tr_parent.title;
				this.tr_parent.title = '';

				if(opposite_direction)
					$(this.div).addClass("revert");

				this.div.style.display = 'block';
				this.div.style.width = this.div.offsetWidth + 'px';

				var div_width = this.div.offsetWidth;
				if(div_width > this.max_width)
				{
					div_width = this.max_width;
					this.div.style.width = this.max_width + 'px';
					this.div_content.style.whiteSpace = 'normal';
				}
				
				// IE6 fixes
				document.getElementById(this.container_id + '-lt').style.height = this.div.offsetHeight + 'px';
				document.getElementById(this.container_id + '-rt').style.height = this.div.offsetHeight + 'px';
				document.getElementById(this.container_id + '-cb').style.width = this.div.offsetWidth + 'px';

				this.div.style.zIndex = '999';

				
				if(opposite_direction)
					this.div.style.left = (x + 10 + window_left) + 'px';
				else
					this.div.style.left = (x - div_width - 10 + window_left) + 'px';
				

				this.div.style.top = (y + 10 + window_top) + 'px';
			}
		};

		this.hide = function(elm)
		{
			if(!this.is_init) return;

			var title = this.div_content.innerHTML.replace(/<br( \/){0,1}>/gi, "\n");
			if(title.length > 0)
			{
				if(elm.title == '')
					elm.title = title;

				this.div.style.display = 'none';
				this.div.style.width = 'auto';
				this.div_content.innerHTML = '';
				$(this.div).removeClass("revert");

				if(this.td_parent.title == '')
					this.td_parent.title = this.td_parent_title;
				if(this.tr_parent.title == '')
					this.tr_parent.title = this.tr_parent_title;
			}
		};

		this.hide_all = function()
		{
			if(!this.is_init) return;

			this.div.style.display = 'none';
			$(this.div).removeClass("revert");
		};

		this.set_max_width = function(width)
		{
			this.max_width = width - 0;
		};

		this.init();
	};

fsTable = (function () {
	/**
	 * Binds common event handlers to enhance UX.
	 *
	 * @param {jQuery} tableContext
	 */
	function bindCommonEvents(tableContext)
	{
		var tt = new tooltip(tableContext.attr('id'));

		tableContext.delegate(".stats-table tbody td:first-child", "mouseenter", function (event) {
			tt.show($(this).get(0), event, true);
		});

		tableContext.delegate(".stats-table tbody td:first-child", "mouseleave", function () {
			tt.hide($(this).get(0));
		});

		tableContext.delegate(".form div span", "mouseenter", function (event) {
			tt.show($(this).get(0), event, false);
		});

		tableContext.delegate(".form div span", "mouseleave", function () {
			tt.hide($(this).get(0));
		});

		tableContext.delegate(".link-inactive", "mouseenter", function (event) {
			tt.show($(this).get(0), event, false);
		});

		tableContext.delegate(".link-inactive", "mouseleave", function () {
			tt.hide($(this).get(0));
		});

        tableContext.delegate(".playoff-box", "mousemove", function (event) {
            tt.show($(this).get(0), event, false);
        });

        tableContext.delegate(".playoff-box", "mouseleave", function () {
            tt.hide($(this).get(0));
        });

        tableContext.delegate(".playoff-box-hover", "mousemove", function (event) {
            tt.show($(this).get(0), event, false);
        });

        tableContext.delegate(".playoff-box-hover", "mouseleave", function () {
            tt.hide($(this).get(0));
        });

        tableContext.delegate(".playoff-box-invert", "mousemove", function () {
            tt.hide($(this).get(0));
        });
	}

	var initialized = false;

	return {
		/**
		 * Initializes table UI enhancemets.
		 *
		 * Known table types are standings running as standalone pages and
		 * live tables running as AHAH components in event detail page.
		 */
		initialize: function () {
			if (initialized) {
				return;
			}

			var tableContext;
			if (0 < $("#sportstats .stats-table").length) {
				tableContext = $("#sportstats");
		    } else if (0 < $("#sportstats #playoff-env").length) {
                tableContext = $("#sportstats");
			} else if (0 < $("#live-table-content .stats-table").length) {
				tableContext = $("#live-table-content");
			}

			if (!tableContext || (0 >= tableContext.length)) {
				return;
			}

			initialized = true;

			bindCommonEvents(tableContext);
		}
	};
})();

$(document).ready(function () { fsTable.initialize() });

