$(document).ready(function(){
    //Handle first and last childs
    $('.news-post').last().children('div.news-border').remove();
    
    
    //dropdown
    $('#main-menu ul li').hoverIntent(       
        function(){
            //set height of sub ul
            $('.sub-menu', this).width($(this).width() + 2);
            
            //slide in sub menu
            $('.sub-menu', this).slideDown(300);
            
        }, 
        function(){
             $('.sub-menu', this).slideUp(300);
        }
    ); // end hover intent
    
    
    //remove arrow frem menu item if there is no dropdown
    $('#main-menu ul li').not('ul.sub-menu li').each(function(i, e){
        
        if($(e).children('ul').size() > 0){           
            
        } else {            
            
            $(e).children('a').addClass('no-dropdown');
                      
        }
        
    });    
    
    
    //add >> to list items in main menu 
    $('.sub-menu li a').each(function(i, e){
        $(e).append(' &raquo;');
    });
    
    //display star ratings based on input from wp
    
    
    function setStars(rate, dir){                                       
        //loop through list of stars    
        $('.stars li').each(function(i, e){
            
            //if the index of the item + 1 is smaller than the rating show the star, if not show faded star
            if((i + 1) < (rate)){

                $(e).children('img').attr('src', dir + "/images/rate-star.png");

            } else {

                $(e).children('img').attr('src', dir + "/images/rate-star-fade.png");
            }

        });

    }  
    
    //ad "Lån op til:" to beløb dd
    $('#menu-item-24 ul').prepend('<li>Lån op til:</li>');
    
   
    //handle backgroundpositions on "Ansøg" btn
    $('.apply-middle a').hover(function(){
        
        $('.apply-middle a').css('background-position', '0 -46px');
        $('.apply-right a').css('background-position', '0 -46px');
        
    }, function() {
        $('.apply-middle a').css('background-position', '0 0px');
        $('.apply-right a').css('background-position', '0 0px');
    });
    
    $('.apply-right a').hover(function(){
        $('.apply-right a').css('background-position', '0 -46px');
        $('.apply-middle a').css('background-position', '0 -46px');
        
    }, function() {
         $('.apply-right a').css('background-position', '0 0px');
        $('.apply-middle a').css('background-position', '0 0px');
    });
    
}); // end ready

