var firstime = true;
var gf = true;
function fixDisplay()
{
  var monsize = GetInnerSize();
  var obj =e('someTressID');
  var obj2 =e('mapDividerID');
  if(obj!= null && obj != "undefined"){
    if(monsize[0] >= 920) {  obj.style.left = monsize[0] - 263 + "px";  obj.style.display="block"; }
    else { obj.style.display="none"; }
  }
  obj2.style.width = monsize[0] + "px";
  obj2.style.display="block";
}


function GetInnerSize () 
{
	var x,y;
	if (self.innerHeight) /*all except Explorer*/ 
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)/*Explorer 6 Strict Mode*/ 
	{
		x = top.document.documentElement.clientWidth;
		y = top.document.documentElement.clientHeight;
	}
	else if (document.body) /*other Explorers*/ 
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}

function adjust_layout()
{
  var inner = GetInnerSize();
  e('container').style.height = inner[1]-128 + "px";
  e('sidebar').style.height = "100%";
  e('map').style.height = "100%";
  e('legend').style.height = "100%";
  
  e('sidebar').style.width= "270px";
  e('map').style.left = e('sidebar').style.width;
  
  if(firstime)
  {
    /*e('legend').style.width = "10px";*/
    e('legend').style.width = "190px";
    e('legend').visibleWidth = "190px";
    e('legend').invisibleWidth= "10px";
    e('legend').style.left = inner[0] - parseInt(e('legend').style.width) + "px";
    e('legendShowHide').title="Hide legend";
    e('legend').style.display="block";
    /*toggle*/
    showHideLegend(!gf);
  }
  else
  {
    if(e('legendShowHide').className=="imgShowHideLegend_show")
    { e('legend').style.left = inner[0] - parseInt(e('legend').visibleWidth) + "px"; }
    else
    { e('legend').style.left = inner[0] - parseInt(e('legend').invisibleWidth) + "px"; }
  }
  update_map_layout();
  firstime=false;
}
function update_map_layout()
{
  var inner = GetInnerSize();
  e('map').style.width = inner[0]- parseInt(e('legend').style.width) - parseInt(e('sidebar').style.width) + "px";
  fixDisplay();
  if(map) { map.checkResize(); ovcontrol.hide(true); ovcontrol.show(true); }
}

function getStyle(el,styleProp)
{
	var x = e(el);
	if (x.currentStyle){var y = x.currentStyle[styleProp];}
	else if (window.getComputedStyle){var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);}
	return y;
}
function showHideLegend(bl)
{
  var inner = GetInnerSize();
  var obj = e("legendShowHide");
  if(bl)
  {
    obj.className="imgShowHideLegend_show";
    e("legend").style.width = e("legend").visibleWidth;
    e("legend").style.left=inner[0]-parseInt(e("legend").visibleWidth)+ "px";
    obj.title="Hide legend";
    gf=true;
    getFacilities(true);
  }
  else
  {
    obj.className="imgShowHideLegend_hide";
    e("legend").style.width = e("legend").invisibleWidth;
    e("legend").style.left=inner[0]-parseInt(e("legend").invisibleWidth) + "px";
    obj.title="Show legend";
    gf=false;
  }
  update_map_layout();
}

