$(function(){

	var $win = $(window);
	var $doc = $(document);


	// hands
	(function(){

		var $block = $('#middle');
		var $lhand = $block.find('.handL').css({ width: 343 });
		var $rhand = $block.find('.handR').css({ width: 429 });

		var lw = 343;
		var rw = 429;

		var $hands = $lhand.add( $rhand );

		//var $wrap = $block.children('.generalWrap');
		//$wrap.append( $hands );

		var stt = false;
		var to;


		// $win.scroll(function(){ var top = $doc.scrollTop(); });

		function refresh(){
			// return;	    
			var d = $doc.width() - 1250;
			var b = d /2 /100 *105;
			var d1 = $doc.width() - 1580;
			 
			 if($doc.width()>1800)
			 {
			    b = d /2 /100 * 90;
  			 }

			var newStt = (d1>0);
			var x;

			if( stt != newStt ){
				stt = newStt;
				if( stt ){
					$hands.show();
					//$lhand.stop().animate({ left: '-1%' }, 555 );
					//$rhand.stop().animate({  right : '-1%' }, 555 );
				} else {
					$hands.hide();
					//$lhand.stop().animate({ left : -400 }, 555 );
					//$rhand.stop().animate({ right : -400 }, 555 );
				}
			}


			if( stt ){
				$lhand.css({ left: '-' + Math.min(lw-b, lw) + 'px' });
				$rhand.css({ right: '-' + Math.min(rw-b, rw) + 'px' });
			}

		};

		$win.resize( refresh /*function(){ clearTimeout(to); to=setTimeout( refresh, 222 );  }*/ );

		refresh();

	})();


   (function(){

     var $prayCommentsDoor = $('.prayCommentsDoor');
	 var $prayComments = $('.prayComments');

		$prayCommentsDoor.click(function(){
		
			var $this = $(this);
			if($this.hasClass('act')){
				$this.removeClass('act');				
				$prayComments.hide();
			}else{
				$this.addClass('act');
				$prayComments.show();
			}

		});



   })();

    (function(){
    
     var $prayCommentsDoor1 = $('.popupPayment_click');
	 var $prayComments1 = $('.popupPayment1');

		$prayCommentsDoor1.click(function(){
		
			var $this = $(this);
			if($this.hasClass('act')){
				$this.removeClass('act');				
				$prayComments1.hide();
			}else{
				$this.addClass('act');
				$prayComments1.show();
			}

		});



   })();






//alert('33');



   (function(){

     var $cell1 = $('.cell1');
     var $cell2 = $('.cell2');     
     var $cell3 = $('.cell3');     
     var $cell4 = $('.cell4');     
     
     var $cellblock1 = $('.cellblock1');
     var $cellblock2 = $('.cellblock2');     
     var $cellblock3 = $('.cellblock3');     
     var $cellblock4 = $('.cellblock4');     

     var $celltd1 = $('.celltd1');
     var $celltd2 = $('.celltd2');     
     var $celltd3 = $('.celltd3');     
     var $celltd4 = $('.celltd4');     

     
     
     
//	 var $prayComments = $('.prayComments');

		$cell1.click(function(){
		
		    var $this = $(this);		    

		    $celltd1.addClass('act');
		    $celltd2.removeClass('act');		    
		    $celltd3.removeClass('act');		    
		    $celltd4.removeClass('act');		    
		    
		    $cellblock2.hide();
		    $cellblock3.hide();
		    $cellblock4.hide();
		    $cellblock1.show();

		});


		$cell2.click(function(){
		
		    var $this = $(this);		    

		    $celltd2.addClass('act');
		    $celltd1.removeClass('act');		    
		    $celltd3.removeClass('act');		    
		    $celltd4.removeClass('act');		    
		    
		    $cellblock1.hide();
		    $cellblock3.hide();
		    $cellblock4.hide();
		    $cellblock2.show();

		});


		$cell3.click(function(){
		
		    var $this = $(this);		    

		    $celltd3.addClass('act');
		    $celltd2.removeClass('act');		    
		    $celltd1.removeClass('act');		    
		    $celltd4.removeClass('act');		    
		    
		    $cellblock2.hide();
		    $cellblock1.hide();
		    $cellblock4.hide();
		    $cellblock3.show();

		});


		$cell4.click(function(){
		
		    var $this = $(this);		    

		    $celltd4.addClass('act');
		    $celltd2.removeClass('act');		    
		    $celltd3.removeClass('act');		    
		    $celltd1.removeClass('act');		    
		    
		    $cellblock2.hide();
		    $cellblock3.hide();
		    $cellblock1.hide();
		    $cellblock4.show();

		});




   })();




   (function(){

     var $switcher = $('.enter');
	 var $block = $('.Field');

	
		$switcher.click(function(){
		
			var $this = $(this);

			if(document.getElementById("search_simple").value=="0"){
				
				$block.hide();
				document.getElementById("enter").innerHTML="Расширенный поиск";				
				document.getElementById("search_simple").value="1";

			}else{
				$block.show();
				document.getElementById("search_simple").value="0";								
				document.getElementById("enter").innerHTML="Простой поиск";								

			}

		});
	
	


   })();
   


   
   (function(){

     var $switcher = $('.more');
	 var $block = $('.brief');
	 var $block_full = $('.full');	 

	
		$switcher.click(function(){
		
			var $this = $(this);
//			alert('fff');
			
			if($this.hasClass('act')){
				$this.removeClass('act');			
				$block.show();
				$block_full.hide();				
				document.getElementById("more").innerHTML="<span>Читать полностью</span>";					

			}else{
				$this.addClass('act');
				$block.hide();
				$block_full.show();								
				document.getElementById("more").innerHTML="<span>Скрыть</span>";

			}

			


		});
	
	


   })();


   (function(){
	    var $switcher = $('.close1');
	    var $block = $('.message');
	    
	    
	    $switcher.click(function(){
		var $this = $(this);
		
		$block.hide();
	    });
	


   })();



//	alert('fff1');


});

//alert('fff1');

   function clearfield(name)
   {
    document.getElementById(name).innerHTML="";
   }

////////////////////////////////////////////////////////////////////////////////

var n_anonces=2;
var idx=0;
var duration_arr= new Array();

function start_rotate(change)
{
 var i;
 var duration;
 
//alert('ll');

  if(document.getElementById('lectBlock_'+idx))  
  {
  
    
    duration=duration_arr[idx];
//     alert('hh'+idx);
    if(change)
    {
    
     for(i=0;i<n_anonces;i++)
     {
       if(document.getElementById('lectBlock_'+i))
       {
         document.getElementById('lectBlock_'+i).style.display="none";
       }
     }
    
    
     document.getElementById('lectBlock_'+idx).style.display="";
     
     
     duration=duration_arr[idx];
    
    }
     idx++;
 
     if(idx>=n_anonces)
     idx=0;
    



    if(duration_arr[idx]<2)    
     duration_arr[idx]=5;


//    alert(duration_arr[idx]);
    setTimeout('start_rotate(true)', 1000*duration);
        
  
  
//   setTimeout('start_rotate()', 2000);

}

  }
////////////////////////////////////////////////////////////////////////////////

 function ChangeBannerColo1r(frame,color)
 {
  alert('fff');
 }

 function ChangeBannerColor(frame,color)
 {
  var colors= new Array();
  var i;
  var doc=window.frames[frame].document;  
  colors[0]="green";
  colors[1]="red";  
  colors[2]="yell";    
  colors[3]="blue";  
  colors[4]="white";      
  


  
  if(!doc.getElementById(color))
  return;
  
  

  
  for(i=0;i<5;i++)
  {
    if(doc.getElementById(colors[i]))
    {
    //    alert('fff1');
	if(color==colors[i])
	{

	    document.getElementById(frame+'_'+colors[i]).innerHTML='<div class="'+colors[i]+'" onclick="ChangeBannerColor(\''+frame+'\',\''+colors[i]+'\');">&nbsp;</div><span>&nbsp;</span>';
	    doc.getElementById(colors[i]).style.display='';	    
	}
	else
	{
	    document.getElementById(frame+'_'+colors[i]).innerHTML='<div class="'+colors[i]+'" onclick="ChangeBannerColor(\''+frame+'\',\''+colors[i]+'\');">&nbsp;</div>';	    
	    doc.getElementById(colors[i]).style.display='none';	    
	}
    }
  }
  
  
  document.getElementById('form_'+frame).value=color;
  openCode(frame,1);
  
 }
 
 var types_opened=new Array();
 types_opened['468x60']=0;
 types_opened['200x300']=0;
 types_opened['120x240']=0; 
 types_opened['240x100']=0; 
 
 
 
///////////////////////////////////////////////////////////////////////
 function openCode(type,update)
 {
  var colors= new Array();
  var i;  
  var id; 
  var color;
  
  

  colors[0]="green";
  colors[1]="red";  
  colors[2]="yell";    
  colors[3]="blue";  
  colors[4]="white";      
  

  
  if(!document.getElementById('form_'+type))
  return;
  

  
  color=document.getElementById('form_'+type).value;
    


  
  for(i=0;i<5;i++)
  {
    if(document.getElementById('code_'+type+'_'+color))
    {

	if((!update && types_opened[type]==0 && color==colors[i])||(update && types_opened[type]==1 && color==colors[i]))
	{
//  alert(color+types_opened[type]);      	
//	        alert(color+'_'+colors[i]);	
	    document.getElementById('code_'+type+'_'+colors[i]).style.display='block';	    
	    SelectCopy("ftext_"+type+'_'+i);
	}
	else
	{
	    document.getElementById('code_'+type+'_'+colors[i]).style.display='none';	    
	}
    }
  }

 if(update)
 {
  return;
 }

  if(types_opened[type]==0)
  {
      types_opened[type]=1;
  }
  else
  {
      types_opened[type]=0;  
  }
  
  
 } 
/////////////////////////////////////////////////////////////
function OpenBannerSimple(type)
{
 if(!types_opened[type] || types_opened[type]==2)
 {
  document.getElementById(type).style.display='block';
  types_opened[type]=1;
  SelectCopy('ftext_'+type);
 }
 else
 {
  document.getElementById(type).style.display='none';
  types_opened[type]=2;
 }
}
/////////////////////////////////////////////////////////////
function SelectCopy(id)
{
 if(!document.getElementById(id))
 return;
 
 document.getElementById(id).focus();
 document.getElementById(id).select();
// window.clipboardData.setData('Text',document.getElementById(id).value);
 
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
change_payments_status=1;
function change_payments(all)
{  

  if(all)
  {
   document.getElementById('payments_abroad').style.display='none';
   document.getElementById('payments_all').style.display='block';   
   document.getElementById('payments_russia').style.display='none';   
   document.getElementById('change_payments_href').innerHTML='Для пожертвований из России';
   change_payments_status=2;
   return false;
  }

  

  if(change_payments_status==1)
  {
   document.getElementById('payments_abroad').style.display='block';
   document.getElementById('payments_all').style.display='none';   
   document.getElementById('payments_russia').style.display='none';   
   document.getElementById('change_payments_href').innerHTML='Для пожертвований из России';
   change_payments_status=2;
   return false;
  }

  if(change_payments_status==2)
  {
   document.getElementById('payments_abroad').style.display='none';
   document.getElementById('payments_all').style.display='none';   
   document.getElementById('payments_russia').style.display='block';   
   document.getElementById('change_payments_href').innerHTML='Для пожертвований не из России';   
   change_payments_status=1;
   return false;
  }  
  
}
/////////////////////////////////////////////////////////////
//change_payments_status=1;
function child_popup(type,sub_type)
{
 if(document.getElementById('click_payment_type'))
 {
  document.getElementById('click_payment_type').value=type;
 }
 if(document.getElementById('click_payment_sub_type'))
 {
  document.getElementById('click_payment_sub_type').value=sub_type;
 } 
 

  document.getElementById('child_popup').style.display='block';
  document.getElementById('child_popup_light').style.display='block';
}
function child_popup_close()
{
  document.getElementById('child_popup').style.display='none';
  document.getElementById('child_popup_light').style.display='none';
}
/////////////////////////////////////////////////////////////////////////
function ImgShw(ID, width, height, alt)
{
	var scroll = "yes";
	var top=0, left=0;
	if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
	if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
	width = Math.min(width, screen.width-10);
	height = Math.min(height, screen.height-28);
	var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
	wnd.document.write(
		"<html><head>"+
		"<"+"script type=\"text/javascript\">"+
		"function KeyPress()"+
		"{"+
		"	if(window.event.keyCode == 27) "+
		"		window.close();"+
		"}"+
		"</"+"script>"+
		"<title></title></head>"+
		"<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">"+
		"<img src=\""+ID+"\" border=\"0\" alt=\""+alt+"\" />"+
		"</body></html>"
	);
	wnd.document.close();
}
/////////////////////////////////////////////////////////////////////////
last_shown_payment_id="";
function payment_img_show(id)
{

     if(last_shown_payment_id && document.getElementById(last_shown_payment_id))
     {
          document.getElementById(last_shown_payment_id).style.display='none';     
     }

   if(document.getElementById(id))
   {

     document.getElementById(id).style.display='';     
     last_shown_payment_id=id;
   }
      
}
/////////////////////////////////////////////////////////////////////////
