var mainPath = '';
var mainPathFlash = '';
window.addEvent('domready', function()
{
	if(window.location.host == 'couderc.loc')
	{
		mainPath = '';
	}else{
		mainPath = 'fileadmin/templates/laRegion2010/';
	}
	/* SUCKERFISH MENU */
	if(Browser.Engine.trident && Browser.Engine.version < 5)
	{
		//Suckerfish Alternative for IE, using MOOTOOLS.
		$$('#menu li').each(function(el, index)
		{
			el.addEvents(
			{
				'mouseenter':function(e)
				{
					this.addClass('over');
				},
				'mouseleave':function(e)
				{
					this.removeClass('over');
				}
			});
		});
	}
	
	
	
	/*
	var cookClip = 1;
	if(Cookie.read('showClipCamp'))
	{
		cookClip = Cookie.read('showClipCamp');
	}
	if(cookClip == 1)
	{
		//Mediabox.open('http://www.laregion2010.fr/index.php?id=212', 'Clip de campagne', '500 360');
	}
	*/
	
	
	
	
	if($('header'))
	{
		var animC = new Element('div', {'id':'AnimHeaderC'}).inject('header','top');
		
		var animHeader = new Swiff(mainPath+"flash/header.swf", { id: 'animHeaderA', width:'960', height: 202, params: { 'wmode': 'transparent','AllowScriptAccess':'always' } });
		animC.adopt(animHeader);
	}
	if($('actusListW'))
	{
		actus.init({
			container:$('actusListW').getParent(), 
			wrapper:$('actusListW'),
			elements:$('actusListW').getElements('.actu'),
			rightBt:$('actusListW').getParent().getElements('.moveRight')[0],
			leftBt:$('actusListW').getParent().getElements('.moveLeft')[0],
			descClass:'.actu-infos'
		});
		actus.wrapper.addClass('scr');
		/*
		actus.list.each(function(el, index) 
		{
			
		});
		*/
	}
	if($('agenda') && $('agendaW'))
	{
		$('agenda').setStyle('overflow','hidden');
		var AgendaScroll = new fmcScrollTo(
		{
			slides: $$('#agenda .event'),
			container: $('agenda'),
			duration:300,
			onShow:function()
			{
				this.options.slides.each(function(el)
				{
					el.setStyle('opacity',.4);
				});
				this.options.slides[this.startIndex].setStyle('opacity',1);
			}
		});
		var stepLength = 1;
		var steps = len = $$('#agenda .event').length;
		var agendaC = $('agenda').getParent();
		AgendaScroll.scrollToEl(0);
		checkBTNS(AgendaScroll.startIndex, steps, 1, agendaC);
		agendaC.getElements('.moveLeft')[0].addEvent('click',function(e)
		{
			e.stop();
			if(AgendaScroll.startIndex != 0 && (AgendaScroll.startIndex-stepLength)>=0)
			{
				AgendaScroll.scrollToEl(AgendaScroll.startIndex-stepLength);
			}else{
				AgendaScroll.scrollToEl(0);
			}
			checkBTNS(AgendaScroll.startIndex, steps, 1, agendaC);
		});
		agendaC.getElements('.moveRight')[0].addEvent('click',function(e)
		{
			e.stop();
			if(AgendaScroll.startIndex < len-1 && Math.ceil(AgendaScroll.startIndex + stepLength / stepLength) - 1 <= steps)
			{
				AgendaScroll.scrollToEl(AgendaScroll.startIndex+stepLength);
			}else{
				//alert('Last : '+ scroller.startIndex +' - '+ (stepLength*steps-stepLength));
				AgendaScroll.scrollToEl(stepLength*steps-stepLength);
			}
			checkBTNS(AgendaScroll.startIndex, steps, 1, agendaC);
		});

	}
	if($('slider') && $('sliderW'))
	{
		var slides = $$('#slider .sliderItem');
		var btns = $$('#sliderMenu a');
		var activeSlide = 0;
		slides.each(function(el,index)
		{
			el.setStyle('display','none');
			if(btns[index])
			{
				btns[index].addEvent('click',function(e)
				{
					if(e) e.stop();
					this.addClass('act');
					if(activeSlide != null)
					{
						btns[activeSlide].getParent().removeClass('act');
						slides[activeSlide].setStyle('display','none');
					}
					activeSlide = index;
					btns[activeSlide].getParent().addClass('act');
					slides[activeSlide].setStyle('display','block');
				});
			}
		});
		slides[activeSlide].setStyle('display','block');
	}
	/* LAST : Lundi 22/02/2010 matin
	var cook = 1;
	if(Cookie.read('showPopup'))
	{
		cook = Cookie.read('showPopup');
	}
	if(cook == 1)
	{
		Edito.init.delay(1500, Edito);
	}
	*/
	/*
	if($('showEdito'))
	{
		$('showEdito').addEvent('click', function(e)
		{
			if(e) e.stop();
			Edito.init();
		});
	}
	*/
	var cook = 1;
	if(Cookie.read('showPopup99'))
	{
		cook = Cookie.read('showPopup99');
	}
	if(cook == 1)
	{
		Edito.init.delay(1500, Edito);
	}
	if($('twitter'))
	{
		var reqTwitt = new Request({url:'fileadmin/templates2/getTwitter.php', 
			encoding:'iso-8859-1',
			onSuccess: function(html) {
				$('twitter').removeClass('waiting');
				$('twitter').getChildren('.twitts')[0].set('html', html);
				
			},
			onFailure: function() {
				$('twitter').set('text', 'Le compte n\'est pas accéssible pour l\'instant.');
			},
			onRequest: function() {
				$('twitter').addClass('waiting');
			}
			
		}).send();
	}
	var galerieItems=$$('.galerie .photo a');
	var galerieItemsDiv=$$('.galerie .photo');
	galerieItems.each(function(photo,ind){
		galerieItemsDiv[ind].addEvents({
			'mouseenter':function(e){
				//this.addClass('photo-hover');
				this.set('tween',{duration:'short'});
				this.tween('background-color','#3B719D');
			},
			'mouseleave':function(e){
				this.tween('background-color','#F5F5F5');
				//this.removeClass('photo-hover');
			}
		});
	});
	
	var acc = new Fx.Accordion($$('.bandeau'), $$('.portraits'),{'display':-1, 'alwaysHide':true});
	

});
