Shadowbox.init({
	language: 'ru',
	adapter: 'mootools',
	skipSetup: true,
	players:  ['img', 'html', 'swf']
});

screenAnimation = function() {
	var s = $('screen_text');

	var step1 = function() {
		s.set('tween', {
			link: 'chain',
			duration: 2500,
			onChainComplete: step2
		});
		s.tween('opacity', 0.99).tween('opacity', 0.5).tween('opacity', 0.99);
	}
	var step2 = function() {
		s.set('tween', {
			link: 'chain',
			duration: 40,
			onChainComplete: step3
		});
		s.tween('opacity', 0.99).tween('opacity', 0.1).tween('opacity', 0.99).tween('opacity', 0.1).tween('opacity', 0.99).tween('opacity', 0);
	}
	var step3 = function() {
		screenAnimation.currentText++;
		if (screenAnimation.currentText == screenAnimation.texts.length) {
			screenAnimation.currentText = 0;
		}
		s.set('html', screenAnimation.texts[screenAnimation.currentText]);

		if (0 && screenAnimation.currentText) {
			step2();
		} else {
			step1();
		}
	}

	step1()

}

window.addEvent('domready', function() {
   if ($chk($('screen_text'))) {  
   		screenAnimation();
   }


	// включаем shadowbox
  var Shadowbox_options = {
    resizeDuration: 0.2,
    fadeDuration: 0.2,
    viewportPadding: 10,
    handleOversize: 'drag',
    overlayOpacity: 0.5,
    viewportPadding: 5,
    autoDimensions: true,
		animate: false
  };

	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);
  }

  new SmoothScroll({
  	onStart: function() {
  		if (this.oldanchor) {
  			this.oldanchor.removeClass('anchored');
  		}
  		this.oldanchor = $(this.anchor).addClass('anchored');
  	}
  });
  
  //Menu
  if ($chk($$('.bg_top_menu'))) {

	$$('.bg_top_menu li').addEvent('mouseenter', function(event) {
            $$('.sub_menu_padding').setStyle('opacity',0);
            $$('.sub_menu_padding2').setStyle('opacity',0);
			var id  = this.get('id');	
			id  = id.match('\\d+');
			var node =  $('submenu'+id);			
		 	node.setStyle('opacity',1);
			node.addClass('current');		 			
    }).addEvent('mouseleave', function(event) {	
    	    $$('.sub_menu_padding').each(function(item) {    	  	
			   if   (!this.hasClass('current'))   		   
					item.setStyle('opacity',0) ;							
			}); 
			$$('.sub_menu_padding2').each(function(item) {    	  	
				 if   (!item.hasClass('nowsub'))   		   
						item.setStyle('opacity',0) ;
							
		 	}); 				 
			event.preventDefault();		  				
    });
    $$('.top_menu').addEvent('mouseleave', function(event) {	
    	 $$('.sub_menu_padding').each(function(item) {    	  	
		 if   (!item.hasClass('now'))   		   
				item.setStyle('opacity',0) ;
							
		 }); 	
		  $$('.sub_menu_padding2').each(function(item) {    	  	
		 if   (!item.hasClass('nowsub'))   		   
				item.setStyle('opacity',0) ;
							
		 }); 	
        if ($$('.now').getStyle('visibility')=='hidden') {    
			$$('.now').setStyle('opacity',1)
		}
    	if ($$('.nowsub').getStyle('visibility')=='hidden') {    
			$$('.nowsub').setStyle('opacity',1)
		}
		$$('.sub_menu_padding').removeClass('current');	
		$$('.sub_menu_padding2').removeClass('current');		
    });
    $$('.sub_menu_padding').addEvent('mouseleave', function(event) {
	    
    		$$('.sub_menu_padding').removeClass('current') ;				
    });
    
    //menu2
    $$('.sub_menu_padding a').addEvent('mouseenter', function(event) {
            $$('.sub_menu_padding2').setStyle('opacity',0);
			var id  = this.get('id');
		
			id  = id.match('\\d+');
			
			var node =  $('submenu2'+id);			
		 	node.setStyle('opacity',1);
			node.addClass('current');		 			
    }).addEvent('mouseleave', function(event) {	
    	    $$('.sub_menu_padding2').each(function(item) {    	  	
		   if   (!this.hasClass('current'))   		   
				item.setStyle('opacity',0) ;							
			}); 			 
			event.preventDefault();		  				
    });
 
    $$('.sub_menu_padding2').addEvent('mouseleave', function(event) {
	    
    		$$('.sub_menu_padding2').removeClass('current') ;				
    });


}
});