var links,bloks;
var $=_;
function mappa(pic)
{
    _('mapRussiaAndWorld').src=pic;
}
function cacheImage(s)
{
var i = new Image();
i.src = s;
}

function srchMorph(el,w){
new Effect.Morph(el, {
  style: 'width:'+w+'px', // CSS Properties
  duration: 0.2 // Core Effect properties
});
}

function galeryChangePhoto(s,e)
{

//bigPhotoSource"bigPhotoDesc

if(_("bigPhoto").src == s || _("bigPhoto").src.indexOf(s)!=-1){ return;}
try{
_("bigPhotoSource").update(e.previous().select('span')[0].innerHTML);
_("bigPhotoDesc").update(e.previous().select('span')[1].innerHTML);
}catch(x){}
_("bigPhoto").fade({afterFinish:function(){
var bl=new Image();
bl.src=s+"?noc="+new Date().getTime();
bl.onload=function(){
_("bigPhoto").width=bl.width;
_("bigPhoto").src = s;_("bigPhoto").onload=function(){  _("bigPhoto").appear(); }
}
}});
_("bigPhoto").parentNode.style.background="url(/d/img/loading.gif) center no-repeat";




}
/*
var eldTimer;
	function topEld(){
	   var pagescroll={top:((document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop),left:((document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft)};
	   var ddim = document.viewport.getDimensions();
	if(Prototype.Browser.IE)
	{
	       new Effect.Tween(null, Number(_('eld').style.top.replace('px','')), pagescroll.top+ddim.height-_('eld').getHeight(),{duration:0.3}, function(p){
	                   _('eld').style.top = p+"px";
	      	        });
	   }else
	   {
	      	        var bak=_('eld').getHeight();
	      	        _('eld').style.position='fixed';
	      	        _('eld').style.left=null;
	      	        _('eld').style.top=ddim.height-_('eld').getHeight()+'px';
	      	        _('eld').style.right="0px";
	      	        _('eld').style.height=bak+"px";
	      	        
	   }
	}	
		
	window.onscroll=function(){
	window.clearTimeout(eldTimer);
	eldTimer=(function(){
	 
	   var pagescroll={top:((document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop),left:((document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft)};
	   var ddim = document.viewport.getDimensions();
	   if(pagescroll.top>ddim.height){
            
	   }else{
	   
	   }
	   }).delay(0.1);
	};
	
	*/

function fixFlash(){
    var embd = document.body.select('embed');
    //alert(embd.length);
    embd.each(function(o){
    if(o.readAttribute('mode')=="opaque"){return;}
    o.writeAttribute({wmode:"opaque"});
    o.hide();
    o.show();
    });var embd = document.body.select('object');
    //alert(embd.length);
    embd.each(function(o){
    if(o.readAttribute('mode')=="opaque"){return;}
    o.writeAttribute({wmode:"opaque"});
    o.hide();
    o.show();
    });
}
var hddl;
var srchHide=function(){
window.clearTimeout(hddl);
hddl=(function(){srchLiCnt=0;
selectedLiSrch=false;
_('searchresults').hide();//new Effect.BlindUp(_('searchresults'),{duration:0.3}); 
}).delay(0.2);
}
var showSearchResults;
function srchPozSinc(){
_('searchresults').toFront().clonePosition(_("searchInput"),{
                                    setWidth:false,
                                    setHeight:false,
                                    setTop:false,
                                    offsetLeft:_("searchInput").getWidth()+_("searchSubm").getWidth()-_('searchresults').getWidth()
                            });
                            
    if(_('tagsNavigation').style.position=="fixed"){
    _('searchresults').style.position="fixed"; 
    _('searchresults').style.top="30px"
    }else{
    _('searchresults').style.position="absolute";
    _('searchresults').toFront().clonePosition(_("searchInput"),{
                                    setWidth:false,
                                    setHeight:false,
                                    offsetLeft:_("searchInput").getWidth()+_("searchSubm").getWidth()-_('searchresults').getWidth(),
                                    offsetTop:_("searchInput").getHeight()+7
                            });
    }                            
}
var srchAjax=function(){
var i=_("searchInput")
                new Ajax.Request('/search/autocompleter/', {///d/new-expert.ru/js/test/ajax.html
                    parameters: { search_text: i.value },
                    method: 'get',
                    onSuccess: function(transport) {
                        if (transport.responseText.length>1)
                        {
                            
                            _('searchresults').update(transport.responseText);
                            srchPozSinc();
                            
                            _('searchresults').show();
                            //new Effect.BlindDown(_('searchresults'),{duration:0.4});
                            _("searchSubm").enable();
                        }else
                        {
                        srchHide();
                        _("searchSubm").disable();
                        }
                        //i.style.background="";
                    }
                    });
}
var srchLiCnt=-1;
var selectedLiSrch=false;
var srchFunc=function(e){
//document.title=e.keyCode; //38 верх 40 вниз
srchPozSinc()
if(e.keyCode==Event.KEY_ESC){
                                srchHide();
                                
                            }
if(e.keyCode==13 && selectedLiSrch){
Event.stop(e);
Proto.go(_('searchresults').select('li')[srchLiCnt].select("a")[0].href);
}                            
    var i=_("searchInput");
  if(e.keyCode !=38 && e.keyCode!=40){
    
    if(i.value.length>2)
    {   
        
       window.clearTimeout(showSearchResults)
       showSearchResults=srchAjax.delay(0.01);

    }
    else
    {
        _('searchresults').hide();
    }
  }
  else
  {
    var list=_('searchresults').select('li');
    $$('.hlsrch').each(function(o){o.removeClassName("hlsrch");});


     if(e.keyCode==38)
     {
        srchLiCnt--;
        if(srchLiCnt<0){srchLiCnt=list.length-1;}      
     }
     else
     {
        srchLiCnt++;
        if(srchLiCnt>=list.length){srchLiCnt=0;}     
     }



     for (var i = 0, length = list.length; i < length; i++) 
     {
        
        if(i==srchLiCnt)
        {
            list[i].addClassName("hlsrch"); 
            selectedLiSrch=true;       
        }
     }

  }

  };
document.observe("dom:loaded", function(){
 /*
 document.observe(((Prototype.Browser.WebKit)?'keydown':'keypress'),function(e){
                            if(e.keyCode==Event.KEY_ESC){
                                //srchHide();
                                alert(11);
                            }
                        });
почему не работает?
                        */
  //searchresults searchInput
//  document.body.observe("click",srchHide);
  _("searchInput").observe("keyup",srchFunc);
_("searchInput").observe("focus",srchFunc);
_("searchInput").observe("blur",srchHide);



$$('.karmalink').each(function(a){
new E.Karma({element:a});
});

$$('.article-karma').each(function(a){
    new E.Karma2({element:a});
});

new Proto.UI.stuck({ element: _('tagsNavigation'),
        	                   onStuck:srchPozSinc,
        	                   onUnStuck:function(){srchPozSinc.delay(0.1) }});
//fixFlash.delay(1); вернуть когда баннерами будет заниматься вменяемый человек
$$('.earButton').each(function(b){
           new E.Ear({
                    button:b,
        	        element:Element.select(b.parentNode,'.earElement')[0]
        	       });
});
try{

}catch(x){}


if(readCookie('elda')!=1 && !top.eldaDisabled){
new E.Elda({element:_('eld'),closeButton:'clzEld'});
createCookie('elda',1,1);
}

//$$(".partners-banners").each(function(e){ e.style.backgroundColor="#fff";new Proto.UI.stuck({element:e, offset:30, place:_('eld')}); });

/*
var ddim = document.viewport.getDimensions();
            var vpOff = document.viewport.getScrollOffsets();
            var elDim = this.container.getDimensions();
            var pd=_(this.options.parent).getDimensions();
            var pagescroll={top:((document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop),left:((document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft)};
            
*/
	
	
	
	
$$(".slider_wrapper").each(function(w){
try{
    var e = w.select('.slide-list')[0];
	    new Proto.UI.InfinityCarousel({
	                buttonLeftClassName:'sl-rarr',
	                buttonRightClassName:'sl-larr',
                	scollerClassName:'slide-block',
	                container:w,
	                element:e     
	    });
	    }catch(x){ }
    });


 });
