function offsHeight(elmName){
     var el;
     el=GetElem(elmName);
     if(el) return el.offsetHeight; else return 0;
}
function Window(mapImgControl){
     this.browserVersion = 0;
     this.isOpera = false;
     this.DetectBrowser();

     this.mWidthScroll = 0;
     this.mHeightScroll = 4;
     this.BorderWidth = 10;
     this.MapScrollWidth = 16;
     this.MapScrollHeight = 16;

     this.MinWidth = 800;
     this.MinHeight = 600;
     this.Width = this.MinWidth;
     this.Height = this.MinHeight;
     this.InfoPanel = GetElem("infoPanel");
     this.MapImg = mapImgControl;

     this.HeightOfOthers = offsHeight("HeaderPane")+offsHeight("FooterPane")+offsHeight("ToolBarPane");
     tmLabel = document.createElement("div");
     document.body.appendChild(tmLabel);
     tmLabel.className = "tmLabel";
     tmLabel.innerHTML = '<a href="http://sputnik.smr.ru/" target=_blank>ОАО "Самара-Информспутник"</a>';
     this.TMLabel = tmLabel;
     var W = this;
     window.onresize = function(){W.Resized();};
}


Window.prototype.Resized = function(){
	var pageWidth = (window.innerWidth)?window.innerWidth:((this.browserVersion)?document.body.offsetWidth:null);
	var pageHeight = (window.innerHeight)?window.innerHeight:((this.browserVersion)?document.body.offsetHeight:null);

	if(this.browserVersion == 1 && !this.isOpera){//only for IE
		pageWidth -= this.mWidthScroll;
		pageHeight -= this.mHeightScroll;
	}

	if (pageWidth < this.MinWidth || pageHeight < this.MinHeight){
		document.body.style.overflow = 'auto';
		if (pageWidth < this.MinWidth) pageWidth = this.MinWidth;
		if (pageHeight < this.MinHeight) pageHeight = this.MinHeight;
	}else{
		document.body.style.overflow = 'hidden';
	}

	// если размер не изменился то выходим (проверять необходимо тк IE выдает несколько событий на Resize)
	if((pageWidth == this.Width) && (pageHeight == this.Heigth))return;

	this.Width = pageWidth;
	this.Heigth = pageHeight;
	var infoWidth = Math.round((pageWidth*3)/10);//30%
	if(infoWidth<100)infoWidth=100;else if(infoWidth>317)infoWidth=317;
	this.InfoPanel.style.width = infoWidth;

	this.TMLabel.style.top = (pageHeight-10);
	this.TMLabel.style.left = (pageWidth-200);
	this.MapImg.Width = pageWidth - infoWidth - this.MapScrollWidth*2 - this.BorderWidth*4;
	this.MapImg.Height = pageHeight - this.HeightOfOthers - this.MapScrollHeight*2 - 80;
	this.MapImg.ProjectionChanged();

	this.InfoPanel.style.height = this.MapImg.Height - this.MapScrollHeight - 170;
	return false;
}

Window.prototype.DetectBrowser = function(){
	if (navigator.userAgent.indexOf("Opera") > -1){
		this.isOpera = true;
	}
	if (document.all) {
		this.browserVersion = 1; //>=IE4
	} else if (document.layers) {
		this.browserVersion = 2; //NS4
	}
}
