/* Javascript: TBox Class 
 * Adjust heights of .box elements in t.css   
 * Version: 0.1 
 * Date: 03.01.2008 
 * Author: Deutsche Telekom AG, T-Com 
 * Editor: Tilman Moser - tilman.moser@telekom.de 
 *
 * This script depends on prototype.js v1.6.0 (prototypejs.org)
 * Changenote:
 * - changed way of selecting resizable elements from $$('box') to container.childElements to include <table> elements into the resizing routing. Beneficial sideeffect: Boxes with a box are not resized anymore.
 * - added support for captionless tables 
 */

var TBox = Class.create({
    initialize: function(containerID) {
      this.container = $(containerID)
      this.maxWidth = this.container.getWidth();
    },
    adjustBoxes: function() {
      rowWidth=0; boxes=[]; maxHeight=0;
      
      allBoxes = this.container.childElements(); 
      
      for (var i=0; i<allBoxes.length; i++) {
        dim = Element.getDimensions(allBoxes[i])
        boxWidth = parseInt(dim['width'])
        boxHeight= parseInt(dim['height'])
        if (rowWidth + boxWidth <= this.maxWidth) {
          rowWidth += boxWidth
          maxHeight = Math.max(maxHeight,boxHeight)
          boxes.push(allBoxes[i])
        } else {
          this.processBoxes(boxes,maxHeight)
          boxes = []
          boxes.push(allBoxes[i])
          maxHeight = boxHeight
          rowWidth = boxWidth
        }
      }
      this.processBoxes(boxes,maxHeight)
    },
    processBoxes: function(boxes,maxHeight) {
      if (boxes.length > 1)
        boxes.each(function(box){
          if (box.hasClassName('list') && box.hasClassName('naked')) { maxHeight = maxHeight + 27;}
          box.setStyle({
            height: maxHeight + 'px'
          });
        });
    }
})
document.observe("dom:loaded", function() {
  var t = new TBox('content')
 t.adjustBoxes()
});


function openPopUp(page,pWidth,pHeight)
{
    width = 300;
    height = 200;
    if ( ! pWidth ) pWidth = width;
    if ( ! pHeight ) pHeight = height;
    winurl = page+'&appWidth='+pWidth+'&appHeight='+pHeight;
    winname = "tmobile";
    test = window.open(winurl,winname,"top=50,left=50,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0,width="+pWidth+",height="+pHeight+",channelmode=0,dependent=0,fullscreen=0");
}

function book(a) {
	var url = a.getAttribute("href");
	window.open(url,"kc","width=750,height=560,left=100,top=200,status=yes,scrolling=yes,location=no,menubar=no,toolbar=no,resizable=yes");
}
