// autoload-stuff
window.addEvent('domready', function() {
  
  // menuHeight = contentHeight, min-height IE Hackstuff
  var contentHeight = $('content').getSize().size.y;
  var leftHeight = $('leftMenu').getSize().size.y;
  var max = Math.max(leftHeight, contentHeight);
  
  $('leftMenu').setStyles(
      'min-height: ' + max + 'px;' +
      'height: auto !important;' + 
      'height: ' + max + 'px;'
    );
  // 90 is the value for padding+margin vertically
  $('content').setStyles(
      'min-height: ' + (max-90) + 'px;' +
      'height: auto !important;' + 
      'height: ' + (max-90) + 'px;'
    );
  
  // much more beautiful for anchors
  new SmoothScroll();
  
  // last menu elem without border
  $$('#leftMenu ul').each(function(listItem) {
    var lastLinks = listItem.getLast().getChildren();
    lastLinks.each(function (lastLink){
      lastLink.setStyle('border', 'none');
    })
  });
  
  // Finally we add PNG-Support for IE6 - ootools-style :-)
  // remembers the id, classes, alt and title tag of the image
  // and shows a cursor-hand if is contained in a link
  // does not affect background-pngs - do this in ie6.css instead
  if (window.ie6) {
    $$('img').each(function(i) {
      iSrc = i.getProperty('src');
      iWidth = i.getSize().size.x;
      iHeight = i.getSize().size.y;
      iID = i.getProperty('id');
      iClass = i.getProperty('class');
      iTitle = i.getProperty('title') + " " + i.getProperty('alt');
      iStyle = "display: inline-block; ";
      if (i.getParent().getProperty('href') !== "") {
        iStyle += "cursor: pointer; "
      }
      var iName = iSrc.toLowerCase();
      if (iName.substring(iName.length - 3, iName.length) == "png") {
        var strNewHTML = '<span id="' + iID + 
                        '" class="'+ iClass + 
                        '" title="' + iTitle +
                        '" style="' + iStyle +
                        'width: ' + iWidth + 
                        'px; height: ' + iHeight + 
                        'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + 
                        "(src=\'" + iSrc + "\', sizingMethod='scale');\"></span>";
        i.outerHTML = strNewHTML;
      }
    });
  }
  
  // AAA-Fontresizing script
  var fontStep = 1;
  var fontDefault = 12;
  
  $('aPlus').addEvent('click', function(e) {
    incFontSize(fontDefault, fontStep);
  });
  
  $('aMinus').addEvent('click', function(e) {
    decFontSize(fontDefault, fontStep);
  });
  $('aReset').addEvent('click', function(e) {
    resetFontSize(fontDefault);
  });
  
});

// Font-Resizing functions

function incFontSize(org, step) {
  $$('#content p, #leftMenu ul li a').each(function(e) {
    var curFontSize = e.getStyle('font-size');
    if (curFontSize == '') {
      curFontSize = org;
    }
    curFontSize = parseInt(curFontSize.replace('px', ''));
    curFontSize += step;
    e.setStyle('font-size', curFontSize + 'px');
  });
}

function decFontSize(org, step) {
  $$('#content p, #leftMenu ul li a').each(function(e) {
    var curFontSize = e.getStyle('font-size');
    if (curFontSize == '') {
      curFontSize = org;
    }
    curFontSize = parseInt(curFontSize.replace('px', ''));
    curFontSize -= step;
    e.setStyle('font-size', curFontSize + 'px');
  });
  
}

function resetFontSize(org) {
  $$('#content p, #leftMenu ul li a').each(function(e) {
    e.setStyle('font-size', org + 'px');
  });  
}

