
	function getChannelName (channel) {
		switch(channel) {
			case 'nbc': return 'NBC';
			case 'abc': return 'ABC';
			case 'golf': return 'The Golf Channel';
			case 'espn': return 'ESPN';
			case 'cbs': return 'CBS';
			case 'tnt': return 'TNT';
			default: return 'cbs';
		}
	}
	function getTimesToday (times) {
		for(var i=0;i<times.length;i++){
			var start = times[i].date.toString() + times[i].start.toString()-0; 
			var startDay = start.toString().substr(0,8)+'0000'-0;
			if (global.today == startDay) return i;
		} return 0;
	}
	function getTimesNext (times) {
		var j = 0; var k = 900000000000;
		for(var i=0;i<times.length;i++){
			var start = times[i].date.toString() + times[i].start.toString()-0; 
			if (global.now < start && start < k) { k = start; j = i; }
		} 
		return j;
	}		
	function getTimesStatus (times) {
		// 1: week ahead, 
		// 2: tomorrow
		// 3: today
		// 4: live now
		// 5: highlights
		// 6: tournament done
		// 7: special: live now, channel2
		var status = 1; // Week ahead
		var lastDay = false;
		for(var i=0;i<times.length;i++){
			if (i==times.length-1) lastDay = true;
			var start = times[i].date.toString() + times[i].start.toString()-0;
			var finish = times[i].date.toString() + times[i].finish.toString()-0;
			var start2 = start;
			var finish2 = finish;
			if (times[i].start2 && times[i].finish2){
				start2  = times[i].date.toString() + times[i].start2.toString()-0
				finish2 = times[i].date.toString() + times[i].finish2.toString()-0;
			}
			var startDay = start.toString().substr(0,8)+'0000'-0;
			if (global.now > finish && global.now > finish2 ) { status = 6; } // after tament
			if (global.now >= start && global.now < finish) { return 4; } // live now
			if (global.now >= start2 && global.now < finish2) { return 7; } // live now2: channel2
			if (global.today == startDay && (global.now < start || global.now < start2)) { return 3; }; // Today
			if (global.today == startDay && global.now >= finish && global.now >= finish2) { 
				if (lastDay) return 6; // End of Tournament
				else return 5; // Highlights
			};
			if(typeof global.today != "undefined"){
				if (diffDate(global.today, startDay) == 24) { return 2; }; // Tomorrow
			}
		}
		return status;
	}

	var moving = false;	
	function moveLeft(i, j, k) { 
		if (!moving) {
			if (k==null) k=1; 
			moving = true;
			move(i, j, k, -1); 
		}
	}
	function moveRight(i, j, k) { 
		if (!moving) {
			if (k==null) k=1; 
			moving = true;
			move(i, j, k, 1); 
		}
	}
	function move(i, j, k, l) {
		var x = Math.round(Math.atan(j/k)*k*.6);
		if (j < x) x=j;
		$(i).style.left = ($(i).style.left.replace('px','') * 1) + (l*x)+'px';
		j -= x; 
		if (j > 0) { setTimeout('move(\''+i+'\','+j+','+k+','+l+');',20); } 
		else { moving = false; }
	}	
	
	var month = ['January','February','March','April','May','June','July','August','September','October','November','December'	];
	var day = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];

	function formatDate (format, date, time) {
		if (time) {
			time = time * 1;
			if (time < 100) time='00'+time;
			if (time < 1000) time='0'+time;
			date = date.toString() + time.toString();
		}
		else date = date.toString();
		var y = date.substr(0, 4);
		var om = date.substr(4, 2);
		var m = om - 1; if (m < 10) m = '0'+m;
		var mo = month[m * 1];
		var d = date.substr(6, 2);
		var h24 = date.substr(8, 2);
		var h12 = h24;
			if (h12 > 12) h12 = h12 - 12;
			if (h12 < 10) h12 = '0'+h12; 
		var i = date.substr(10, 2);
		var dateObj = new Date(y, m, d, h24, i, 0);
		var dy = day[dateObj.getDay()];
		var x = format;
		var ampm1 = 'am';
		var ampm2 = 'a.m.';
		if (h24 > 11 && h24 != 24) { ampm1 = 'pm'; ampm2 = 'p.m.'; }
		var stime = h12*1; if (i*1 > 0) stime += ':'+i;
		x=x.replace(/\[y4\]/gi, y);
		x=x.replace(/\[y2\]/gi, y.substr(2, 2));
		x=x.replace(/\[m4\]/g, mo);
		x=x.replace(/\[m3\]/g, mo.substr(0, 3));
		x=x.replace(/\[m4\]/g, mo.substr(0, 4));		
		x=x.replace(/\[M4\]/g, mo.toUpperCase());
		x=x.replace(/\[M3\]/g, mo.substr(0, 3).toUpperCase());
		x=x.replace(/\[m2\]/gi, om);
		x=x.replace(/\[m1\]/gi, om * 1);
		x=x.replace(/\[d4\]/g, dy);
		x=x.replace(/\[D4\]/g, dy.toUpperCase());
		x=x.replace(/\[d3\]/g, dy.substr(0, 3));
		x=x.replace(/\[D3\]/g, dy.substr(0, 3).toUpperCase());
		x=x.replace(/\[d2\]/gi, d);
		x=x.replace(/\[d1\]/gi, d * 1);
		x=x.replace(/\[H2\]/g, h24);
		x=x.replace(/\[H1\]/g, h24 * 1);
		x=x.replace(/\[h2\]/g, h12);
		x=x.replace(/\[h1\]/g, h12 * 1);
		x=x.replace(/\[i2\]/gi, i);
		x=x.replace(/\[i1\]/gi, i * 1);
		x=x.replace(/\[time\]/gi, stime);
		x=x.replace(/\[p0\]/g, ampm1.substr(0,1));
		x=x.replace(/\[p1\]/g, ampm1);
		x=x.replace(/\[p2\]/g, ampm2);
		x=x.replace(/\[P1\]/g, ampm1.toUpperCase());
		x=x.replace(/\[P2\]/g, ampm2.toUpperCase());
		return x;
	}
	function formatTime (format, time) {
		time = time * 1;
		if (time < 100) time='00'+time;
		if (time < 1000) time='0'+time;
		time = time.toString();
		var h24 = time.substr(0, 2);
		var h12 = h24;
			if (h12 > 12) h12 = h12 - 12;
			if (h12 < 10) h12 = '0'+h12; 
		var i = time.substr(2, 4);
		var x = format;
		var ampm1 = 'am';
		var ampm2 = 'a.m.';
		if (h24 > 11 && h24 != 24) { ampm1 = 'pm'; ampm2 = 'p.m.'; }
		var stime = h12*1; if (i*1 > 0) stime += ':'+i;
		x=x.replace(/\[H2\]/g, h24);
		x=x.replace(/\[H1\]/g, h24 * 1);
		x=x.replace(/\[h2\]/g, h12);
		x=x.replace(/\[h1\]/g, h12 * 1);
		x=x.replace(/\[i2\]/gi, i);
		x=x.replace(/\[i1\]/gi, i * 1);
		x=x.replace(/\[p0\]/g, ampm1.substr(0,1));
		x=x.replace(/\[p1\]/g, ampm1);
		x=x.replace(/\[p2\]/g, ampm2);
		x=x.replace(/\[P1\]/g, ampm1.toUpperCase());
		x=x.replace(/\[P2\]/g, ampm2.toUpperCase());
		x=x.replace(/\[time\]/gi, stime);
		return x;
	}

	function diffDate (a, b) {
		a = a.toString(); 
		b = b.toString();
		var x = Date.UTC(a.substr(0,4)-0,a.substr(4,2)-1,a.substr(6,2)-0,a.substr(8,2)-0,a.substr(10,2)-0,0);
		var y = Date.UTC(b.substr(0,4)-0,b.substr(4,2)-1,b.substr(6,2)-0,b.substr(8,2)-0,b.substr(10,2)-0,0);
		return (y-x) / 3600000; //hours
	}
	var Times;
		