//<![CDATA[
//<![CDATA[
var CPHB = {

  getHeight: function( id) {
    var element = $( id),
        height = parseFloat( element.getHeight()) + parseFloat( element.getStyle( "padding-top")) + parseFloat( element.getStyle( "padding-bottom"));

    return height;
  },

  max: function( a, b) {
    return  ( a >= b)? a: b;
  },

  /*
  patchForIE6: function() {
    if( /MSIE 6/.test( navigator.userAgent)) {
      $( "main-logo").replace( '<div id="main-logo" style="position:relative; height:128px; width:128px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src=\'/images/site/logo.cphb.png\',sizingMethod=\'scale\');"></div>');
    }
  },
  */

  handleTopBanner: function() {
    var topBanner = $( "top-banner");

    if( topBanner) {

      // ver si el banner tiene que estar visible o no
      var cookieName = "cphb_banner_cerrado",
          cookieJar = new CookieJar( {
            expires: 24*60*60,   // un día
            path: "/"
          });

      if( cookieJar.get( cookieName)) {
        $( "header").setStyle( { marginBottom: "1em"});
        return;  // que el banner quede oculto
      }

      topBanner.show();
      // ^

      $( "close-top-banner").observe( "click", function( evt) {
        evt.stop();
        topBanner.hide();
        cookieJar.put( cookieName, true);
        $( "header").setStyle( { marginBottom: "1em"});
      }.bindAsEventListener( this));
    }
  },

  main: function() {
    var leftHeight = this.getHeight( "left-menu"),
        rightHeight = this.getHeight( "right-menu"),
        verticalHeight = this.max( leftHeight, rightHeight),
        centerHeight = this.getHeight( "middle-panel"),
        diff = centerHeight - verticalHeight;

    // console.log( "leftHeight = " + leftHeight + ", rightHeight = " + rightHeight + ", centerHeight  = " + centerHeight + ", diff = " + diff);
    if( diff > 0) {
      // el +16 es por el margin-bottom original de 1em de los menus+panel central
      $( rightHeight > leftHeight ? "right-menu": "left-menu").setStyle( {
        marginBottom: "" + (diff + 16) + "px"
      });
    }

    //this.patchForIE6();
    this.handleTopBanner();
  }
}
//]]>

//]]>