
var uniquepageid=window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, "") //get current page path and name, used to uniquely identify this page for persistence feature

var r_inc = 0;
var r_ind = 0; 
var r_increment = 20;
var r_l = 0;
var r_CurDiv = 1;

 function Run(divId)
 {
  var obj = document.getElementById(divId);
  r_l = parseInt(obj.style.left);
  
  r_l = r_l+r_increment; 
  obj.style.left = r_l+'px';
  r_inc = r_inc +1;
  if (r_inc<22) 
    {
	 r_ind = setTimeout(function(){Run(divId)}, 8);
	}
	 else
	 if (r_inc <= 25)
	 {
	  r_ind = setTimeout(function(){Run(divId)}, 15);
	  r_increment = 15;
	 }
 }
 
 function ToggleRight(divId)
 {
  r_inc = 0;
  r_l = 0;
  r_increment = 20;
  Run(divId);
 }
    

function CollapseDiv(divId)
{
	if (document.getElementById(divId) != null) 
	{
		//document.getElementById(divId).style.left = '485px';
		//document.getElementById(divId).style.width = '100px'; 
		document.getElementById(divId).style.visibility = 'hidden';
		document.getElementById(divId).style.zIndex = '0';
		
		//document.write
	//alert('collapse div');
	}
}

function CollapseAllDivs(id)
{

    if (id==r_CurDiv) {return;}

   	for (var i=1; i<=5; i++)
	 {
	 	if ( (i != id) && (i != r_CurDiv) ) {
			CollapseDiv('div'+i); 
			//document.getElementById(divId).style.zIndex = '0';
		}
	 }
	 
	/* if (document.getElementById('div' + id) != null) {
	 	//document.getElementById('div' + id).style.width = '0px';
		//document.getElementById('div' + id).style.visibility = 'hidden';
		document.getElementById('div' + id).style.left = '-490px';
		document.getElementById('div' + id).style.zIndex = '10';	
	 }*/
	 
	
	 
	 
	 document.getElementById('div' + id).style.visibility = 'visible';
	 //document.getElementById('div' + r_CurDiv).style.zIndex = '0';
	 
	 //var obj = document.getElementById('div' + id);
     //obj.style.filter='alpha(opacity=0)';
	 //obj.style.opacity = 0.0;
	 
	 document.getElementById('div' + r_CurDiv).style.zIndex = '0';
	 document.getElementById('div' + id).style.zIndex = '5';
	 
	 var IE = document.all;
	 if (!IE)
	  {
	   document.getElementById('div' + id).style.opacity = 0;
	   clearTimeout(sT); 
	   clearTimeout(hT);
	   SmoothShow('div'+id, 100, 10);
	  }
       else	  
	  {
	   var obj = document.getElementById('div' + id);
       obj.style.filter='alpha(opacity=100)';
	   clearTimeout(sT); 
	   clearTimeout(hT);
	   SmoothShow('div'+id, 100, 10);
	  }  	  
	  
	 r_CurDiv = id;
	 	 
	 /* //document.getElementById('div' + id).style.opacity = 0;  
	 
	 //SmoothHide('div'+r_CurDiv, 0, 0);
	 clearTimeout(sT); 
	 clearTimeout(hT);
	 SmoothShow('div'+id, 100, 10);
	 
	 //alert(r_CurDiv); */
	 	 
}

function HideDiv(divId)
{
 document.getElementById(divId).style.visibility = 'hidden'
}

function MakeDivVisible(divId)
 {
  /* if (visible==1)  
   {document.getElementById(divId).style.visibility = 'visible'}
    else
   {document.getElementById(divId).style.visibility = 'hidden'} */ 	
   
  if (document.getElementById(divId).style.visibility == 'visible')
    {
	 document.getElementById(divId).style.visibility = 'hidden'
    } 	
	 else
	{
	 document.getElementById(divId).style.visibility = 'visible';
	 //document.getElementById(divId).style.zIndex = '20';
    }	
 }

function animatedcollapse(divId, animatetime, persistexpand, initstate){
	this.divId=divId
	this.divObj=document.getElementById(divId)
	this.divObj.style.zIndex = "10"
	this.divObj.style.overflow="hidden"
	this.timelength=animatetime
	this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
	//this.isExpanded=animatedcollapse.getCookie(uniquepageid+"-"+divId) //"yes" or "no", based on cookie value
	this.isExpanded = "yes";
	this.contentheight=parseInt(this.divObj.style.height)
	var thisobj=this
	if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
		animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
		if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
			this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
	}
	else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
	if (persistexpand)
		animatedcollapse.dotask(window, function(){animatedcollapse.setCookie(uniquepageid+"-"+thisobj.divId, thisobj.isExpanded)}, "unload")
}

animatedcollapse.prototype._getheight=function(persistexpand){
	this.contentheight=this.divObj.offsetHeight
	if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //collapse content
		this.divObj.style.visibility="visible"
	}
	else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
		this.divObj.style.height=this.contentheight+"px"
}


animatedcollapse.prototype._slideengine=function(direction){
	var elapsed=new Date().getTime()-this.startTime //get time animation has run
	var thisobj=this
	if (elapsed<this.timelength){ //if time run is less than specified length
		var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
	this.divObj.style.height=distancepercent * this.contentheight +"px"
	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
	}
	else{ //if animation finished
		this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
		this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
		this.runtimer=null
	}
}


animatedcollapse.prototype.slidedown=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine("down")
		}
	}
}

animatedcollapse.prototype.slideup=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
			this.startTime=new Date().getTime()
			this._slideengine("up")
		}
	}
}

animatedcollapse.prototype.slideit=function(){
	if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
		alert("Please wait until document has fully loaded then click again")
	else if (parseInt(this.divObj.style.height)==0)
	  {
	  	this.divObj.style.zIndex = 50;
 		this.slidedown()
	  }
	else if (parseInt(this.divObj.style.height)==this.contentheight)
		this.slideup()
}

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------

animatedcollapse.curveincrement=function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}


animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

animatedcollapse.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

animatedcollapse.setCookie=function(name, value){
		document.cookie = name+"="+value
}


var hT, sT;

function SmoothShow(objId, x, delay)   
{ 
   var obj = document.getElementById(objId);
   op = (obj.style.opacity)?parseFloat(obj.style.opacity):parseInt(obj.style.filter)/100;
   //alert(op+' '+x);
   	     
   if(op < x)  
   { 
      clearTimeout(hT);
      op += 0.05; 
      obj.style.opacity = op; 
      obj.style.filter='alpha(opacity='+op*100+')'; 
      sT=setTimeout('SmoothShow(\''+objId+'\', '+x+')', delay); 
   } 
   
} 
	    
function SmoothHide(objId, x)   
{ 
   var obj = document.getElementById(objId);
   
   //op = (obj.style.opacity)?parseFloat(obj.style.opacity):parseInt(obj.style.filter)/100;
   obj.style.opacity = x;  
   obj.style.filter='alpha(opacity='+x*100+')';
   clearTimeout(sT);
	     
   /*
if(op > x)  
   { 
      clearTimeout(sT);
      op -= 0.05; 
      obj.style.opacity = op; 
      obj.style.filter='alpha(opacity='+op*100+')'; 
      hT=setTimeout('SmoothHide(\''+objId+'\', '+x+')',30); 
   } 
*/
}

function GetWindowWidth()
 {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return myWidth;
 }

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

function getScrollY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function myShowPic(path){
 var obj = document.getElementById('photoDiv');
 var myWidth = 0;
 var myMargin = 0.0;
 
 if (obj!=null)
  {
  	SmoothHide('photoIMG', 0.1); 
	document.body.removeChild(obj); 
	script = null;
    img = null;
    obj = null;
  }
 
  if (1==1)
  {
  	obj = document.createElement("div");
	p_child_center = document.createElement("p");
	p_child_right = document.createElement("p");
	link = document.createElement("a");
	text = document.createTextNode("Закрыть (X)");
	img = document.createElement("img");
	img_load = document.createElement("img");
	
	document.body.appendChild(obj);
	
	obj.id = "photoDiv";
	obj.style.backgroundColor = "#999999";
	obj.style.color = 'white';
	obj.style.zIndex = 100;
	obj.style.position = 'absolute';
	obj.style.top = getScrollY()+200+'px';
	obj.style.height = 60 + 'px';
	obj.style.width = 250 + 'px';
	//obj.style.opacity = 0.6; 
    //obj.style.filter='alpha(opacity=60)'; 
	
	    myWidth = GetWindowWidth();
		myMargin = parseInt(obj.style.width) / myWidth * 100;
		myMargin = Math.round((100 - myMargin) / 2);
		
		obj.style.marginLeft = myMargin + '%';
		obj.style.marginRight = myMargin + '%';
		
		
	
	obj.appendChild(p_child_right);
	p_child_right.align = 'right';
	obj.appendChild(p_child_center);
	p_child_center.align = 'center';
	p_child_center.appendChild(img_load);
	
	p_child_right.appendChild(link);
	p_child_right.style.marginTop = '0px';
	p_child_right.style.marginBottom = '0px';
	
	link.appendChild(text);
	link.href = 'javascript:void(0)';
	link.style.color = 'white';
	link.onclick = function() {document.body.removeChild(obj); script = null;  img = null; obj = null;}; 
	
	   		
	img_load.src = 'images/load.gif';
	
	
	img.src = path;
	img.defaultCharset = '';
	img.id = 'photoIMG';
	img.style.opacity = 0.1;
	img.style.filter = 'alpha(opacity=10)';
	img.title = 'Нажмите на изображение для закрытия.'; 
	
	//только после загрузки
	
	img.onload = function(){
	
	obj.style.top = getScrollY()+50+'px';
	
	p_child_center.removeChild(img_load);
	img_load = null;
	p_child_center.appendChild(img);
	
	
	script = document.createElement("script");
			
			
	//link.appendChild(text);
	//link.href = 'javascript:void(0)';
	//link.style.color = 'white';
	link.onclick = function() {SmoothHide('photoIMG', 0.1); document.body.removeChild(obj); script = null;  img = null; obj = null;}; 
	
	
				
	img.onclick = function() {SmoothHide('photoIMG', 0.1); document.body.removeChild(obj); script = null;  img = null; obj = null;};
	
			
		obj.style.height = img.height + 50 + 'px';
		obj.style.width = img.width + 50 + 'px';
		
		myWidth = GetWindowWidth();
		myMargin = parseInt(obj.style.width) / myWidth * 100;
		myMargin = Math.round((100 - myMargin) / 2);
		
		obj.style.marginLeft = myMargin + '%';
		obj.style.marginRight = myMargin + '%';
		
		obj.appendChild(script);
		script.type = 'text/javascript';
		script.text = 'SmoothShow("photoIMG", 1, 50);';
	} 
	
	
  	//document.write('<div style="position:absolute; margin-left:20%; margin-right:20%; background-color:#CCCCCC'); 
  }
  
 }

