var Scroller = new Class({

	Implements: [Events, Options],

	options: {
		area: 250,
		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(1000 / 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 (change.y || change.x) {
		    
			this.fireEvent('change', [scroll.x + change.x, scroll.y + change.y]);
			
		}
	}

});

Shadowbox.init({
	language: 'ru',
	adapter: 'mootools',
	skipSetup: true,
	players:  ['img']
});


window.addEvent('domready', function() {



	// включаем shadowbox
  var Shadowbox_options = {
    resizeDuration: 0.2,
    fadeDuration: 0.2,
    viewportPadding: 10,
    handleOversize: 'drag',
    overlayOpacity: 0.5,
    viewportPadding: 5,
    autoDimensions: true,
		animate: false
  };
  
  function init_image() {
	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) {
		Shadowbox.setup(list, Shadowbox_options);
  }
  }
  
  init_image() ;
  
  //Правая плашка
  
 if ($chk('.list_plashka')) {
		
		$$('.list_plashka a').addEvent('click', function(event) {
				var rel=this.get('rel');
				var node =  $('black-w')
				
			      
				if (rel!=null) {
					if (node.getStyle('visibility')=='hidden' ) {	
						node.morph({
      									'opacity': 0						
      					}); 
						var html  = $(rel).get('html');
						
						node.getElement('.center').set('html',html);
						
						node.morph({
      									'opacity': 1						
      					});      					
						this.getParent('ul').getElements('li').removeClass("akt_link_plashka");  			
	        			this.getParent('li').addClass("akt_link_plashka");
	        			
					
					}
					else {
				     	node.morph({
      									'opacity': 0						
      					}); 
      					this.getParent('ul').getElements('li').removeClass("akt_link_plashka");
      				
      					
					}
					event.preventDefault(); 
				} 
			
	        
			
		
				
     })
     $$('.close').addEvent('click', function(event) {
				        
						var node =  $('black-w');
						$('list_plashka').getElements('li').removeClass("akt_link_plashka");
					    node.morph({
      									'opacity': 0						
      					}); 
      					event.preventDefault(); 
			
	    
			
		
				
     })
  } 
// 
if ($chk('.tooltip')) {	
	var node = $('js-tooltip');      
	var height = node.getStyle('height').toInt();
	    
	var top=-height+20 ;
	node.setStyle('margin-top',top);
	node.setStyle('visibility','visible');
  }
  

});
 

