
var Rotator = new Class({
      Implements: [Events, Options],
      options: {          
        cur: 0,          
        timeout: 3000,
        effect: 'slider'
      },
    
     initialize: function(list, options,events){
            this.setOptions(options);
             this.list=list;
             this.length=list.length; 
             if (this.options.effect=='rotator')
              this.list[0].setStyle('opacity', 1); 
          this.f.delay(this.options.timeout, this);  
          this.scroll = $$('.banner-slider .hidden');   
    },
    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.f.delay(this.options.timeout, this);
               
    },
  
    slide: function() {   
       	if(this.options.effect == 'slider'){
          		if(this.options.cur == this.length){
          		   
          		   $$('.banner-slider__arrbot').setStyle('display','block')
          		   var scroll       = new Fx.Scroll('banner-hidden', {
          				wait: false,
          				duration: 2000,
          				opacity: true,
          				transition: Fx.Transitions.Expo.easeInOut
          			}); 
          			scroll.start(0, 0)   
          		      this.options.cur = 0
          	   }else{
          		   if((this.length-this.options.cur) == 1)
          			$$('.banner-slider__arrbot').setStyle('display','none')
          			$$('.banner-slider__arrtop').setStyle('display','block')
          		   var scroll       = new Fx.Scroll('banner-hidden', {
          				wait: false,
          				duration: 2000,
          				opacity: true,
          				transition: Fx.Transitions.Expo.easeInOut
          			}); 
          			scroll.start(0, this.options.cur*235)
          	   }
          	   if(!this.options.cur) $$('.banner-slider__arrtop').setStyle('display','none')     
                    this.public.slideAfter();
         };
         if(this.options.effect == 'rotator'){
            if (this.options.cur >=this.length  ) this.options.cur = 0;
          if (this.options.cur < 0) this.options.cur = this.length-1;
          
          for(i=0;i<this.length;i++) {
           this.list[this.options.cur].morph({
                   
                     '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].morph({
                   
                     'opacity' : '1'
                    
                     
                                 
               });
         //this.list[this.options.cur].setStyle('opacity', 1).set('tween', {duration: 700});
          this.public.slideAfter();         
         
         }                    
    },
    
 public: { slideAfter: function() { 
    
    }   
  } 

})

window.addEvent('domready', function() {

	if ($chk($$('.banner-slider'))) {
		
		var  newslist = $$('.banner-item')
		if (newslist.length>0) {
		  newslist.Rotator = new Rotator(newslist, {timeout: 6000});
		  
			 
		  newslist.Rotator.start();    
		} 
		
		$$('.banner-slider').addEvent('mouseenter', function(e) {
				   
			 newslist.Rotator.stop();    

		}).addEvent('mouseleave', function(e) {
			   newslist.Rotator.start();  
		});      
		
		$$('.banner-slider__arrtop').addEvent('click', function(e) {
			e.preventDefault()
			var cur = newslist.Rotator.options.cur
			if(cur){
				newslist.Rotator.stop();
				newslist.Rotator.options.cur = cur-1
				var scroll       = new Fx.Scroll('banner-hidden', {
					wait: false,
					duration: 500,
					opacity: true,
					transition: Fx.Transitions.Expo.easeInOut
				}); 
				scroll.start(0, (cur-1)*235)
				
				if((cur-1) == 0)
					$$('.banner-slider__arrtop').setStyle('display','none')
					$$('.banner-slider__arrbot').setStyle('display','block')
			}
		})
		 
		$$('.banner-slider__arrbot').addEvent('click', function(e) {
			e.preventDefault()
			var cur = newslist.Rotator.options.cur
			if(cur != newslist.Rotator.list.length){
				newslist.Rotator.stop();
				newslist.Rotator.options.cur = cur+1
				var scroll       = new Fx.Scroll('banner-hidden', {
					wait: false,
					duration: 500,
					opacity: true,
					transition: Fx.Transitions.Expo.easeInOut
				}); 
				scroll.start(0, (cur+1)*235)
				
				if((newslist.Rotator.length-newslist.Rotator.options.cur) == 1)
					$$('.banner-slider__arrbot').setStyle('display','none')
					$$('.banner-slider__arrtop').setStyle('display','block')
			}
		})
		 
	}
	  
	 //Ротатор фоток в галерее
if ($chk($('gallery_rotator'))) {
    var  gallerylist = $$('#gallery_rotator > div').setStyle('opacity', 0).set('tween', {duration: 200});
       
    if (gallerylist.length>0) {
      gallerylist.Rotator = new Rotator(gallerylist, {timeout: 2500,effect:'rotator'});
        
         
      gallerylist.Rotator.start();    
    } 
    
    $('gallery_rotator').addEvent('mouseenter', function(e) {
               
         gallerylist.Rotator.stop();    

    }).addEvent('mouseleave', function(e) {
           gallerylist.Rotator.start();  
    });       
}

if ($chk($('gallery_rotator2'))) {
    var  gallerylist = $$('#gallery_rotator2 > div').setStyle('opacity', 0).set('tween', {duration: 200});
       
    if (gallerylist.length>0) {
      gallerylist.Rotator = new Rotator(gallerylist, {timeout: 2500,effect:'rotator'});
        
         
      gallerylist.Rotator.start();    
    } 
    
    $('gallery_rotator2').addEvent('mouseenter', function(e) {
               
         gallerylist.Rotator.stop();    

    }).addEvent('mouseleave', function(e) {
           gallerylist.Rotator.start();  
    });       
}

})

