//Скроллер плагин
var Scroller = new Class({

  Implements: [Events, Options],

  options: {
    area: 110,
    velocity: 1,
    onChange: function(x, y){
        
      this.element.scrollTo(x, y);
    },
    fps: 50,
    horizontal: false, //v3 modified
    vertical: true
  },

  initialize: function(element, options){
    this.setOptions(options);
     
    this.element = document.id(element);    
    this.listener = ($type(this.element) != 'element') ? document.id(this.element.getDocument().body) : this.element;
    this.timer = null;
    this.bound = {
      attach: this.attach.bind(this),
      detach: this.detach.bind(this),
      getCoords: this.getCoords.bind(this)
    };
  },

  start: function(){
   
    this.listener.addEvents({
      mouseenter: this.bound.attach, //v3 modified
      mouseleave: this.bound.detach
    });
  },

  stop: function(){
    this.listener.removeEvents({
      mouseenter: this.bound.attach,
      mouseleave: this.bound.detach
    });
    this.detach();
    this.timer = $clear(this.timer);
  },

  attach: function(){
    this.listener.addEvent('mousemove', this.bound.getCoords);
  },

  detach: function(e){
    var node = this;
    this.detachTimer = (function() {
      node.listener.removeEvent('mousemove', node.bound.getCoords);
      node.timer = $clear(node.timer);
    }).delay(50);
    
  },

  getCoords: function(event){  
    this.page = (this.listener.get('tag') == 'body') ? event.client : event.page;
    if (!this.timer) this.timer = this.scroll.periodical(Math.round(100 / this.options.fps), this);
        
  },

  scroll: function(){
    
    var size = this.element.getSize(),
      scroll = this.element.getScroll(),
      pos = this.element.getOffsets(),
      scrollSize = this.element.getScrollSize(),
      change = {x: 0, y: 0};
    
    // v3 modified
    if (!this.options.horizontal) delete this.page.x;
    if (!this.options.vertical) delete this.page.y;

    for (var z in this.page){  
    
      if (this.page[z] < (this.options.area + pos[z]) ) {      
        change[z] = (this.page[z] - this.options.area - pos[z]) * this.options.velocity;        
      }
      else if (this.page[z] + this.options.area > (size[z] + pos[z]) ) {      
        change[z] = (this.page[z] - size[z] + this.options.area - pos[z]) * this.options.velocity;
      }
    }
    
    
    
    //if ($chk($('slide'))) {
  
         var node =this;
        
          if (scroll.y==110)  {
              $$('.ar-bot').setStyle('visibility','hidden');
            
        }
        else {
             $$('.ar-bot').setStyle('visibility','visible');
              
        };
        if (scroll.y==0)  {
              $$('.ar-top').setStyle('visibility','hidden');
            
        } 
        else {
            $$('.ar-top').setStyle('visibility','visible');
              
        }
       
  //  }
    
    if (change.y || change.x) {       
      this.fireEvent('change', [scroll.x + change.x, scroll.y + change.y]);      
    } 
  }

});


///////////////////////////////////////////
//Плагин ротации объявлений и новостей
var Rotator = new Class({
      Implements: [Events, Options],
      options: {          
        cur: 0,          
        timeout: 3000
      },
    
     initialize: function(list, options,events){
            this.setOptions(options);
             this.list=list;
             this.length=list.length;  
             this.list[0].setStyle('opacity', 1);
          this.f.delay(this.options.timeout, this);  
          this.scroll = $$('.scroller ul');   
    },
    start: function() {
              this.active=true;

    },
    stop: function() {
              this.active=false;
    },
    setpos: function(pos) {
            this.options.cur = pos;
            this.slide();            
    },
   getpos: function(pos) {             
           return   this.options.cur;            
    },
    f: function() {
        if (this.active) {
            this.options.cur++;
            this.slide();  
        } 
         this.scroll.scrollTo(0,this.options.cur*40);          
        this.f.delay(this.options.timeout, this);
               
    },
     //События
  
    slide: function() {         
          for(i=0;i<this.length;i++) {
          //this.list[i].tween('opacity', 0);
         this.list[i].setStyle('opacity', 0);
          }                 
          if (this.options.cur >=this.length  ) this.options.cur = 0;
          if (this.options.cur < 0) this.options.cur = this.length-1;          
         // this.list[this.options.cur].tween('opacity', 1);
         //this.list[this.options.cur].fade('In');
         this.list[this.options.cur].setStyle('opacity', 1).set('tween', {duration: 150});
          this.public.slideAfter();         
    },
    
 public: { slideAfter: function() { 
    
    }   
  } 

})

function  getPageSize(){
       var xScroll, yScroll;

       if (window.innerHeight && window.scrollMaxY) {
               xScroll = document.body.scrollWidth;
               yScroll = window.innerHeight + window.scrollMaxY;
       } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
               xScroll = document.body.scrollWidth;
               yScroll = document.body.scrollHeight;
       } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
               xScroll = document.documentElement.scrollWidth;
               yScroll = document.documentElement.scrollHeight;
       } else { // Explorer Mac...would also work in Mozilla and Safari
               xScroll = document.body.offsetWidth;
               yScroll = document.body.offsetHeight;
       }

       var windowWidth, windowHeight;
       if (self.innerHeight) { // all except Explorer
               windowWidth = self.innerWidth;
               windowHeight = self.innerHeight;
       } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
               windowWidth = document.documentElement.clientWidth;
               windowHeight = document.documentElement.clientHeight;
       } else if (document.body) { // other Explorers
               windowWidth = document.body.clientWidth;
               windowHeight = document.body.clientHeight;
       }

       // for small pages with total height less then height of the viewport
       if(yScroll < windowHeight){
               pageHeight = windowHeight;
       } else {
               pageHeight = yScroll;
       }

       // for small pages with total width less then width of the viewport
       if(xScroll < windowWidth){
               pageWidth = windowWidth;
       } else {
               pageWidth = xScroll;
       }

       return [pageWidth,pageHeight,windowWidth,windowHeight];
}

window.addEvent('domready', function() {
  var box = new CeraBox({
		group: true,
		errorLoadingMessage: 'The requested content cannot be loaded. Please try again later.'
	}); 
  
	list = $$(document.links);
	list = list.filter(function(item){
		//if (item.hasClass('no')) return false;
		return item.href.test(/\.(jpe?g|png|gif|swf)$/)
	});
	if (list && list.length) {
		box.addItems(list, {
			animation: 'ease'
		});
	} 
  new SmoothScroll({
    onStart: function() {
      if (this.oldanchor) {
        this.oldanchor.removeClass('anchored');
      }
      this.oldanchor = $(this.anchor).addClass('anchored');
    }
  });


  

if ($chk($('teasers'))) {

  	var  teasers = $$('#teasers .item ').setStyle('opacity', 0).set('tween', {duration: 200});
  	if (teasers.length>0) {
  		teasers.Rotator = new Rotator(teasers, {timeout: 5000});
       	teasers.Rotator.public.slideAfter = function () {
	             var pos = teasers.Rotator.getpos();
	              	$$('.switch_link .items').getElement('img').set('src','/images/keyslideoff.png');
	           		$$('.switch_link .item'+pos).getElement('img').set('src','/images/keyactive.png');
	           		$$('.top_banner_img .images').morph({				
				      	'opacity': 0
		          });	
	           
	           if ($chk($$('.top_banner_img .image'+pos))) $$('.top_banner_img .image'+pos).morph({				
				      	'opacity': 1
		          });	
	    };
  		teasers.Rotator.start();		
  	} 
    $$('.top_banner').addEvent('mouseenter', function(e) {
       	    	
				 teasers.Rotator.stop();    

		}).addEvent('mouseleave', function(e) {
		       teasers.Rotator.start();	
    }); 
   					
}
 		//При наведении на плашку спец. меняем его положение
     	$$('.switch_link .items').addEvent('click', function(e) {
     
		   var pos = this.get('rel').toInt(); 
		     	e.preventDefault();
		    	teasers.Rotator.setpos(pos);
		   
         
        
		});
 
	if ($chk($('sidemenu'))) {
		$$('.sidemenu li').addEvent('mouseenter', function(e) {
        this.getElement('ul').setStyle('display','block').set('tween', {duration: 200});		
		}).addEvent('mouseleave', function(e) {
        this.getElement('ul').setStyle('display','none').set('tween', {duration: 200});		       	
    	}); 		           
    }

	/*if ($chk($$('sobit'))) {
		$$('.sobit li').addEvent('click', function(e) {
		var currentid = this.get('id');
		$$('.sobit li').removeClass('active');
		this.addClass('active');
        $$('.podsobit').setStyle('display','none').set('tween', {duration: 200});
		this.getParent().getParent().getElementById('podsobit'+currentid).setStyle('display','block').set('tween', {duration: 200});		
        $$('.catsobit').setStyle('display','none').set('tween', {duration: 200});
		this.getParent().getParent().getElementById('catsobit'+currentid).setStyle('display','block').set('tween', {duration: 200});		
		}); 		       

		$$('.podsobit li').addEvent('click', function(e) {
		var currentid = this.get('id');
		$$('.podsobit li').removeClass('active');
		this.addClass('active');		
        $$('.catsobit').setStyle('display','none').set('tween', {duration: 200});
		this.getParent().getParent().getElementById('catpodsobit'+currentid).setStyle('display','block').set('tween', {duration: 200});				
		});    
    
		if ($chk('wedzagran')) {
		    $$('#wedzagran').addEvent('click', function(e) {
		    
		    var maxyear = ($$('#wedzagrannews').get('rel')) + ($$('#maxyear').get('rel'));
		    
			$$('.shownews').setStyle('display','none').set('tween', {duration: 200});
			$$('#wedzagrannews').setStyle('display','block').set('tween', {duration: 200});
			$$('.yearspisok').setStyle('display', 'none').set('tween', {duration: 200});
	 		document.getElementById(maxyear).setStyle('display', 'block').set('tween', {duration: 200});
			$$('.sortbydate').setStyle('display', 'none').set('tween', {duration: 200});			
			document.getElementById('datey'+maxyear).setStyle('display', 'block').set('tween', {duration: 200});
	 		$$('.month li').removeClass('active');
	 		$$('.sortbymonth').setStyle('display', 'block').set('tween', {duration: 200});
			});
		};    

		if ($chk('simplewed')) {
		    $$('#simplewed').addEvent('click', function(e) {

		    var maxyear = ($$('#simplewednews').get('rel')) + ($$('#maxyear').get('rel'));
		    
			$$('.shownews').setStyle('display','none').set('tween', {duration: 200});
			$$('#simplewednews').setStyle('display','block').set('tween', {duration: 200});
			$$('.yearspisok').setStyle('display', 'none').set('tween', {duration: 200});
	 		document.getElementById(maxyear).setStyle('display', 'block').set('tween', {duration: 200});
			$$('.sortbydate').setStyle('display', 'none').set('tween', {duration: 200});			
			document.getElementById('datey'+maxyear).setStyle('display', 'block').set('tween', {duration: 200});
	 		$$('.month li').removeClass('active');
	 		$$('.sortbymonth').setStyle('display', 'block').set('tween', {duration: 200});						 			
			});
		};
		
		if ($chk('lastwed')) {
		    $$('#lastwed').addEvent('click', function(e) {

		    var maxyear = ($$('#lastwednews').get('rel')) + ($$('#maxyear').get('rel'));
		    
			$$('.shownews').setStyle('display','none').set('tween', {duration: 200});
			$$('#lastwednews').setStyle('display','block').set('tween', {duration: 200});
			$$('.yearspisok').setStyle('display', 'none').set('tween', {duration: 200});
	 		document.getElementById(maxyear).setStyle('display', 'block').set('tween', {duration: 200});
			$$('.sortbydate').setStyle('display', 'none').set('tween', {duration: 200});			
			document.getElementById('datey'+maxyear).setStyle('display', 'block').set('tween', {duration: 200});
	 		$$('.month li').removeClass('active');
	 		$$('.sortbymonth').setStyle('display', 'block').set('tween', {duration: 200});						 			
			});
		};
		
		if ($chk('allwed')) {
		    $$('#allwed').addEvent('click', function(e) {

		    var maxyear = ($$('#allwednews').get('rel')) + ($$('#maxyear').get('rel'));
		    
			$$('.shownews').setStyle('display','none').set('tween', {duration: 200});
			$$('#allwednews').setStyle('display','block').set('tween', {duration: 200});
			$$('.yearspisok').setStyle('display', 'none').set('tween', {duration: 200});
	 		document.getElementById(maxyear).setStyle('display', 'block').set('tween', {duration: 200});
			$$('.sortbydate').setStyle('display', 'none').set('tween', {duration: 200});			
			document.getElementById('datey'+maxyear).setStyle('display', 'block').set('tween', {duration: 200});
	 		$$('.month li').removeClass('active');
	 		$$('.sortbymonth').setStyle('display', 'block').set('tween', {duration: 200});						 			
			});
		};					
	}*/

	if ($chk($$('yearspisok'))) {

	 	/*$$('.year-next').addEvent('click', function(event) {
		 	event.preventDefault();
			var block = this.getParent().getParent().getParent().get('rel');			
			var maxyear = block + ($$('#maxyear').get('rel'));
			var minyear = block + ($$('#minyear').get('rel'));	 		
			var pos = this.getParent().getParent().get('id').toInt();
	 		var newpos = pos - 1;			
			if (newpos < minyear) newpos = pos;	 				
	 		$$('.sortbymonth').setStyle('display', 'block').set('tween', {duration: 200});
			$$('.yearspisok').setStyle('display', 'none').set('tween', {duration: 200});
	 		this.getParent().getParent().getParent().getElementById(newpos).setStyle('display', 'block').set('tween', {duration: 200});
			$$('.sortbydate').setStyle('display', 'none').set('tween', {duration: 200});			
			this.getParent().getParent().getParent().getElementById('datey'+newpos).setStyle('display', 'block').set('tween', {duration: 200});
			 	 			 		
	 	});
	 	
		$$('.year-prev').addEvent('click', function(event) {
	 		event.preventDefault();
			var block = this.getParent().getParent().getParent().get('rel');			
			var maxyear = block + ($$('#maxyear').get('rel'));
			var minyear = block + ($$('#minyear').get('rel'));
	 		var pos = this.getParent().getParent().get('id').toInt();
	 		var newpos = pos + 1;
			if (newpos > maxyear) newpos = pos;	 		
	 		$$('.sortbymonth').setStyle('display', 'block').set('tween', {duration: 200});
			$$('.yearspisok').setStyle('display', 'none').set('tween', {duration: 200});
	 		this.getParent().getParent().getParent().getElementById(newpos).setStyle('display', 'block').set('tween', {duration: 200});	 		
			$$('.sortbydate').setStyle('display', 'none').set('tween', {duration: 200});
			this.getParent().getParent().getParent().getElementById('datey'+newpos).setStyle('display', 'block').set('tween', {duration: 200}); 	 			 		
	 	});
	 	
	 	$$('.showinmonth').addEvent('click', function(event) {
	 	    event.preventDefault();
	 	    $$('.month li').removeClass('active');
	 	    this.addClass('active');
	 	    var themonth = this.get('rel');
	 	    var theyear = this.getParent().get('rel');
			$$('.sortbymonth').setStyle('display', 'none').set('tween', {duration: 200});
			this.getParent().getParent().getParent().getElementById('datey'+theyear+'m'+themonth).setStyle('display', 'block').set('tween', {duration: 200}); 	 			 			 	    
	 	}); */
	}

  impblocks = {
        list: $$('#impinfo > div').setStyle('display', 'none').set('tween', {duration: 200}),
        cur: 0,
//        timeout: 10000,
        f: function() {
        
        		if ($('lenta').hasClass('closed')){	
        		    
	                this.cur++;
	                this.slide();
	                this.selectframe();
	                this.movelenta();                  
                   
                }
//                 this.f.delay(this.timeout, this);
               
        },
        slide: function() {
			for(i=0;i<this.length;i++) {
			    this.list[i].tween('display', 'none');
			} 
			             
	         if (this.cur >=this.length  ) this.cur = 0;
	         if (this.cur < 0) this.cur = this.length-1;	        
	         this.list[this.cur].tween('display', 'block'); 		
		},
        movelenta: function() {
		             
					 var  middle = $('lenta').getStyle('height').toInt() /2;
		             
	                 var leftpos =  $('lenta').getStyle('margin-top').toInt();
		               	if (this.cur>=1)
		                	{
							leftpos= 8 - (this.cur)*72;
							}	                
					   	else leftpos=0;
					   
					   
					              
	                 $('lenta').morph({
	      					'margin-top': leftpos						
	      			 }); 
				
		},
		selectframe: function() {
		      $$('.item-scroll').each(function(item) {		         	  
				       item.removeClass('first');     
			   });    
              $$('#itemscroll'+this.cur).addClass('first'); 
		},
        prev: function() {        	
                 this.cur--;
	              this.slide();
                 this.selectframe(); 
				this.movelenta();               
        },
        next: function() {        	
                 this.cur++;
	             this.slide();
                this.selectframe();
				this.movelenta();               
        },
        movepos: function(pos) {        	
                
                this.cur=pos;
                this.slide();
               
                this.selectframe();
				//this.movelenta();               
        },     
  };

  impblocksk = {
        list: $$('#impinfok > div').setStyle('display', 'none').set('tween', {duration: 200}),
        cur: 0,
//        timeout: 10000,
        f: function() {
        
        		if ($('lentak').hasClass('closed')){	
        		    
	                this.cur++;
	                this.slide();
	                this.selectframe();
	                this.movelenta();                  
                   
                }
//                 this.f.delay(this.timeout, this);
               
        },
        slide: function() {
			for(i=0;i<this.length;i++) {
			    this.list[i].tween('display', 'none');
			} 
			             
	         if (this.cur >=this.length  ) this.cur = 0;
	         if (this.cur < 0) this.cur = this.length-1;	        
	         this.list[this.cur].tween('display', 'block'); 		
		},
        movelenta: function() {
		             
					 var  middle = $('lentak').getStyle('height').toInt() /2;
		             
	                 var leftpos =  $('lentak').getStyle('margin-top').toInt();
		               	if (this.cur>=1)
		                	{
							leftpos= 8 - (this.cur)*72;
							}	                
					   	else leftpos=0;
					   
					   
					              
	                 $('lentak').morph({
	      					'margin-top': leftpos						
	      			 }); 
				
		},
		selectframe: function() {
		      $$('.item-scrollk').each(function(item) {		         	  
				       item.removeClass('first');     
			   });    
              $$('#itemscrollk'+this.cur).addClass('first'); 
		},
        prev: function() {        	
                 this.cur--;
	              this.slide();
                 this.selectframe(); 
				this.movelenta();               
        },
        next: function() {        	
                 this.cur++;
	             this.slide();
                this.selectframe();
				this.movelenta();               
        },
        movepos: function(pos) {        	
                
                this.cur=pos;
                this.slide();
               
                this.selectframe();
				//this.movelenta();               
        },      
  };

  impblocksz = {
        list: $$('#impinfoz > div').setStyle('display', 'none').set('tween', {duration: 200}),
        cur: 0,
//        timeout: 10000,
        f: function() {
        
        		if ($('lentaz').hasClass('closed')){	
        		    
	                this.cur++;
	                this.slide();
	                this.selectframe();
	                this.movelenta();                  
                   
                }
//                 this.f.delay(this.timeout, this);
               
        },
        slide: function() {
			for(i=0;i<this.length;i++) {
			    this.list[i].tween('display', 'none');
			} 
			             
	         if (this.cur > this.length  ) this.cur = 0;
	         if (this.cur < 0) this.cur = this.length-1;	        
	         this.list[this.cur].tween('display', 'block'); 		
		},
        movelenta: function() {
		             
					 var  middle = $('lentaz').getStyle('height').toInt() /2;
		             
	                 var leftpos =  $('lentaz').getStyle('margin-top').toInt();
		               	if (this.cur>=1)
		                	{
							leftpos= 8 - (this.cur)*72;
							}	                
					   	else leftpos=0;
					   
					   
					              
	                $('lentaz').morph({
	      					'margin-top': leftpos						
	      			 }); 
				
		},
		selectframe: function() {
		      $$('.item-scrollz').each(function(item) {		         	  
				       item.removeClass('first');     
			   });    
              $$('#itemscrollz'+this.cur).addClass('first'); 
		},
        prev: function() {        	
                this.cur--;
	            this.slide();
                this.selectframe(); 
				this.movelenta();               
        },
        next: function() {        	
              this.cur++;
	            this.slide();
              this.selectframe();
				this.movelenta();               
        },
        movepos: function(pos) {        	
                
                this.cur=pos;
                this.slide();
               
                this.selectframe();
				//this.movelenta();               
        },     
  };

  
  impblocks.length = impblocks.list.length;
  if (impblocks.length>0)   {
	  impblocks.list[0].setStyle('display', 'block');
//	  impblocks.f.delay(impblocks.timeout, impblocks);
  }
    
  impblocksk.length = impblocksk.list.length;
  if (impblocksk.length>0)   {
	  impblocksk.list[0].setStyle('display', 'block');
//	  impblocksk.f.delay(impblocksk.timeout, impblocksk);
  }

  impblocksz.length = impblocksz.list.length;
  if (impblocksz.length>0)   {
	  impblocksz.list[0].setStyle('display', 'block');
//	  impblocks.f.delay(impblocks.timeout, impblocks);
  }
  
	// Z
	function Znext(){
		console.log("up");
		if (impblocksz.cur > 0) {
			impblocksz.prev();
			event.preventDefault();
			$$('#right-arrowz').setStyle('display', 'block');
			$$('#left-arrowz').setStyle('display', 'block');	
			if (impblocksz.cur == '0') { $$('#right-arrowz').setStyle('display', 'none');}	
		}
	}
	function Zprev(){
		console.log("down");
		if (impblocksz.cur < (impblocksz.length - 1)) {		
			impblocksz.next();
			event.preventDefault();
			$$('#left-arrowz').setStyle('display', 'block');
			$$('#right-arrowz').setStyle('display', 'block');
			if (impblocksz.cur == (impblocksz.length - 1)) { $$('#left-arrowz').setStyle('display', 'none');}
		}
	}
	
	// K
	function Knext(){
		console.log("up");
		if (impblocksk.cur > 0) {
			impblocksk.prev();
			event.preventDefault();
			$$('#right-arrowk').setStyle('display', 'block');
			$$('#left-arrowk').setStyle('display', 'block');	
			if (impblocksk.cur == '0') { $$('#right-arrowk').setStyle('display', 'none');}	
		}
	}
	function Kprev(){
		console.log("down");
		if (impblocksk.cur < (impblocksk.length - 1)) {		
			impblocksk.next();
			event.preventDefault();
			$$('#left-arrowk').setStyle('display', 'block');
			$$('#right-arrowk').setStyle('display', 'block');
			if (impblocksk.cur == (impblocksk.length - 1)) { $$('#left-arrowk').setStyle('display', 'none');}
		}
	}
	
	// 3rd
	function next(){
		console.log("up");
		if (impblocks.cur > 0) {
			impblocks.prev();
			event.preventDefault();
			$$('#right-arrowk').setStyle('display', 'block');
			$$('#left-arrowk').setStyle('display', 'block');	
			if (impblocks.cur == '0') { $$('#right-arrowk').setStyle('display', 'none');}	
		}
	}
	function prev(){
		console.log("down");
		if (impblocks.cur < (impblocks.length - 1)) {		
			impblocks.next();
			event.preventDefault();
			$$('#left-arrow').setStyle('display', 'block');
			$$('#right-arrow').setStyle('display', 'block');
			if (impblocks.cur == (impblocks.length - 1)) { $$('#left-arrow').setStyle('display', 'none');}
		}
	}
  
  // scrolling for news
  // Z
    $$('#lentaz').addEvent('mousewheel', function(event) { 
		event = new Event(event);
	 
		/* Mousewheel UP */
		if (event.wheel > 0) {
	        Znext();
		} 
		/* Mousewheel DOWN*/
		else if (event.wheel < 0) {
			Zprev();
		}
	});
	// K
    $$('#lentak').addEvent('mousewheel', function(event) { 
		event = new Event(event);
	 
		/* Mousewheel UP */
		if (event.wheel > 0) {
	        Knext();
		} 
		/* Mousewheel DOWN*/
		else if (event.wheel < 0) {
			Kprev();
		}
	});
	
	// 3rd
    $$('#lenta').addEvent('mousewheel', function(event) { 
		event = new Event(event);
	 
		/* Mousewheel UP */
		if (event.wheel > 0) {
	        next();
		} 
		/* Mousewheel DOWN*/
		else if (event.wheel < 0) {
			prev();
		}
	});
	
	
	//нижняя стрелка
	$$('#left-arrow').addEvent('mousedown', function(event) {     				
					impblocks.next();				
		      event.preventDefault();
          $$('#left-arrow').setStyle('display', 'block');
          $$('#right-arrow').setStyle('display', 'block');
          if (impblocks.cur == (impblocks.length - 1)) { $$('#left-arrow').setStyle('display', 'none');}	
          //if (impblocks.cur == '0') { $$('#left-arrow').setStyle('display', 'none');}                     
     }).addEvent('mouseup', function(event) {     				
		          	event.preventDefault();		            
     });

	$$('#left-arrowk').addEvent('mousedown', function(event) {     				
					impblocksk.next();				
		      event.preventDefault();
          $$('#left-arrowk').setStyle('display', 'block');
          $$('#right-arrowk').setStyle('display', 'block');
          //if (impblocksk.cur == '0') { $$('#left-arrowk').setStyle('display', 'none');}
          if (impblocksk.cur == (impblocksk.length - 1)) { $$('#left-arrowk').setStyle('display', 'none');}
     }).addEvent('mouseup', function(event) {     				
		          	event.preventDefault();		            
     });

	$$('#left-arrowz').addEvent('mousedown', function(event) {     				
					impblocksz.next();				
		      event.preventDefault();
          $$('#left-arrowz').setStyle('display', 'block');
          $$('#right-arrowz').setStyle('display', 'block');
          //if (impblocksz.cur == '0') { $$('#left-arrowz').setStyle('display', 'none');}
          if (impblocksz.cur == (impblocksz.length - 1)) { $$('#left-arrowz').setStyle('display', 'none');}		                         
     }).addEvent('mouseup', function(event) {     				
		          	event.preventDefault();		            
     });     
	      
	//верхняя стрелка
    $$('#right-arrow').addEvent('mouseleave', function(event) {
		          	event.preventDefault(); 							
     }).addEvent('mousedown', function(event) { 				 
				        impblocks.prev();
		          	event.preventDefault();
                $$('#right-arrow').setStyle('display', 'block');
                $$('#left-arrow').setStyle('display', 'block');
                //if (impblocks.cur == (impblocks.length - 1)) { $$('#right-arrow').setStyle('display', 'none');}
                if (impblocks.cur == '0') { $$('#right-arrow').setStyle('display', 'none');} 		          		      				
     }).addEvent('mouseup', function(event) {
		          	event.preventDefault();
     });

    $$('#right-arrowk').addEvent('mouseleave', function(event) {
		          	event.preventDefault(); 							
     }).addEvent('mousedown', function(event) { 				 
				        impblocksk.prev();
		          	event.preventDefault();
                $$('#right-arrowk').setStyle('display', 'block');
                $$('#left-arrowk').setStyle('display', 'block');
                if (impblocksk.cur == '0') { $$('#right-arrowk').setStyle('display', 'none');}
                //if (impblocksk.cur == (impblocksk.length - 1)) { $$('#right-arrowk').setStyle('display', 'none');}		          		      				
     }).addEvent('mouseup', function(event) {
		          	event.preventDefault();
     });

    $$('#right-arrowz').addEvent('mouseleave', function(event) {
		          	event.preventDefault(); 							
     }).addEvent('mousedown', function(event) { 				 
                impblocksz.prev();
		          	event.preventDefault();
                $$('#right-arrowz').setStyle('display', 'block');
                $$('#left-arrowz').setStyle('display', 'block');
                //if (impblocksz.cur == (impblocksz.length - 1)) { $$('#right-arrowz').setStyle('display', 'none');}	
                if (impblocksz.cur == '0') { $$('#right-arrowz').setStyle('display', 'none');}		          		      				
     }).addEvent('mouseup', function(event) {
		          	event.preventDefault();
     });
	      
	 //конкретный кадр 
	 
    $$('.item-scroll').addEvent('click', function(event) {
	 	event.preventDefault();	                 
		var pos = this.get('rel');
		impblocks.movepos(pos);					
    $$('#left-arrow').setStyle('display', 'block');
    $$('#right-arrow').setStyle('display', 'block');
    if (pos == '0') { $$('#left-arrow').setStyle('display', 'none');}
    if (pos == (impblocks.length - 1)) { $$('#right-arrow').setStyle('display', 'none');}
     })

     $$('.item-scrollk').addEvent('click', function(event) {
	 	event.preventDefault();	                 
		var pos = this.get('rel');
		impblocksk.movepos(pos);
    $$('#left-arrowk').setStyle('display', 'block');
    $$('#right-arrowk').setStyle('display', 'block');
    if (pos == '0') { $$('#left-arrowk').setStyle('display', 'none');}
    if (pos == (impblocksk.length - 1)) { $$('#right-arrowk').setStyle('display', 'none');}    					
     })
	 
    $$('.item-scrollz').addEvent('click', function(event) {
	 	event.preventDefault();	                 
		var pos = this.get('rel');
		impblocksz.movepos(pos);
    $$('#left-arrowz').setStyle('display', 'block');
    $$('#right-arrowz').setStyle('display', 'block');
    if (pos == '0') { $$('#left-arrowz').setStyle('display', 'none');}
    if (pos == (impblocksz.length - 1)) { $$('#right-arrowz').setStyle('display', 'none');}   					
     })

    $$('.smallshowinfo').addEvent('click', function(event) {
    window.location = this.get('href');
    })	    
/*     
//скроллер спецпредложений
  $$('.scroller ul').each(function(item) {
    var area = 110;

    item.myScroller = new Scroller(item, {
        area: area,
        velocity: 0.05,
        horizontal: false, 
        vertical: true
        
    });

    item.myScroller.start();
  });
*/
});

