$(document).ready(function() {

 var slidePos=0;
 var activeHead=0;
 var timer=0;
 
 function setCounter(){
   timer=setInterval(function() {
            var next=(activeHead==3?1:activeHead+1);
            var act=activeHead;
            //alert(activeHead);
  					$('#header'+act).fadeOut(400,function(){$('#header'+next).fadeIn(400);activeHead=next;setAct(activeHead)});
  				}, 15000);
 }

 $('#header1').fadeIn(400,function(){activeHead=1; setCounter(); setAct(activeHead)});
 
 function setAct(x){
  $('#headerNav li').removeClass('act');
  $("#headerNav li[name='"+x+"']").addClass('act');
 }
 
 /*header nav*/
 $('#headerNav li').click(function(){
  if($(this).attr('name')==activeHead || activeHead==0) return;
  var next=eval($(this).attr('name'));
  clearInterval(timer);
  $('#header'+activeHead).fadeOut(400,function(){$('#header'+next).fadeIn(400);activeHead=next;setCounter();setAct(activeHead)});
 });
 
 /* menu */
 $('#menu li').hover(function(){
  if($(this).find('ul').length > 0){
   $(this).addClass('hovered');
   $(this).find('ul').eq(0).css({display: 'block'});
  }
 },function(){
  if($(this).find('ul').length > 0){
   $(this).removeClass('hovered');
   $(this).find('ul').eq(0).css({display: 'none'});
  }
 });
 
 
 
});
