
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - vtu.js - */
// when html is load final - jquery style based on prototype...

(function($) {    
  $(document).ready(function() {
      // handle ajax sections
      // .documentContent// - / means something under the class
      //
      // i = index , o = object
      // move facts box up
      $.each($(".documentContent//.dom-moveUp"), function(i, o) {
          var origin = $(o);
          var destination = $('div.plain');
          origin.insertBefore(destination);
        });
      
      // move history box down so it doesn't collide with the facts box
      $.each($(".documentContent//div.reviewHistory"), function(i, o) {
          var origin = $(o);
          var destination = $('div.plain');
          origin.insertAfter(destination);
        });
      
      // insert, remove help text for an input field
      // $('.dom-inputFieldHint').hint();
      
      // used for form buttons
      $.each($('div.searchColumnOne'), function(i, o) {
          var fields = $(o).children('.field');
          var len = (fields.length);
          $("div.searchColumnThree").addClass("column"+len+"Rows");
        });
      
      // fix kupu table markup such that the first <tbody> is changed to
      // a <thead>; this is required for ``jquery.tablesorter.js``.
      $.each($('table.plain'), function(i, j) {
          var tChildren = $(j).children();
          if (tChildren.eq(0).get(0).tagName.toLowerCase() == "tbody") {
              var children = tChildren.eq(0).remove().children();
              var head = $("<thead />").append(children);
              $(j).prepend(head);
          }
        });
      
      // Add wrapper inside portlet footer on portlet pages
      // Used to set correct margin on absolute positioned footer
      $.each($('.portletPageColumns .portletFooter'), function(i, j) {
          $(j).wrapInner("<span></span>");
          $(j).children(":first").addClass("portletFooterWrapper");
          // if ($(j).parent(".portletCollectionSpecialFirstItem") && $(j).children(":first") && $.browser == "msie")
          //   $(j).children(":first").css("border-top","1px solid #99a5a5");
      });
      
      // invoke table sorting with "zebra" effect
      $("table.plain").tablesorter({widgets: ['zebra']}); 
      
      // add classes "first" and "last" to header cells
      // and wrap span in cells (IE issue)
      $.each($("table.plain>thead>tr"), function(i, j) {
          var cells = $("th", $(j).eq(0));
          cells.eq(cells.length-1).addClass('last');
          cells.eq(0).addClass('first');
          $.each(cells, function(a, b) {
              $(b).wrapInner("<span></span>");
          });
      });
      
      // add class "first" to first table body row
      $.each($("table.plain>tbody"), function(i, j) {
          var rows = $("tr", $(j));
          rows.eq(0).addClass("first");
      });
      
      // apply rounded corners to paragraphs containing a span
      // with visual highlighting
      
      // Fix for FF3 where the content column inherits table width (100%)
      // Not needed for onlinecirius
      // $.each($("div.portletPageColumns"), function(i, j) {
      //     var width = $(this).width();
      //     $(this).css("width", width);
      // });
      
      // Set numbered class on portlets to set row height on frontpage
      // First we wrap the two small plone column portlets
      // Then we append numbered portlet class to the main portlet rows in the two columns
      // Now from CSS you can set height on "portletRow1", "portletRow2" &c.
      $("div.portletPageColumns .ploneColumn").wrapAll('<div class="portlet"></div>');
      $.each($("div.portletPageFirstColumn .visualPadding>.portlet"), function(i, j) {
          $.each($(j), function(a, b) {
              $(b).addClass("portletRow" + (i+1));
          });
      });
      $.each($("div.portletPageSecondColumn .visualPadding>.portlet"), function(i, j) {
          $.each($(j), function(a, b) {
              $(b).addClass("portletRow" + (i+1));
          });
      });

      // --- Set correct top margin on rich image portlet footer
      var richHeight = $(".portletRichImage").height();
      var $richFooter = $(".portletRichImage .portletFooter");
      $richFooter.css({"top":richHeight-$richFooter.height()-21})

      // --- Set height on portlet with jquery.equalizecols.js and jquery.onfontresize.js
      // --- Thanks to Tom Deater for these valuable jQuery plugins.
      var $rowoneportlets = $("div.portletPageColumns .portletRow1");
      if ($rowoneportlets) $rowoneportlets.equalizeCols();
      var rowtwo = $.makeArray( $("div.portletPageColumns .portletPageFirstColumn .portletRow2 .ploneColumn .portlet") );
      $.merge(rowtwo, $.makeArray( $("div.portletPageColumns .portletPageSecondColumn .portletRow2") ));
      var $rowtwoportlets = $(rowtwo);      
      if ($rowtwoportlets) $rowtwoportlets.equalizeCols();
      
      
            
      var settings = {
      tl: { radius: 5 },
      tr: { radius: 5 },
      bl: { radius: 5 },
      br: { radius: 5 },
      antiAlias: true,
      autoPad: true };
      
      $("span.visualHighlight").parent("p").
        wrap('<div class="highlightContainer" style="background-color: #e6f3f3">'+
             '</div>').parent('div').
        corner(settings);

      $('dd.actionMenuContent').bgiframe();
    });
    // Very crude way of truncating link text in specific portlet on frontpage
    // http://trac.headnet.dk/vtu-faelles/ticket/2442
    $.each($('.section-frontpage .portletPageColumns .firstRow .position-3 .portletItem a'),  function() { 
        maxlength = 100;
        maxsingleline = 18;
        link = $(this); 
        markup = link.html();
        datestart = markup.lastIndexOf('<span class="portletItemDetails">');
        text = $.trim(markup.substr(0, datestart));
        if (maxlength < text.length) {
            text = text.substr(0, maxlength);
            lastspace =  text.lastIndexOf(' ');
            if (lastspace != -1) {
                text = text.substr(0, lastspace);
            } else {
                text = text.substr(0, maxsingleline);
            }
            link.html(text+' &hellip;'+markup.substr(datestart, markup.length));
        }
      });
})(jQuery);

// swap approach skipped 
function swap(origin, destination) {
    var temp = origin.after('<span></span>').next();
    destination.after(origin);
    destination.insertBefore(temp);
    temp.remove();
}


/* - jquery-integration.js - */
// http://en.iu.dk/portal_javascripts/jquery-integration.js?original=1
var jq=jQuery.noConflict();if(typeof cssQuery=='undefined'){
function cssQuery(s,f){return jq.makeArray(jq(s,f))}};

