$(function(){
	var checkCursor = false;
	var successTween;

	var measurer_em = $('#measurer_em');
	var em = measurer_em.width();

	var jThermoContainer = $('#thermo')
	var jThermoTable = $('#thermo_tb');
	var jThermoTableTd = $('#thermo_tb td');
	var jThermoTableBg = $('#thermo_bg');
	var jThermoTableTdSelected = $('#thermo_selected');
	
	var currentBgPos;
	var strivingBgPos;

	var currentBgHeight = jThermoTable.height();

	if (!jThermoTableTdSelected.size()) {jThermoTableBg.css('left', -2000)}//scorpix
//	if (!jThermoTableTdSelected.size()) {jThermoTableBg.css('left', -jThermoTableBg.width() * 1.2)}
	if (jThermoTableTdSelected.size()) {
		jThermoTableBg.css('left', jThermoTableTdSelected[0].offsetLeft);
		jThermoTableBg.height(currentBgHeight);
	}

	jThermoTable.hover(
		function(){
			checkCursor = false;
		},
		function(){
			checkCursor = true;
		}
	);

	jThermoTableTd.hover(
		function(){
			jThis = $(this)
			setTimeout(
				function(){
					if (!checkCursor) {
						//scorpix
						if (-2000 == parseInt(jThermoTableBg.css('left')))
							jThermoTableBg.css('left', jThermoTableBg.width() * -1.2);

						currentBgPos = jThermoTableBg[0].offsetLeft;
						strivingBgPos = jThis[0].offsetLeft;
						jThermoTableBg.height(currentBgHeight);
						successTween = new Tween('thermo_bg', 'left', EEQ.Cubic.easeOut, currentBgPos, strivingBgPos, 30);
					};
				},
				20
			)
		},
		function(){
			setTimeout(
				function(){
					if (checkCursor) {
						currentBgPos = jThermoTableBg[0].offsetLeft;
						strivingBgPos = jThermoTableBg.width() * -1.2;
						if (jThermoTableTdSelected.size()) {
							strivingBgPos = jThermoTableTdSelected[0].offsetLeft;
						}
						successTween = new Tween('thermo_bg', 'left', EEQ.linear, currentBgPos, strivingBgPos, 30);
						
						// scorpix
						successTween.onMotionFinishComplete = function() {
							jThermoTableBg.css('left', -2000);
						}
					}
				}, 
				20
			)
		}
	);
	

	function thermoRedraw(){
		if (jThermoTableTdSelected.size()) {
			jThermoTableBg.css('left', jThermoTableTdSelected[0].offsetLeft);
		};
		jThermoTableBg.css('height', jThermoTable.height())
		currentBgHeight = jThermoTable.height();
	}

	setInterval(fontSizeCheck, 300);
	
	function fontSizeCheck(){
		if (em != measurer_em.width()) {
			em = measurer_em.width();
			thermoRedraw();
		};
	}

	$(window).resize(
		function(){
			thermoRedraw();
		}
	);
});
