jQuery.noConflict();
var ticker$ = jQuery;

ticker$.news_ticker = {
	init: function() {
		for (module in ticker$.news_ticker) {
			if (ticker$.news_ticker[module].init)
				ticker$.news_ticker[module].init();
		}
	}
};

ticker$(document).ready(ticker$.news_ticker.init);

ticker$.news_ticker.scroll = {

	init: function() {
		ticker$('#news ul li a')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
		ticker$('#news').css({'width':'315px'});
		ticker$('#topics').css({'visibility':'visible'});
	},

	preload: function() {
		ticker$(this).parent().css({'position':'relative'});
		w=(ticker$.browser.msie)?ticker$(this).innerWidth()+ticker$(this).parent().find('span').innerWidth()+32:ticker$(this).parent().width();
		ticker$(this).parent().wrap("<div class='mask' style='margin:0;padding:0;position:apsolute;width:"+w+"px'></div>");
		ticker$(this).parent().parent().wrap("<div class='tickercontainer' style='position:relative;display:block;overflow:hidden;width:315px;'></div>");
	},

	enter: function() {
		if(315<ticker$(this).parent().innerWidth()){
			var p=ticker$(this).parent().position();
			var w = ticker$(this).parent().innerWidth()+16;
			ticker$(this).parent().stop();
			ticker$(this).parent().animate({left: '-'+ (w-305)}, (w+p.left)/315*3000, "linear");
		}
	},

	exit: function() {
		if(315<ticker$(this).parent().innerWidth()){
			var p=ticker$(this).parent().position();
			var w = ticker$(this).parent().innerWidth()+16;
			ticker$(this).parent().stop();
			ticker$(this).parent().animate({left: 0}, (315-p.left)/w*1000, "swing");
		}
	}
};

function reset_ticker(){
	ticker$('#news').css({'width':'100%'});
	ticker$('#topics').css({'visibility':'hidden'});
	ticker$("div[class*='mask']").each(function(){ticker$(this).replaceWith(ticker$(this).html());});
	ticker$("div[class*='tickercontainer']").each(function(){ticker$(this).replaceWith(ticker$(this).html());});
	ticker$.timer(500, function(timer){timer.stop();ticker$.news_ticker.init();});
}
