
function dsGetPageSize () {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}


function dsEffectsClass () {

	this.setElementOpacity = function (elem, nOpacity) {
		var opacityProp = this.getOpacityProperty();
		if (!elem || !opacityProp) return;
		if (opacityProp=="filter") {
			nOpacity *= 100;
			var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
			if (oAlpha) oAlpha.opacity = nOpacity;
				else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
		} else elem.style[opacityProp] = nOpacity;
	}

	this.getOpacityProperty = function () {
		if (typeof document.body.style.opacity == 'string') return 'opacity';
		else if (typeof document.body.style.MozOpacity == 'string') return 'MozOpacity';
		else if (typeof document.body.style.KhtmlOpacity == 'string') return 'KhtmlOpacity';
		else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) return 'filter';
		return false;
	}
}

dsEffects = new dsEffectsClass();

function dsModalWindowClass () {

	this.hideBody = function () {
    
		this.pageSize = dsGetPageSize();		
	
		this.shadowDiv = document.createElement("DIV");
		this.shadowDiv.style.position = 'absolute';
		this.shadowDiv.style.top = '0px';
		this.shadowDiv.style.left = '0px';
		this.shadowDiv.style.width = this.pageSize[0]+'px';
		this.shadowDiv.style.height = this.pageSize[1]+'px';
		this.shadowDiv.style.backgroundColor = 'black';
		document.body.appendChild(this.shadowDiv);
		dsEffects.setElementOpacity(this.shadowDiv, 0.6);

	}

	this.show = function (text, dWidth, dHeight) {
		this.hideBody();
		if (!dWidth) dWidth = 640;
		if (!dHeight) dHeight = 480;
		this.dWidth = dWidth;
		this.dHeight = dHeight;
		this.modalDiv = document.createElement("DIV");
		document.body.appendChild(this.modalDiv);

		Body = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
		SY = window.scrollY ? window.scrollY : Body.scrollTop;
		SX = window.scrollX ? window.scrollX : Body.scrollLeft;

		this.modalDiv.id = 'modal_form';
		this.modalDiv.style.position = 'absolute';
		oLeft = SX + Math.round((this.pageSize[2]/2) - (dWidth/2));	
		oTop = SY + Math.round((this.pageSize[3]/2) - (dHeight/2));
		this.modalDiv.style.left =  oLeft + 'px';
		this.modalDiv.style.top =  oTop + 'px';
		this.modalDiv.style.width = dWidth + 'px';
		this.modalDiv.style.height = dHeight + 'px';
		this.modalDiv.innerHTML = text;
		return false;
	}

	this.close = function () {
	    document.body.removeChild(this.shadowDiv);
	    document.body.removeChild(this.modalDiv);
	    return false;
	}

	this.showBody = function () {
		document.body.removeChild(this.shadowDiv);
	}
}

dsModalWindow = new dsModalWindowClass();

function showPano () {
    text = '<div style="background:#FFFFFF; width:620px; height:420px; position:relative;"><img src="img/window-close.gif" width="9" height="9" alt="Закрыть" style="cursor:pointer; position:absolute; top:1px; right:1px;" onclick="return dsModalWindow.close();" /><div id="pano" style="padding:10px; "></div></div>';
	dsModalWindow.show(text, 620, 420);
	createFlash('pano', '.files/pano/pano.swf?panoMetaDataUrl=.files/pano/xml/view_a.xml', 600, 400, '', 0, 0, '', true);
	return false;
}
