
jQuery(function($){

	(function ()
	{

		// Versione con var globali e intervalli, invece delle fn di animaz jQuery, per + velocita`

		var scr_opts = {
			// Velocita` dello scroller (inv. prop.)
			speed:60,
			// Selettore box
			sel:'#news>div',
			// Classe aggiunta sul box all'attivazione
			classAdd:'scroller_on'
		};

		var scr_on = false;

		var scr_elem = $(scr_opts.sel).first();
		var scr_pos = 0;
		var scr_h0 = 0;
		var scr_interval = null;

var scr_doScroll = function() {
			var o = scr_elem.ol
				.get(0);
			var h0 = scr_h0;
//			var t = o.position().top;
// var t = parseInt(o.style.top);
			if (scr_pos+h0<0) { scr_pos += h0; }
o.style.marginTop=(--scr_pos)+"px"; // + veloce di jQuery... forse. (?) // ev.: o.style.marginTop?
//			o.css({top:(--scr_pos)+"px"});
		}

		// A jQuery lascio solo l'inizializzazione:

		//$(window).unload(clearInterval(scr_interval)); /* DÀ UN PROBLEMA CON CHROME: interferisce con le select autom. - disattivato tempor. */

		scr_elem
			.addClass(scr_opts.classAdd)
			.css({position:'relative',overflow:'hidden'})
			.find('ol:eq(0)').css({height:'auto',overflow:'hidden',position:'absolute',right:0})
//			.css({background:"red"})
			.each(function(){
				var o = $(this);
				// salva l'altezza...
				scr_h0 = o.height();
				// ...e raddoppia...
				if ( o.outerHeight(true) > scr_elem.height() ) { // ma solo se deve scorrere
					scr_on = true;
					o.children().clone().appendTo(o);
				}
				scr_elem.ol = o;
				
//o.get(0).style.top=scr_pos;
			})
			.end()
			.each(function(){
				if ( !scr_on ) return;
				$(this)
				.hover(
					function(e){
						// ferma
						clearInterval(scr_interval);
					},
					function(e){
						// riparte
						scr_interval = setInterval(function(){scr_doScroll()},scr_opts.speed);
				})
			})
			.trigger('mouseleave');
	})();

});

