var soonMenu = new Class({
	
	Implements: Options,
	
	options: {
		maxSize : 18,
		minSize : 12
	},

	initialize: function(container, elems, options){
		this.setOptions(options);
		this.container = $(container);
		this.elems     = elems;
		this.container.addEvents({
			'mousemove': function(e){
				this.menuFx(e);
			}.bind(this),
			'mouseleave': function(){
				this.reset();
			}.bind(this)
		});
	},

	reset: function(){
		this.elems.each(function(el, i){
			var repos = new Fx.Morph(el).start({'font-size': this.options.minSize});
		}.bind(this));
	},

	menuFx: function(e){
		this.elems.each(function(el, i){
			cos = ( el.getPosition().y + el.getSize().y /2 - (e.client.y) - window.getScroll().y ) / this.options.maxSize / 2;
			//if (i==0) console.log (cos);
			cos = Math.max(Math.min(cos,Math.PI/2), - Math.PI/2);
			el.setStyle('font-size',( Math.max((this.options.maxSize * Math.cos(cos)), this.options.minSize)).toInt());
		},this);
	}
});

var soonNews = new Class({

	Implements: Options,

	options: {
		ziNews: 'uneHomeNews',
		timer : 5000
	},

	initialize: function(options){
		this.setOptions(options);
		this.news    = $$('.' + this.options.ziNews);
		this.newsNum = this.news.length;
		this.i       = 0;
		this.news.each(function(el, i){
			if (i != 0) el.setStyle('opacity', 0);
		});
		this.defil.delay(this.options.timer, this);
	},

	defil: function(){
		var j;
		j = this.i == this.newsNum - 1 ? 0 : this.i + 1;
		this.news[this.i].fade('out');
		this.news[j].fade('in');
		this.i == this.newsNum - 1 ? this.i = 0 : this.i++;
		this.newsFx = this.defil.delay(this.options.timer, this);
	}

});

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

	var footerSoon = function(){
		var minHeight = $('main').getScrollSize().y;
		//hauteur du div principal
		if(minHeight < (window.getSize().y - 20)){
			var cpc = window.getSize().y - 96 + 'px';
			$('main').setStyle('height', cpc);
		}
	}
	footerSoon();
	window.addEvent('resize', function(){
		footerSoon();
	});

	if ($$('.uneHomeNews').length > 1){
		var newsFx = new soonNews({ziNews : 'uneHomeNews'})
	}

	//effet m6 sur menus clients et thèmatiques
	if ($('listClients')) var clientsMenu = new soonMenu ('listClients', $$('#listClients li'));
	if ($('listThem')) var themMenu    = new soonMenu ('listThem', $$('#listThem li'));

	//accordéon de la page de news
	if ($$('.newsContent').length > 1){
		$$('.newsPTitre').setStyle('cursor', 'pointer');
		var newsAcc = new Fx.Accordion($$('.newsPTitre'), $$('.newsContent'), {
			opacity: false
		});
	}

	//accordéon de la page de FAQ si trois et plus
	if ($$('.uneFaq').length > 2){
		$$('.uneFaq h3').setStyle('cursor', 'pointer');
		var faqAcc = new Fx.Accordion($$('.uneFaq h3'), $$('.faqRep'), {
			opacity: false,
			display: quest,
			onActive: function(){ footerSoon(); }
		});
	}

	//menu à puces...
	if($$('.menuAnim')){
		var ma = $$('.menuAnim');
		var mb = $$('#puceMenu a');
		var lb = $('topbaselink');
		var lbfx = new Fx.Tween(lb, {duration: 500, link: 'cancel'});
		ma.each(function(el, i){
			var elfx = new Fx.Morph(el, {duration: 500, link: 'cancel'});
			el.addEvents({
				'mouseenter': function(){
					lbfx.start('width', 0);
					elfx.start({
						'width'       : 150 + (i * 27)
					});
					el.getFirst('a').setStyle('background-position', 'left -50px');
				},
				'mouseleave': function(){
					lbfx.start('width', 563);
					elfx.start({
						'width'       : 17
					});
					el.getFirst('a').setStyle('background-position', 'left center');
				}
			});
		}); 
	}

	//carrousel web
	if ($$('.uneReal').length > 0){
		var real     = $$('.uneReal');
		var cont     = $$('.realimg');
		var prevButt = $$('.leftArrow');
		var nextButt = $$('.rightArrow');
		var buttDivs = $$('.animButts');
		var ziPictos = $$('.carrouPicto');
		var cTxtCont = $$('.realRight');
	
		cont.each(function(el, i){
			new moodVcarrou(real[i], el, {
				nextB    : nextButt[i],
				prevB    : prevButt[i],
				buttDiv  : buttDivs[i],
				listPicto: ziPictos[i],
				listText : cTxtCont[i]
			});
		});
	}

	//joujou avec les listes de vidéos
	//plus utilisé pour le moment
	if ($$('.videoSerie').length > 1){
		ziDivs  = $$('.videoSerie');
		ziLinks = $$('.paginLing');
		ziDivs.each(function(el, i){
			if (i != 0) el.setStyle('display', 'none');
		});
		footerSoon();
		ziLinks.each(function(el, i){
			el.addEvent('click', function(e){
				e.stop();
				ziLinks.each(function(elem, j){
					i == j ? elem.addClass('selectPage') : elem.removeClass('selectPage')
				});
				ziDivs.each(function(elem, j){
					i == j ? elem.setStyle('display', 'block') : elem.setStyle('display', 'none');
					footerSoon();
				});
			});
		});
	}

});//fin domready général


