
var G24 = {

	TRACKED : 302098,

	init : function() {
		G24.initSliders();
		G24.initTicker('tracked');
	},
	
	initSliders : function() {
		$("#thumbnail-boxes .box").hover(
			function() { $('.on', this).stop().animate({ right: '0px' }, 300 ); }, 
			function() { $('.on', this).stop().animate({ right: '-124px' }, 300); }
		).click(function() {
			window.location = $('a.arrow', this).attr('href');
		});
	},
	
	initTicker : function(id) {
		var el = $('#'+id);
		if (!el) return;
		var tick = function() {
			var d = new Date();
			var milliseconds = (d.getHours()*60*60 + d.getMinutes()*60 + d.getSeconds())*1000 + d.getMilliseconds();
			var interval = Math.ceil((86400*1000) / G24.TRACKED);
			el.html(G24.formatNumber(Math.ceil(G24.TRACKED * (milliseconds / (86400*1000)))));
			setTimeout(tick, interval);
		};
		tick();
	},
	
	formatNumber : function(nStr) {
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	
};


$(document).ready(function() {
	G24.init();
});
