var divList;
var rollID;
var rollChk=0;
var laskuri = 0;
var tOut = 12000;

function rollNews(t){
	if (laskuri>=divList.length) laskuri=0;
	showActive('#'+divList[laskuri].id);
	laskuri++;
	rollID = setTimeout('rollNews('+tOut+')', t);
}
function showActive(active){
		//alert(active);
		if (rollChk==1){
			$('.headline').hide();
			$('.newsroll .panel .item a').removeClass('active');
			$('.newsroll .panel .item[id*="'+active+'"] a').addClass('active');
			$(active).show();
		}else{
			$('.headline .pic').hide();
			$('.headline').hide();
			$('.newsroll .panel .item a').each( function(){
				$(this).removeClass('active');
				$(this).animate({
					left: '95px'
				},200);
				$(this).children().children('.pvm').hide();
			});
			$('.newsroll .panel .item[id*="'+active+'"] a').addClass('active');
			$('.newsroll .panel .item[id*="'+active+'"] a').children().children('.pvm').show();
			$('.newsroll .panel .item[id*="'+active+'"] a').animate({
				left: '40px'
			},500);
			$(active).show();
			$(active+' .pic').fadeIn('slow');
		}
}

$(document).ready( function(){
	$.extend({
		newsroll: function(name){
			var roll = '#'+name;
			$(roll).addClass('newsroll');
			$(roll+' ul').addClass('panel');
			$(roll+' .panel li').addClass('item');
			$(roll+' .panel li a').addClass('default');
			$(roll+' div').addClass('headline');
			divList = $(roll+' div').toArray();
			$('.headline').hide();
			$('.item a').click( function(event){
				event.preventDefault();
				if(rollID) clearInterval(rollID);
				rollChk = 0;
				$(this).blur();
				location.href = $(this).attr('href');
			});
			/*
			$('.panel .item a').mouseenter( function(){
				if(rollID){
					clearInterval(rollID);
				}
				var thisLaskuri = $(this).attr('rel');
				if (laskuri == thisLaskuri) rollChk = 1;
				showActive( $(this).parent('.item').attr('id') );
				rollChk=0;
				laskuri = thisLaskuri;
			});
			$('.panel').mouseleave( function(){
				clearInterval(rollID);
				if (laskuri>0){ laskuri--; }
				rollChk = 1;
				rollNews(tOut/3);
				rollChk=0;
			});
			*/
			rollNews(tOut);
			$(roll).removeClass('newsroll-hide');
		}
	});
	
	$.newsroll('newsroll');


});



