
window.addEvent('domready', function(){
	
	if($('corpo').getElement(".box-news")){
		var scrEl = $('corpo').getElement(".box-news");
		var durata = 3000 ;
		var myScroller = new Fx.Scroll(scrEl, {
		    duration: durata,
		    link: 'cancel',
			transition: 'linear'
		});
		var nitems = $$('.news-item');
		var select= 0;
		nitems.each(function(e){
			e.myEffects = new Fx.Morph(e, {duration: 300, link: 'chain'});
		});
		
		nitems.addEvents({
			'mouseenter': function(){
				myScroller.pause();
				autoscrollp = $clear(autoscrollp);
				this.myEffects.start({
				    'margin-left': [20, 0],
					'margin-right': [20, 0],
				    'width': [150, 190],
					'padding-top': 20 ,
					'padding-bottom': 20 ,
					'background-color': '#fff',
					'border-width': '1px 1px 1px 1px'
				});
			},
			'mouseleave': function(){
				myScroller.resume();
				autoscrollp = autoscroll.periodical(durata, myScroller);
				this.myEffects.start({
				    'margin-left': [0, 20],
					'margin-right': [0, 20],
				    'width': [188, 150],
					'padding-top': 10 ,
					'padding-bottom': 10 ,
					'border-width': '0 0 1px 0'
				}).chain((function(){this.setStyle('background-color','transparent')}).bind(this));
			}
		});
		var myScroller_up = new Element('div', {
		    'class': 'scroll_up',
		    'html': '',
		    'events': {
				'click': function(){
					select = select<1?0:select-1;
					myScroller.toElement(nitems[select]);
				},
		        'mouseover': function(){this.setStyle('background-color','#3af'); $clear(autoscrollp) },
		        'mouseout': function(){this.setStyle('background-color','transparent'); autoscrollp = autoscroll.periodical(durata, myScroller)},
		        'mousedown': function(){this.setStyle('background-color','#fff');},
		        'mouseup': function(){this.setStyle('background-color','#3af');}
		    }
		});
		var myScroller_down = new Element('div', {
		    'class': 'scroll_down',
		    'html': '',
		    'events': {
		        'click': function(){
		            select = select< nitems.length-1?select+1:select;
		            myScroller.toElement(nitems[select]);
		        },
		        'mouseover': function(){this.setStyle('background-color','#3af'); $clear(autoscrollp)},
		        'mouseout': function(){this.setStyle('background-color','transparent'); autoscrollp = autoscroll.periodical(durata, myScroller)},
		        'mousedown': function(){this.setStyle('background-color','#fff');},
		        'mouseup': function(){this.setStyle('background-color','#3af');}
		    }
		});

		myScroller_down.inject(scrEl, 'after');
		myScroller_up.inject(scrEl, 'before');

		var autoscroll = function(){
			if(select< nitems.length-1) {
				select = select+1;
				this.toElement(nitems[select]);
			} else {
				select = 0;
				this.toTop();
			}
		} ;
		var autoscrollp = autoscroll.periodical(durata, myScroller);
		if(nitems[1]){	myScroller.toElement(nitems[1]); select = 1;}
		
	}
	
	var items = $$('#menu li');
	items.addEvents({
		'mouseenter': function(){
			this.set('tween', {
				duration: 500,
				link:'ignore',
				transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
			}).tween('width', '180px');
		},
		'mouseleave': function(){
			this.set('tween', {}).tween('width', '40px');
		}
	});
	var itms_sel = $$('#menu li.selected');
	itms_sel.removeEvents('mouseleave');
	itms_sel.setStyle('width', '180px');
	
	if($("prd_cat_0")) {
		$("prd_cat_0").addEvents({
			'mouseenter': function(){
				this.set('tween', {
					duration: 1500,
					link:'ignore',
					transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
				}).tween('margin-left', '-600px');
			},
			'mouseleave': function(){
				this.set('tween', {}).tween('margin-left', '0px');
			}
		});
		$("prd_cat_1").addEvents({
			'mouseenter': function(){
				this.set('tween', {
					duration: 1000,
					link:'ignore',
					transition: Fx.Transitions.Bounce.easeOut // This could have been also 'bounce:out'
				}).tween('margin-top', '0px');
			},
			'mouseleave': function(){
				this.set('tween', {}).tween('margin-top', '-200px');
			}
		});
		$("prd_cat_2").addEvents({
			'mouseenter': function(){
				this.set('tween', {
					duration: 1500,
					link:'ignore',
					transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
				}).tween('margin-left', '0px');
			},
			'mouseleave': function(){
				this.set('tween', {}).tween('margin-left', '-400px');
			}
		});
		$("prd_cat_3").addEvents({
			'mouseenter': function(){
				this.set('tween', {
					duration: 1000,
					link:'ignore',
					transition: Fx.Transitions.Bounce.easeOut // This could have been also 'bounce:out'
				}).tween('margin-left', '-200px');
			},
			'mouseleave': function(){
				this.set('tween', {}).tween('margin-left', '0px');
			}
		});
		var myTips = new Tips('.tips');
		myTips.tip.set('tween',{duration: 500});
		myTips.addEvent('show', function(tip){
			tip.fade(0.8);
		});
		myTips.addEvent('hide', function(tip){
			tip.fade('out');
		});
	};
	if($("c6")) {
		/*var slide_rc = function(){ this.counter++; };*/
		var slider2 = $('slide-ric') ;
		var myFx =function (){
			var h = 144 ;
			if(this.getStyle('height').toInt()+this.getStyle('margin-top').toInt()==h) {
				this.tween('margin-top', '0');
			} else {
				this.tween('margin-top', this.getStyle('margin-top').toInt()-h);
			}
		};
		myFx.periodical(4000, slider2);
		
		new viewer($$('#slide-prod img'),{
			mode: 'alpha',
			interval: 3000
		}).play(true);
	}
	if($("club")) {
		new viewer($$('#club1 img'),{
			mode: 'alpha',
			interval: 4000
		}).play(true);
	}
	if($("slide-menu")) {
		new viewer($$('#slide-menu img'),{
			mode: 'alpha',
			fxOptions: {duration:1500},
			interval: 5000
		}).play(true);
	}
	if($('corpo').getElement(".menucat")){
		var catimg = $$('.categoria-box > a:first-child');
		//var efxs = [];
		catimg.each(function(itm, i){
			var efxs = new Fx.Morph(itm, {link: 'cancel', duration: 500, transition: Fx.Transitions.Elastic.easeOut});
			var efxs2 = new Fx.Morph(itm.getFirst(), {link: 'cancel', duration: 500, transition: Fx.Transitions.Elastic.easeOut});
			itm.addEvents({
				'mouseenter': function(){
					efxs.start({'height': [165], 'width': [165], 'top':[10], 'left':[18] });
					efxs2.start({'margin': [-3]});
				},
				'mouseleave': function(){
					efxs.start({'height': [140], 'width': [140], 'top':[22], 'left':[30] });
					efxs2.start({'margin': [-15] });
				}
			})
		});
	}
});

var simpleRoll = new Class({
	Implements: [Options, Events],
	options: {
		slides: [],
		startIndex: 0,
		wrap: true
		//onShow: $empty
	},
	initialize: function(options){
		this.setOptions(options);
		this.addSlides(this.options.slides);
		if(this.slides.length) this.showSlide(this.options.startIndex);
		this.cycleForward.periodical(5000, this);
	},
	slides: [],
	addSlides: function(slides){
		$$(slides).each(function(slide){
			this.slides.include($(slide));
			slide.setStyle('display', 'none');
			//slide.addEvent('click', this.cycleForward.bind(this));
		}, this);
	},
	addSlide: function(slide){
		this.addSlides($splat($(slide)));
	},
	cycleForward: function(){
		if($chk(this.now) && this.now < this.slides.length-1) this.showSlide(this.now+1);
		else if ((this.now) && this.options.wrap) this.showSlide(0);
		else if(!$defined(this.now)) this.showSlide(this.options.startIndex);
	},
	cycleBack: function(){
		if(this.now > 0) this.showSlide(this.now-1);
		else if(this.options.wrap) this.showSlide(this.slides.length-1);
	},
	showSlide: function(iToShow){
		if (this.fading) return;
		var now = this.now;
		var currentSlide = this.slides[now];
		var slide = this.slides[iToShow];
		var fadeIn = function (s){
			this.fading = true;
			s.setStyles({
				display:'block',
				visibility: 'visible',
				opacity: 0
			});
			s.get('tween').start('opacity', 1).chain(function(){
				this.fading = false;
				this.fireEvent('onShow', [slide, iToShow]);
			}.bind(this));
		}.bind(this);
		if(slide) {
			if($chk(now) && now != iToShow){
				this.fading = true;
				currentSlide.get('tween').start('opacity', 0).chain(function(){
					currentSlide.setStyle('display', 'none');
					fadeIn(slide);
				}.bind(this));
			} else fadeIn(slide);
			this.now = iToShow;
		}
	}
});
