
	var topMargin = 0;
	var floatPos = 0;
	var slideTime = 800;
	var brsw = BrowserDetect.browser;
	var ns6 = (!document.all && document.getElementById);
	var ie4 = (document.all);
	var ns4 = (document.layers);
	var canvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
	var oldscroll = 0;
	
	
var secs=0;
var timerID = null;
var timerRunning = true;
var delay = 1000;
var event_index = 0;
var start = true;


function InitializeTimer()
{
	
	if (start)
	{
		
	//document.getElementById('calendar-events').innerHTML = "<select id=\"event-type\" onchange=\"event_num = 0; StopTheClock(); event_index=this.selectedIndex; xajax_next_event(event_num, 1, event_index);  return false;\"	name=\"event_type\"><option value=\"0\">события</option><option value=\"1\">новости</option></select>" + document.getElementById('calendar-events').innerHTML;
	start = false;
	}
  if (brsw == 'Explorer')
  {
	  ;//document.getElementById('calendar-year').className = 'calendar-year-ie';
	  
  }
  secs = 0; // Set the initial delay
  StartTheTimer();
}

function StopTheClock()
{
  if (timerRunning)
  {
    clearTimeout(timerID);
    timerRunning = false;
  }
}

function StartTheTimer()
{
  if (secs==0)
  {
  	
    secs = 10; //-OR- timerRunning=false;
    //alert(document.getElementByName('event_type'));
    xajax_next_event(event_num,0,event_index);
  }
  //self.status = secs;
  secs = secs - 1;
  if (timerRunning)
  {
    timerID = self.setTimeout("StartTheTimer()", delay);
  }
}	

	
	function layerObject(id,left) {
		if (ns6) {
			
			this.obj = document.getElementById(id).style;
			this.obj.left = left;
			return this.obj;
			
		}
		else if(ie4) {
			this.obj = document.all[id].style;
			this.obj.left = left;
			return this.obj;
		}
		else if(ns4) {
			
			this.obj = document.layers[id];
			this.obj.left = left;
			return this.obj;
		}
	}
	function layerSetup() {
		
		if (brsw == 'Explorer')
		{
			pageWidth =canvas.clientWidth;
		pageHeight = canvas.clientHeight;
			topMargin = pageHeight - 110;
			floatPos = 562;
		}		
		else if (brsw == 'Opera')
		{
			pageWidth = innerWidth;
			pageHeight = innerHeight;

			topMargin = pageHeight - 110;
			floatPos = 550;			
		}
		else
		{
			pageWidth = innerWidth;
			pageHeight = innerHeight;
			
			topMargin = pageHeight - 110;
			floatPos = '550';
		}					
	}

	function floatObject(resiz) {
		if ( brsw == 'Explorer' ) {
			document.all.floatLayer.style.pixelTop = 562;
			document.all.floatLayer.style.visibility = '';
			document.all.floatLayer.style.display = '';
		}
		else if (  brsw == 'Opera'  ) {
			document.all.floatLayer.style.pixelTop = 550;
			document.all.floatLayer.style.visibility = '';
			document.all.floatLayer.style.display = '';
		}
		else if ( ns4 ) {
			document.layers["floatLayer"].top = 550;
			document.layers["floatLayer"].visibility = '';
		}
		else if ( ns6 ) {
			document.getElementById('floatLayer').style.top = '550px';
			document.getElementById('floatLayer').style.visibility = '';
		}
	} 
function main() {
	layerSetup();
	if (ns4) {
		this.currentY = document.layers["floatLayer"].top;
		this.scrollTop = window.pageYOffset;
		mainTrigger();
	}
	else if(ns6) {		
		this.currentY = parseInt(document.getElementById('floatLayer').style.top);
		this.scrollTop = scrollY;
		mainTrigger();
	} else if(ie4) {		
		this.currentY = floatLayer.style.pixelTop;
		this.scrollTop = canvas.scrollTop;
		mainTrigger();
   	}
}
function mainTrigger() {
	if (this.scrollTop != 0)
		var newTargetY = this.scrollTop + this.topMargin;
	else 
		var newTargetY = floatPos;
	if (newTargetY < 550) newTargetY = 550;
	if ( this.currentY != newTargetY) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			floatStart();
		}
		animator();
   }
}

function floatStart() {
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt) {
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}
	else {
		this.D = this.currentY;
	   }
}

function animator() {
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) 
	{
		if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
		if ( ns4 )document.layers["floatLayer"].top = newY;
		if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
	}
}
function startFloater(resiz) {
	floatLyr = new layerObject('floatLayer', 0);
	if(ns6||ns4 || brsw=='Opera') {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup();
		window.setInterval("main()", 10);
		floatObject(resiz);
	}
	else if(ie4) {
		pageWidth =canvas.clientWidth;
		pageHeight = canvas.clientHeight;
		layerSetup();
		window.setInterval("main()", 10);
		floatObject(resiz);
		
   }
}  

function setOpacity( value ) {

 document.getElementById('upwindow').style.opacity = value / 10;
 document.getElementById('upwindow').style.filter = 'alpha(opacity=' + value * 10 + ')';
 if (value > 6)
 {
 document.getElementById('shadow').style.opacity = value/5 / 10;	
 document.getElementById('shadow').style.filter = 'alpha(opacity=' + value/5 * 10 + ')';
 }
  
}

function fadeInMyPopup() {
 for( var i = 0 ; i <= 100 ; i+=10 )
   setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );  
}

function fadeOutMyPopup() {
 for( var i = 1 ; i <= 100 ; i++ ) {
   setTimeout( 'setOpacity(' + (10 - i / 10) +')' , 4 * i );
 }

 setTimeout('closeMyPopup()', 400 );
}

function closeMyPopup() {
 document.getElementById('upwindow').style.display = "none";
 document.getElementById('subwindow').style.display = "none";
 document.getElementById('shadow').style.opacity = 0;
 document.getElementById('shadow').style.filter = 'alpha(opacity=0)';
 
}

function fireMyPopup() {
 setOpacity( 0 );
 document.getElementById('upwindow').style.display = "block";
 document.getElementById('shadow').style.display = "block";
 fadeInMyPopup();
}

	function share_article() {
		var back = document.getElementById('subwindow');
		var layer = document.getElementById('upwindow');
		var shadow = document.getElementById('shadow');
		
		wnd_name = 'upwindow';	
		if (brsw == 'Firefox')
		{
			back.style.display='block';	
			back.style.height= parseInt(window.innerHeight+ window.pageYOffset) + 'px';			
			layer.style.top= parseInt(window.innerHeight/2 - 265/2 + window.pageYOffset) + 'px';
			layer.style.left= parseInt(window.innerWidth/2 - 350/2)  + 'px';

			shadow.style.top= parseInt(window.innerHeight/2 - 265/2  + 2 + window.pageYOffset) + 'px';
			shadow.style.left= parseInt(window.innerWidth/2 - 350/2 + 2) + 'px';						
		}
		else if (brsw != "Opera")
		{
			back.style.display='block';
			back.style.height= parseInt(canvas.clientHeight  + canvas.scrollTop);// + 'px';
			layer.style.top= parseInt(canvas.clientHeight/2 - 265/2 + canvas.scrollTop);// + 'px';
			layer.style.left= parseInt(document.body.clientWidth/2 - 350/2);// + 'px';

			shadow.style.top= parseInt(canvas.clientHeight/2 - 265/2 + canvas.scrollTop+2);// + 'px';
			shadow.style.left= parseInt(canvas.clientWidth/2 - 350/2 + 2);// + 'px';
		}
		else
		{
			layer.style.top= parseInt(canvas.clientHeight/2 - 265/2 + canvas.scrollTop/2);// + 'px';		
			layer.style.left= parseInt(document.body.clientWidth/2 - 350/2);// + 'px';		
			layer.style.border='1px solid #eee';

			shadow.style.top= parseInt(canvas.clientHeight/2 - 265/2 + 2 +canvas.scrollTop/2);// + 'px';		
			shadow.style.left= parseInt(canvas.clientWidth/2 - 350/2 + 2);// + 'px';		
		}
		
		fireMyPopup();					
	}
	
	function share_cancel() {
		wnd_name = 'upwindow';	
		if (brsw != "Opera")
		{		
		var layer = document.getElementById('upwindow');
		var shadow = document.getElementById('shadow');	
		shadow.style.display='none';
		fadeOutMyPopup();
		}
		else
		{
			document.getElementById('upwindow').style.display='none';
			document.getElementById('shadow').style.display='none';	
			
		}
	}
	
	
