isGecko = navigator.userAgent.toLowerCase().indexOf("gecko") != -1;

addEventListener = function(func,obj,listener)
{	if(listener)(isGecko) ? obj.addEventListener(listener,func,false) : obj.attachEvent("on"+listener,function(obj){return function(event){obj.handleEvent(event);}}.call(func,func));	}

toCenter = function(topDiv)
{	if(topDiv)
	{	topDiv.style.left = "50%";
		topDiv.style.top = "47%";
		topDiv.style.marginLeft=-Number(topDiv.style.width.replace("px",""))/2;
		topDiv.style.marginTop=-Number(topDiv.style.height.replace("px",""))/2;	}	}

setAttribute = function(obj,attribute,attr)
{	if(obj)if(obj.nodeType!=3)
	if(attribute=="style")(isGecko) ? obj.setAttribute("style",attr) : obj.style.setAttribute("cssText",attr);
	else if(attribute=="class")obj.setAttribute((isGecko)?"class":"className",attr);
		else obj.setAttribute(attribute,attr);	}
		
getAttribute = function(obj,attribute,nolower)
{	var ret;
	if(obj)if(obj.nodeType!=3)
	if(attribute=="style")ret = (isGecko) ? obj.getAttribute("style") : obj.style.getAttribute("cssText");
	else if(attribute=="class")ret = obj.getAttribute((isGecko)?"class":"className");
		else ret = obj.getAttribute(attribute)
	if(ret)return((nolower?ret:ret.toLowerCase()))
	else return("");	}
	
loadXML = function(path)
{	if(window.ActiveXObject)var request = new ActiveXObject('Microsoft.XMLHTTP');
	if(window.XMLHttpRequest)var request = new XMLHttpRequest();
	if(request)
	{	request.open('GET',path,false);
		request.send(null);
		var code=request.responseText;
		return(code);	}	}

/////////////////////////////////
///////// Прозрачность
/////////////////////////////////
setOpacity = function(elem, nOpacity)
{	var opacityProp = 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 if(elem.style)elem.style[opacityProp] = nOpacity;	}
	
getOpacity = function(elem)
{	var opacityProp = getOpacityProperty();
	if (!elem || !opacityProp) return null;
	if (opacityProp=="filter")
	{	var oAlpha = (elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha);
		return (!oAlpha?0:oAlpha.opacity/100);	}
	else return(Number(!elem.style[opacityProp]?0:elem.style[opacityProp]));	}

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;	}
	
				
/////////////////////////////////
///////// Функции
/////////////////////////////////
maps = function () 
{   var map = new YMaps.Map(document.getElementById("YMapsID1"));
	map.setCenter(new YMaps.GeoPoint(30.3076, 59.82999), 15);

	var s = new YMaps.Style();
	s.balloonContentStyle = new YMaps.BalloonContentStyle
	(	new YMaps.Template("<div><a target='_blank' href='http://maps.yandex.ru/?ll=30.3076, 59.82935&z=15&l=map'><img src='$[description]'></a></div>")	);

	var placemark = new YMaps.Placemark(new YMaps.GeoPoint(30.3076, 59.82935), {style: s} );
	placemark.description = 'img/logo.gif';
	map.addOverlay(placemark);    
	placemark.openBalloon(); 
	
	var map = new YMaps.Map(document.getElementById("YMapsID2"));
	map.setCenter(new YMaps.GeoPoint(30.33661, 60.06007), 15);

	var s = new YMaps.Style();
	s.balloonContentStyle = new YMaps.BalloonContentStyle
	(	new YMaps.Template("<div><a target='_blank' href='http://maps.yandex.ru/?ll=30.33461, 60.05907&z=15&l=map'><img src='$[description]'></a></div>")	);

	var placemark = new YMaps.Placemark(new YMaps.GeoPoint(30.33461, 60.05907), {style: s} );
	placemark.description = 'img/logo.gif';
	map.addOverlay(placemark);    
	placemark.openBalloon(); 	}

show_top = function()
{	this.pause = null;
	this.showbox = null;
	this.inner = null;
	this.width = 600; this.height = 700;
	this.zoom = 0; this.alpha = 0;
	this.root = null;
	this.step=20;
	this.img = new Image();		
		
	this.init = function()
	{	this.pause = document.getElementById("pause");		
		setOpacity(this.pause,0.4);
		this.showbox = document.getElementById("showbox");
		this.inner = this.showbox.getElementsByTagName("div")[0];
		addEventListener(this,this.img,"load");	}
		
	this.show = function(root,show)
	{	if(show)
		{	this.root = root; 			
			this.img.src = getAttribute(this.root,"path");
			this.showbox.style.width = 200;
			this.showbox.style.height = 100;
			this.inner.innerHTML = '<img style="margin:30px" src="img/loading.gif">';
			this.showbox.style.display = this.pause.style.display = (isGecko?"table":"block");	}
		else 
		{	this.inner.innerHTML = "";
			this.showbox.style.display = this.pause.style.display = (isGecko?"none":"none");	}	}
				
	this.resize	= function()
	{	if(this.pause)this.pause.style.height = (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight-(isGecko?0:4);
		toCenter(this.showbox);	}	
	
	this.handleEvent = function(event)
	{	var target = (isGecko) ? event.target:event.srcElement;
		if(event.type == "load")
		{	this.showbox.style.width = this.img.width;
			this.showbox.style.height = this.img.height;		
			this.inner.innerHTML = '<img src="'+this.img.src+'">';			
			this.showbox.style.display = (isGecko?"table":"block");
			toCenter(this.showbox);	}	}	}
			
gallery = function(show)
{	var g = document.getElementById("gallery");
	if(!g)return;
	setOpacity(g,0.5);
	var out = document.getElementsByTagName("td")[0];
	
	var html = '<object id="galleryin" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="900" height="800" id="gallery" align="middle">';
	html+='<param name="allowScriptAccess" value="sameDomain" />';
	html+='<param name="allowFullScreen" value="false" />';
	html+='<param name="movie" value="gallery.swf" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="scale" value="noscale" /><param name="bgcolor" value="#372a17" />	<embed src="gallery.swf" menu="false" quality="best" scale="noscale" bgcolor="#372a17" width="900" height="800" name="gallery" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	html+='</object>';
	
	out.innerHTML = html;
	
	if(show)g.style.display = (isGecko?"table":"block");
	else g.style.display = "none";
}

timer = function()
{	pause.resize();	}

tonumber = function(str)
{	var regexp = new RegExp("[^0123456789]","ig");
    return(Number(str.replace(regexp,"")));	}

load = function()				
{	pause.init();
	if(document.getElementById("YMapsID1"))maps();
	setInterval(timer,10);	}
	
pause = new show_top();


		



