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


	


	if($('menu-right-tabs')) {

	var IndexTab = new Tabs('menu-right-tabs', {duration:1000});

	} else {

	new SmoothScroll ({duration: 1000,transition:Fx.Transitions.Expo.easeInOut}, window); 

	}

	

	if($('right')) {

	$$('.menu-right li').each(function(elem) { 

			elem.addEvent('mouseenter', function(e) { 

						this.tween('left', '0', '10px')				 

				})

				elem.addEvent('mouseleave', function(e) { 

						this.tween('left', '10px', '0')				 

				})

		});

	}

	

	//if($$('.index-text')[0]) Intro.init();

	if($('homepage')) {

	var mySwiff = new Swiff('http://mamma-giovanna.ru/intro3.swf', { container: 'banner', width:900, height:300});

	}
	
	
	
	
	  var flashBanners = function(banners, duration, durationEfect) {

        this.count = 0;
        this.items = banners.length;
        this.banners = banners;
        this.duration = duration;
        this.durationEfect= durationEfect;

        this.init  = function()
        {
             this.banners.setStyle('opacity',0);
             this.fadeIn(0);
              setInterval(this.run.bind(this),this.duration)
        };

        this.run =  function()
        {
            this.fadeOut(this.count)

            this.count ++;
            if( this.items==this.count)
            {
               this.fadeIn(0)
               this.count = 0;
            } else {
              this.fadeIn(this.count)
            }

            return this;
        };


        this.fadeIn = function(index)
        {
                
               var Effect = new Fx.Tween(this.banners[index], {duration:this.durationEfect})
                Effect.start('opacity',[0,1]);
        }

        this.fadeOut = function(index)
        {
                 var Effect = new Fx.Tween(this.banners[index], {duration:this.durationEfect})
                Effect.start('opacity',[1,0]);

        }
    }


  var fl = new flashBanners($$('#promo-banner img'),3000, 1500);
  fl.init();

})



var Intro = {

	

	init: function() {

		this.len = $$('.index-text span').length;

           $$('.index-text span')[1].set('opacity',0);
	   //$$('.index-text span')[2].set('opacity',0);
	    

		this.count = 0;

 

		this.rotate.periodical(6000,this);

		$$('.index-text span').set('tween', {duration:1200});

	},

	

	rotate: function() {

		

		if(this.count<this.len) {

			var counter  = this.count++;

			$$('.index-text span').tween('opacity',0);

			$$('.index-text span')[counter].tween('opacity',1);

		} else {

			this.count = 0;

			

		}

		

	}

	

}

var Tabs = new Class ({

 	Implements: [Options, Events],

 	options: {

 		duration: 500,

		width: 660,

		opened: 1,

		layer: 'left',

		container: 'tabs-content',

		content: '.tab-content'

 		},

 	

 	initialize: function(ID,options){

				this.setOptions(options);	

 				this.ID = $(ID);

				this.layer = $(this.options.layer).setStyles({overflow:'hidden', position:'relative'})

				this.li = $$('#' +ID+' li');

				this.pocet = this.li.length;

				this.container = $(this.options.container);

				this.container.setStyles({width:this.pocet*this.options.width, position:'relative'});

				 $$(this.options.content + ' h2').setStyle('display','none');

				 $(this.options.layer).setStyle('height',$$(this.options.content)[0].getStyle('height'));

				

		this.li.each(function(elem,i) {

				if(i==(this.options.opened-1)) {

					elem.addClass('selected');

					this.container.setStyle('left',-(this.options.opened-1)*this.options.width);

				}

				

				elem.addEvent('click',function(event){ 

							 event.preventDefault();

							 // change title

							 var title = $(elem).getElements('a').get('text');

							 $('content-title').set('text',title);

							 this.li.each(function(el,j) { 

								el.removeClass('selected');

								if(i==j) { elem.addClass('selected');

									this.vyska  = $$(this.options.content)[i].getStyle('height');

									

									(function(){$(this.options.layer).tween('height',this.vyska);}.bind(this)).delay(1200);

								}

							  }.bind(this))

							 this.efekt(i,this.options.container,'left','');						

				}.bind(this));				  

		}.bind(this));

		

		

 	},

 	

	efekt: function(index,elem,how,type) {



		this.myEfekt = new Fx.Tween(elem, {duration:this.options.duration, transition: Fx.Transitions.Expo.easeOut});

		this.myEfekt.start(how,-index*this.options.width);	

			

	}

 	

 });






