$(function(){
	var
		news = $('.topnews'),
		inputs = news.find('input[name=topnews]'),
		time = 7500,
		interval,
		timeout,
		current;
	
	function changeNews() {
		var old = inputs.index( inputs.filter(':checked') );
		current = old + 1;
		if(current >= inputs.length)
			current = 0;
		inputs[current].checked = true;
		if($.browser.msie && $.browser.version < 9)
			ieChange(old);
	}
	function stop(e) {
		if(e)
			e.stopImmediatePropagation();
		clearInterval(interval);
		interval = null;
		if(timeout) {
			clearTimeout(timeout);
			timeout = null;
		}
	}
	function start() {
		if(!interval)
			interval = setInterval(changeNews, time);
	}
	function ieChange(old) {
		news.find('strong').css({color:'#FFF'});
		$(inputs[old]).next().css({
			'opacity' : 0,
			'z-index' : 100
		});
		inputs[old].checked = false;
		$(inputs[current]).next().css({
			'opacity' : 1,
			'z-index' : 103
		}).next().find('strong').css({color:'#E00'});
		inputs[current].checked = true;
	}
	news.mouseenter(stop).mouseleave(start);
	news.find('label').mouseenter(function(e){
		if($.browser.msie && $.browser.version < 9) {
			var old = inputs.index( inputs.filter(':checked') );
			current = inputs.index( inputs.filter('#'+this.htmlFor) );
			ieChange(old);
		}
		$( '#'+this.htmlFor ).get(0).checked = true;
	}).mouseleave(function(e) {
		e.stopImmediatePropagation();
	}).click(function(){
		location.pathname = $(this).data('link');
	});
	timeout = setTimeout(start,time);
	if($.browser.msie && $.browser.version < 9) {
		news.find('label').mouseenter(function() {
			var old = inputs.index( inputs.filter(':checked') );
			current = inputs.index( $('#'+this.htmlFor) );
			ieChange(old);
		}).first().mouseenter();
	}
});

