var ind = 0
function qqq() {
     $$('.kupon').each(function(item) {
		     var  vis = item;
            var color = item.style.color;            
            if (color=="red"){
                vis.style.color = "#fff"
                ind=1
            }
            else{
              vis.style.color = "red"
              ind=0
            }       
		  });
  
}

window.setInterval('qqq()',300);

var Rotator = new Class({
      Implements: [Events, Options],
      options: {          
        cur: 0,          
        timeout: 3000,
        effect: 'rotator'
      },
    
     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);  
           
    },
    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 == '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[i].morph({                   
                     'opacity' : '0'                
            });
          }                 
        
          this.list[this.options.cur].set('morph', {duration: 1000, transition: Fx.Transitions.linear});        
           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() { 
    
    }   
  } 

})

//Скроллер плагин
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);
        
  },
  scrollTime: function(){
        var scroll = this.element.getScroll();      
        this.fireEvent('change', [scroll.x + 200, scroll.y]);    
  },
  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]);      
    } 
  }

});

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'
		});
	} 


	$$('.slider-box__wrapper').each(function(item) {
		var area =200;			
		item.myScroller = new Scroller(item, {
				area: area,
				velocity: 0.01,
				horizontal: true, 
				vertical: false
				
		});
		
		item.myScroller.start();
	
	});

  	//скроллер
	$$('.slider_2').each(function(item) {
		var area = 200;
			
		item.myScroller = new Scroller(item, {
				area: area,
				velocity: 0.05,
				horizontal: true, 
				vertical: false
		});

		item.myScroller.start();
	 //  setTimeout(function() {item.myScroller.scrollTime(); }, 500)

	});
	// //слайдер на главной 
if ($chk($$('.slider'))) {
		   
		var  newslist = $$('.slider .item')
		if (newslist.length>0) {
  		  newslist.Rotator = new Rotator(newslist, {timeout: 6000});			 
  		  newslist.Rotator.start();
      
        $$('.slider').addEvent('mouseenter', function(e) {
    				   
    			 newslist.Rotator.stop();    
    
    		}).addEvent('mouseleave', function(e) {
    			   newslist.Rotator.start();  
    		}); 
   
		} 
		
    
} 

// Pawel numbers for goods

	$$('.more').addEvent('click', function(){
		var node = this;
		id = node.id;
		productid = id.substring(5, id.lenght);
		value =  parseInt($("number_of_"+productid).get('value'));
		newvalue = value+1;
		$("number_of_"+productid).set('value', newvalue );
	});
	
	$$('.less').addEvent('click', function(){
		var node = this;
		id = node.id;
		productid = id.substring(5, id.lenght);
		value =  parseInt($("number_of_"+productid).get('value'));
		if (value >= 1) newvalue = parseInt(value)-1;
		$("number_of_"+productid).set('value', newvalue );
	});

//

});

