(function($) {
  $(document).ready(function() {
      // i = index , o = object
      // Move frontpage link lists from portlet body to portlet footer + other frontpage manipulation
      var height = 0;
      
      $(".frontPage .row_1 .portletItem").each(function(x){
          //Max portlet height in row 1
          height = $(this).outerHeight(true) > height ? $(this).outerHeight(true) : height;
      });
      //Equal portlet height in row 1
      $(".frontPage .row_1 .portletItem").height(height);
      
      height = 0;
      $(".frontPage .row_2 .portletItem").each(function(x){
          //Max portlet height in row 2
          height = $(this).outerHeight(true) > height ? $(this).outerHeight(true) : height;
      });
      //Equal portlet height in row 2
      $(".frontPage .row_2 .portletItem").height(height);

      
      height = 0;
      $(".frontPage #collage").each(function(x){
          
          height = $(this).outerHeight(true) > height ? $(this).outerHeight(true) : height;
      });
      //Equal portlet height in news portlet
      $(".frontPage #portal-column-two .portletfeedmixer .portletItem").css('min-height', height-57);
      
      var height = 0;
      $.each($(".frontPage .row_4 .portletfeedmixer"), function(i, o) {
          //Replace H2 with H3 in Nyt om styrelserne on frontpage
          $(".portletHeader h2", $(o) ).each(function (x) {
              $(this).replaceWith( "<h3>" + $(this).html() + "</h3>");
          });
          (i % 2 > 0) ? $(o).css('margin-left','7px') : $(o).css('margin-right','7px').css('clear','both');
          
          // Mark first item
          var firstitem = $( ".portletItem ul.arrowBullets li:first", $(o) ).addClass("first");
          
          // Add description to first feedmixer link
          $("<span/>").appendTo( firstitem )
                      .addClass( "description" )
                      .text( $( "a", $(firstitem) ).attr("title") )
                      .stringModifier( "shorten" , {start:0, maxlength:135, suffix:"&hellip;"} )
                      .prepend( "<br/>" );

          
          //Set height on rows - the extra 1px on margin bottom compensate for border collapse (somehow...)
          if (i % 2 > 0) {
              height = ($(o).height() > height) ? $(o).height() : height;
          }
          else {
              height = $(o).height();
          }
          (i % 2 > 0) ? $(o).parent().prev().andSelf().wrapAll('<div style="height: ' + height + 'px; margin-bottom: 1px"/>') : temp = 0;
          
      });
      
      // Remove arrow from non-link list-items in Arrow bullet lists in portlets
      $(".portlet ul.arrowBullets li").each(function(x) {
          if ( $(this).find("a").length == 0 ) {
              $(this)
                .css({"listStyleImage":"none",
                      "listStyleType": "disc"});
          }
      });
      
  })
})(jQuery);
