$(function(){

 // MENU
 $("#nav li ul").hide();
 $("#nav li").hover( 
  function(){ $(this).children('ul').stop(true, true).slideDown('slow').prev().addClass('active'); },
  function(){ $(this).children('ul').stop(true, true).slideUp('fast').prev().removeClass('active'); }
 );

 // CURRENT MENU ITEM
 $("#nav a").each(function(){ 
  if( $(this).attr('href') === location.href || $(this).attr('href') === location.href.split('/').pop() ) $(this).addClass('current');
 });

// NEWSTICKER

var first = 0,
		pause = 3000,
		current = 0,
		num = 5;
var newsitems = $("#ticker li").size();

function removeFirst(){
 $('#ticker li:eq(' + (current%newsitems) + ')').css('font-weight', 'normal').hide(1000);
 addLast();
}

function addLast(){
 $('#ticker li:eq(' + ((current+num)%newsitems) + ')').show(1000, function(){ $('#ticker li:visible').first().css('font-weight', 'bold'); });
 
 current++;
}
$('#ticker li:eq(0)').css('font-weight', 'bold');
$('#ticker li:gt(4)').each(function(){$(this).hide();});
 interval = setInterval(removeFirst, pause);
 
 
 
 
 var first2 = 0,
		pause2 = 3000,
		current2 = 0,
		num2 = 3;
var newsitems2 = $("#ticker2 li").size();

function removeFirst2(){
 $('#ticker2 li:eq(' + (current2%newsitems2) + ')').css('font-weight', 'normal').hide(1000);
 addLast2();
}

function addLast2(){
 $('#ticker2 li:eq(' + ((current2+num2)%newsitems2) + ')').show(1000, function(){ 
 $('#ticker2 li:visible').first().css('font-weight', 'bold'); });
 current2++;
}
$('#ticker2 li:eq(0)').css('font-weight', 'bold');
$('#ticker2 li:gt(2)').each(function(){$(this).hide();});
 interval2 = setInterval(removeFirst2, pause2);

/*var headline_count;
var headline_interval;
var old_headline = 4;
var current_headline = 0;

function activateTicker() {
	headline_count = $("#ticker li").size();
	$("#ticker li:eq("+(current_headline)+")").css('top',0);
	$("#ticker li:eq("+(current_headline+1)+")").css('top',25);
	$("#ticker li:eq("+(current_headline+2)+")").css('top',50);
	$("#ticker li:eq("+(current_headline+3)+")").css('top',75);
	$("#ticker li:eq("+(current_headline+4)+")").css('top',100);
	headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
}

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count;
	$("#ticker li:eq(" + old_headline + ")").animate({top:-25},"slow", function() {
		$(this).css('top','25px');
	});
	$("#ticker li:eq(" + (current_headline) + ")").show().animate({top:0},"slow");  
	old_headline = current_headline;
}
activateTicker();*/
/*
var headline_count2;
var headline_interval2;
var old_headline2 = 0;
var current_headline2 = 0;

function activateTicker2() {
	headline_count2 = $("#ticker2 li").size();
	$("#ticker2 li:eq("+current_headline+")").css('top',0);
	headline_interval2 = setInterval(headline_rotate2,5000); //time in milliseconds
}

function headline_rotate2() {
	current_headline2 = (old_headline2 + 1) % headline_count2; 
	$("#ticker2 li:eq(" + old_headline2 + ")").animate({top:-20},"slow", function() {
		$(this).css('top','25px');
	});
	$("#ticker2 li:eq(" + current_headline2 + ")").show().animate({top:0},"slow");  
	old_headline2 = current_headline2;
}
activateTicker2();*/

/* // NEWS TICKER
 // GROUP 1
 var newsitems = $("#ticker li").hide().size();
 var curritem = 0;
 $("#ticker li:first").show();
 function ticknews(){ 
 	$("#ticker li:eq("+curritem+")").css({position: 'relative'}).animate({top: '+=150'}, {duration: 1000, complete: function(){  $(this).hide(); showNext(); }});
	
 }  
 function showNext(){
	 curritem = ++curritem%newsitems;
	$("#ticker li:eq("+curritem+")").css({position: 'relative', top: '-150px'}).show().animate({top: '+=150'});
 }
 setInterval(ticknews,5000); // timer
 
 // GROUP 2
 var newsitems2 = $("#ticker2 li").hide().size();
 var curritem2 = 0;
 $("#ticker2 li:first").show();
 function ticknews2(){ 
 	$("#ticker2 li:eq("+curritem2+")").css({position: 'relative'}).animate({top: '+=150'}, {duration: 1000, complete: function(){  $(this).hide(); showNext2(); }});
	
 }  
 function showNext2(){
	 curritem2 = ++curritem2%newsitems2;
	$("#ticker2 li:eq("+curritem2+")").css({position: 'relative', top: '-150px'}).show().animate({top: '+=150'});
 }
 setInterval(ticknews2,5000); // timer */
 
});
