$(document).ready(function() {
  
//CSS3 tilføjelser
$('.fanda li:last-child').addClass("last");

//Font replacement
  Cufon.replace('h1, h2, h3, #faq dt, #topmenu li a, #competence-menu li strong, #news .subject, #news .headline, .morenews dt, #leftmenu a', {hover: true});


//Galleri: Klik på pil, skifter billede
if ($('#imagegallery').length)
  $(function () {
    $(".nextImage").click($.exposure.nextImage);
    $(".prevImage").click($.exposure.prevImage);
  })

//Popup
  $("#leftmenu ul li ul li:first-child").addClass("border");
  $("#leftmenu ul li ul li:last-child").addClass("noborder");
  


//Tilføj og fjern streger på #leftmenu
  $("#leftmenu ul li ul li:first-child").addClass("border");
  $("#leftmenu ul li ul li:last-child").addClass("noborder");
  
  
  $(".infotip-word").mouseover(showMenu);
  var showMenu = function(ev) {
    var pos = $(this).offset();
    var width = $(this).width();
    $(".infotip-container").css( { "left": (pos.left + width) + "px", "top":pos.top + "px" });
    $(".infotip-container").fadeIn("fast");
  }

//Leftmenu animation
  if ($('#leftmenu ul li ul').length) { //Submenu eksisterer
    $(function () {
      $('#leftmenu ul li ul').each(function(){
        $(this).hide(); //Kør alle submenu op
        $(this).parent().children("a").addClass("submenu"); //tilføj class submenu
                
      });
      
      if ($('a.active').parent().children("ul").length) { //Active submenu eksisterer
        $(function () {
            $('a.active').parent().children("ul").slideDown("slow"); //Åbn dem
            
        });
      }
      
      if ($('#leftmenu ul li ul li a.active').length) { //Active submenu eksisterer
        $(function () {
            $('#leftmenu ul li ul li a.active').parent().parent().parent().children("a").addClass("active").parent().children("ul").slideDown("slow"); //Åbn og giv active
            
        });
      }
        
    });
  }
/*  if ($('#leftmenu ul li ul').length) { //Submenu eksisterer
    $(function () {
      $('#leftmenu ul li ul').each(function(){
        $(this).slideUp(); //Kør alle submenu op
        $(this).parent().children("a").addClass("submenu"); //tilføj class submenu
        
      });
      $('a.submenu').click(function() {
        $("#leftmenu .active").not(this).next().slideToggle().prev().removeClass("active");
        $(this).toggleClass("active");
        Cufon.replace('a.submenu', { hover: true });
        $(this).next().slideToggle('normal', function() {      
          $('.open').slideUp().removeClass("open");
        });
      });
        
    });
  }
*/  
  
//Undgå spam på e-mails
jQuery.fn.mailto = function() {
  return this.each(function(){
    var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
    $(this).before('<a href="mailto:' + email + '" rel="nofollow" title="Email ' + email + '">' + email + '</a>').remove();
  });
};
$('.noemail').mailto();

//Random billede i #header
  bgImageTotal=12;
  randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
  
  //Online skal den nedenstående URL ændres til "/images/headerbgs/"
  imgPath=('/images/headerbgs/'+randomNumber+'.jpg');
  $('#header').css('background-image', ('url("'+imgPath+'")'));



});
