var iMinWidth = 1000;
var iMaxWidth = 1256;
var iTop = 20;
var iMargin = 100;


function Resize_Layout() {
   var iWindowWidth = Get_WindowWidth();
   var iCalcWidth;

   if (iWindowWidth < iMinWidth) { iCalcWidth = iMinWidth; }
   else if (iWindowWidth > iMaxWidth) { iCalcWidth = iMaxWidth; }
   else { iCalcWidth = iWindowWidth; }

   Set_LayoutPosition();
   Set_LayoutWidth(iCalcWidth);
   Set_LayoutHeight();
   Set_PositionMainMenu();
}

function Set_LayoutPosition() {
   document.getElementById("head_image").style.left = iMargin + 'px';
   document.getElementById("main-navi").style.left = iMargin + 'px';
   document.getElementById("main-navi-bck").style.left = (iMargin + 2) + 'px';
   document.getElementById("site").style.left = iMargin + 'px';
   document.getElementById("footer_free").style.left = iMargin + 'px';
   document.getElementById("background").style.left = (iMargin + 3) + 'px';   

}

function Set_PositionMainMenu() {
	var iMainNaviContent = document.getElementById("main-navi-content").offsetWidth;
        var iMainNavi = document.getElementById("main-navi").offsetWidth;
	if(iMainNavi-iMainNaviContent > 98 ) {
	    document.getElementById("main-navi-content").style.styleFloat = "left";
            document.getElementById("main-navi-content").style.cssFloat = "left";
	    document.getElementById("main-navi-content").style.marginLeft = "98px";
	    document.getElementById("main-navi-bck-content").style.styleFloat = "left";
            document.getElementById("main-navi-bck-content").style.cssFloat = "left";
	    document.getElementById("main-navi-bck-content").style.marginLeft = "98px";
	}	
}


function Set_LayoutWidth(iCalcWidth) {
   document.getElementById("head_image").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("head_image_02").style.width = (iCalcWidth - (2 * iMargin) - 
      document.getElementById("head_image_01").offsetWidth -
      document.getElementById("head_image_03").offsetWidth) + 'px';
   document.getElementById("head_image_04").style.width = (iCalcWidth - (2 * iMargin) - 
      document.getElementById("head_image_01").offsetWidth) + 'px';
   document.getElementById("main-navi").style.width = (iCalcWidth - (2 * iMargin) - 4) + 'px';
   document.getElementById("main-navi-bck").style.width = (iCalcWidth - (2 * iMargin) - 4) + 'px';
   document.getElementById("site").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("head").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("body").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("body_middle").style.width = (iCalcWidth - (2 * iMargin) -
      document.getElementById("body_left").offsetWidth -
      document.getElementById("body_right").offsetWidth) + 'px';
   document.getElementById("content").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("content_middle").style.width = (iCalcWidth - (2 * iMargin) - 40 -
      document.getElementById("content_left").offsetWidth -
      document.getElementById("content_right").offsetWidth) + 'px';
   document.getElementById("footer").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("footer_middle").style.width = (iCalcWidth - (2 * iMargin) -
      document.getElementById("footer_left").offsetWidth -
      document.getElementById("footer_right").offsetWidth) + 'px';
   document.getElementById("footer_free").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("footer_free_02").style.width = (iCalcWidth - (2 * iMargin) -
      document.getElementById("footer_free_01").offsetWidth -
      document.getElementById("footer_free_03").offsetWidth) + 'px';
   document.getElementById("background").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("bck_head").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("bck_head_02").style.width = (iCalcWidth - (2 * iMargin) -
      document.getElementById("bck_head_01").offsetWidth -
      document.getElementById("bck_head_03").offsetWidth) + 'px';
   document.getElementById("bck_body").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("bck_footer").style.width = (iCalcWidth - (2 * iMargin)) + 'px';
   document.getElementById("bck_footer_02").style.width = (iCalcWidth - (2 * iMargin) -
      document.getElementById("bck_footer_01").offsetWidth -
      document.getElementById("bck_footer_03").offsetWidth) + 'px';
}

function Set_LayoutHeight() {
   var iBody = 0;
   var iBodyLeft = document.getElementById("content_left").offsetHeight;
   var iBodyMiddle = document.getElementById("content_middle").offsetHeight;
   var iBodyRight = document.getElementById("content_right").offsetHeight;
   if ((iBodyLeft >= iBodyMiddle) && (iBodyLeft >= iBodyRight)) {
      iBody = iBodyLeft;
   } else if ((iBodyMiddle >= iBodyLeft) && (iBodyMiddle >= iBodyRight)) {
      iBody = iBodyMiddle;
   } else {
      iBody = iBodyRight;
   }

   document.getElementById("body").style.height = iBody+'px';
   document.getElementById("content").style.height = iBody+'px';
   document.getElementById("bck_body").style.height = (iBody + 103)+'px';   
   document.getElementById("body_left").style.height = iBody+'px';
   document.getElementById("body_middle").style.height = iBody+'px';
   document.getElementById("body_right").style.height = iBody+'px';
   document.getElementById("content_left").style.height = iBody+'px';
   document.getElementById("content_middle").style.height = (iBody-40)+'px';
   document.getElementById("content_top").style.height = (iBody-65)+'px';
   document.getElementById("content_right").style.height = (iBody-45)+'px';
   document.getElementById("footer_free").style.top = (iTop) +
      document.getElementById("head").offsetHeight +
      iBody + 'px';

}

function Output_WindowSize() {
   alert("Systemmeldung: " + "\n" 
           + "Fensterbreite: " + Get_WindowWidth() + " px" + "\n" 
           + "Fesnterhöhe: " + Get_WindowHeight() + " px");
}

function Get_WindowWidth() {
   if (window.innerWidth) {
      return window.innerWidth;
   } else if (document.body && document.body.offsetWidth) {
      return document.body.offsetWidth;
   } else {
      return 0;
   }
}

function Get_WindowHeight() {
   if (window.innerHeight) {
      return window.innerHeight;
   } else if (document.body && document.body.offsetHeight) {
      return document.body.offsetHeight;
   } else {
      return 0;
   }
}
