/**
 * JavaScript for the cp3 pages
 * 
 * Requires: jQuery and translator
 */

jQuery(document).ready(function () {
    // Strip everything set inside the posts... :)
    jQuery('div.entry span').attr('style', '');

    // add :: to rss feeds
    jQuery('div#boxleft li')
      .filter(function (i) {return i > 0;/* not the first */})
      .each(function () { x = jQuery(this); x.html(':: ' + x.html()); });
    jQuery('div#boxright li')
      .filter(function (i) {return i > 0;/* not the first */})
      .each(function () { x = jQuery(this); x.html(':: ' + x.html()); }); 

    // Add extra link to event archives if applicable
    if (0 && jQuery('.eventpage_notall')[0]) {
      var ul = jQuery('div.sidebar_text ul');
      if (ul[0]) {
	ul = jQuery(ul[0]);
	var title = jQuery('#maincontent h1')[0];
	if (title) {
	  title = ' for ' +jQuery(title).html();
	} else {
	  title = '';
	}
	ul.html('<li><a href="'+location.href+'?all=1">Archives'+title+'</a></li>' + ul.html());
      };
    };
    
    /* Make the feed boxes the same height */
    var boxes = jQuery('div.feedbox');
    jQuery('div.feedbox ul').each(function () {
	var ul = jQuery(this);
	if (ul) {
	  /**
	   * At least one child
	   */
	  while (ul.height() > 80 && ul.children()[1]) {
	    jQuery(ul.children()[ul.children().length-1]).remove();
	  }
	}
      });
    /* Next, get the height of the two boxes, and use the maximum */
    var boxes = jQuery('div.feedbox');
    var h = 0;
    for (var i = 0 ; i < boxes.length; i++) {
      var nh = jQuery(boxes[i]).height();
      if (nh > h) h = nh;
    }
    boxes.height(h);

    /**
     * Finally replace CP3 with CP&sup3; 
     * - requires translator
     */
    (new Translator(function( text ){
	    return text.replace(/CP3/g, "CP³");
    })).traverse(this);
  });

