
/* - vtu.js - */
(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);
        });

      $.each($(".arrowBulletsTwoColumn"), function(index) {
	      $.each($('li', this), function(i, o) {
		  var li = $(o);
		  if (i%2==0) {
		      li.addClass("right");
		  } else { // sadly, for ie7 it is not enough to clear the right li 
		      vc = $(document.createElement('div'));
		      vc.addClass("visualClear");
		      vc.insertAfter(li);
		  }
	      });
	  });

      // Special wrapper for allow-bullets (for IE7)
      $("ul.arrowBullets").wrap("<div class=\"listContainer\" />");

      // Wide portlets CSS
      $.each($(".portlet"), function(i, j) {
          if ($(j).width() > 600) $(j).addClass("wideportlet");
      });

      // used for form buttons
      $.each($('div.searchColumnOne'), function(i, o) {
          var column_one_height = $(this).height();
          var column_two_height = $('div.searchColumnTwo').height();
          var form_fields_height = column_one_height - 12;
          if (column_two_height > column_one_height) {
            var form_fields_height = column_two_height - 12;
          }
          $('div.searchColumnThree').css('height', form_fields_height);
          $('div.searchColumnThree').css('min-height', form_fields_height);
        });
      
      // 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 cnodes = $(j).children();
            // We only do the following, if it is a table with headers but without thead tag
            // This is for backward compability, and because kupu in class names doesn't distinguish
            // between plain tables with and without table headers.
            
            // Note: take care cnodes could contain: caption | thead | tbody - quick fix for that
            if (cnodes.length > 1 && cnodes.get(0).tagName.toLowerCase() != "thead" && cnodes.get(1).tagName.toLowerCase() != "thead") {
              var children = $("tbody", $(j)).eq(0).remove().children();
              var caption = $("caption", $(j));
              var head = $("<thead />").append(children);
              $(j).prepend(head);
              $(j).prepend(caption);
            };

           if ($("tbody", j).length) {
                $(j).tablesorter({widgets: ['zebra']});
           } else {
              $("th", j).addClass('header');
           }
        });
      
      // 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");
      });
      
      // alert('ping im from vtu.theme');
      
      
      // apply rounded corners to paragraphs containing a span
      // with visual highlighting

      // Note: temporaly disabled created problems with the two-columns-disable-columns template
      // // Fix for FF3 where the content column inherits table width (100%)
      // $.each($("div.portletPageColumns"), function(i, j) {
      //     var width = $(this).width();
      //     $(this).css("width", width);
      // });
      
      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);

      $("div.factsFloatRight").corner(settings);
      $("div.factsFloatLeft").corner(settings);

      $('dd.actionMenuContent').bgiframe();
    });

 })(jQuery);

