// Projekt: anderswohnen.net 2.0              */
// (C) 06/2010 Heil-Computertechnik, Dortmund */
//     Alle Rechte vorbehalten                */


      function callAdjustContent() {

        // 1:alert('onload');

        reAdjustElement('content', 'innercontent', 30);
        return state('resized');
        }


      function callReAdjustContent() {

        // 1:alert('onresize');

        reAdjustElement('content', 'innercontent', 30);
        return state('resized');
        }


      function eventstate(val) {
        reAdjustElement("content");
        return state(val);
        }


      function state (val) {
        var oldval;
        if (!state.val) {
          oldval = 'resized'; 
          state.val = 'resized'; }
        else {
          oldval = state.val; }
        if (!val) {} else {
          state.val = val; }
        return oldval;
        }


      function checkBrowserName(name) {  
      // *** check browser type via userAgent
      // *** known strings are 'MSIE', 'firefox', 'opera', 'safari'
        var agent = navigator.userAgent.toLowerCase();  
        if (agent.indexOf(name.toLowerCase())>-1) {  
          return true;  
          }  
        return false;  
        } 

      function checkMSIE() {  
      // *** short checkBrowser to 'MSIE'
        if(checkBrowserName('MSIE')){  
          return true; 
          } 
        return false; 
        }


// *** funktioniert so nur, wenn innercontent keine Höhenangabe hat oder diese so groß ist, dass der Inhalt voll reinpasst

      function reAdjustElement (containerId, elementId, distanceTop) {
        var container, element;
        var containerHeight, containerMaxHeight, containerTop, elementWidth;
        var wrkHeight;
        var scrollCtrl;

        scrollCtrl = checkMSIE();

        container=document.getElementById(containerId);
        containerTop=container.offsetTop;
        containerHeight=container.offsetHeight;
        containerMaxHeight=container.scrollHeight;
        element=document.getElementById(elementId);
        elementWidth=element.offsetWidth;

// alert('innercontent style.width:'+element.style.width+'/offsetWidth:'+element.offsetWidth+'/scrollWidth:'+element.scrollWidth);

        if (!reAdjustElement.initialTop) {
          reAdjustElement.initialTop=containerTop;
          reAdjustElement.initialHeight=containerHeight;
          reAdjustElement.initialMaxHeight=containerMaxHeight;
          reAdjustElement.initialWidth=elementWidth;

// alert('reAdjustElement.initialWidth:'+reAdjustElement.initialWidth);

          container.style.height=(containerHeight-0)+'px';
          }

        if (containerTop<distanceTop) {
          // *** viewport was made smaller in vertical direction
          if (!container.style.overflow) {
            // *** check if scrollbar is set
            container.style.overflow='auto';
            if (scrollCtrl) {
              // *** 2 lines for IE only:
              container.style.overflowX='hidden';
              element.style.width=(reAdjustElement.initialWidth-17)+'px'; }
            }
          else {
            if (container.style.overflow!='auto') {
              container.style.overflow='auto';
              if (scrollCtrl) {
                // *** 2 lines for IE only:
                container.style.overflowX='hidden';
                element.style.width=(reAdjustElement.initialWidth-17)+'px'; }}
            }

          wrkHeight=(containerHeight-0+containerTop);
          // *** following block: don't shrink container smaller than 32 pixel
          if (wrkHeight>32) {
            if (container.style.height!=((wrkHeight-distanceTop)+'px')) {
              container.style.height=(wrkHeight-distanceTop)+'px'; }
            }
          else {
            if (container.style.height!='32px') {
              container.style.height='32px'; } }
          }
        else {
          // *** viewport was made larger in vertical direction, but ...
//
// is it large enough, to disable bars ?
//
          if (!container.style.overflow) {
            container.style.overflow='hidden';
            if (scrollCtrl) {
              // *** for IE only:
              element.style.width=reAdjustElement.initialWidth+'px'; }
            }
          else {
            if (!container.style.overflow!='hidden') {
              container.style.overflow='hidden';
              if (scrollCtrl) {
                // *** for IE only:
                element.style.width=reAdjustElement.initialWidth+'px'; }}
            }

          if (containerHeight<reAdjustElement.initialHeight) {
            wrkHeight=(containerHeight-0+containerTop);
            if (container.style.height!=(wrkHeight-distanceTop)+'px') { 
              container.style.height=(wrkHeight-distanceTop)+'px';
              }
            if (container.style.overflow!='auto') {
              container.style.overflow='auto';
              if (scrollCtrl) {
                // *** 2 lines for IE only:
                container.style.overflowX='hidden';
                element.style.width=(reAdjustElement.initialWidth-17)+'px'; }}
            }
          else {
            if (container.style.height!=(reAdjustElement.initialHeight-0)+'px') { 
              container.style.height=(reAdjustElement.initialHeight-0)+'px';
              }
            if (!container.style.overflow=='hidden') {
              container.style.overflow='hidden';
              if (scrollCtrl) {
                // *** for IE only:
                element.style.width=reAdjustElement.initialWidth+'px'; }}}
            }
      }


      function shade(picture) {
        picture.style.clip="rect(0px 100px 383px 0px)";
        picture.style.bottom="-354px";
        }

      function illume(picture) {
        picture.style.clip="rect(384px 100px 766px 0px)";
        picture.style.bottom="30px";
        }

