var currentScrollHome = 1;
var currentScrollActu = 1;

var scroll = '';
var scrollActu = '';

var timerHome = false;
var timerActu = false;

var currentDirHome = 'right';
var currentDirActu = 'right';

window.addEvent('domready',function() {
	scroll = new Fx.Scroll('homeScroll-wrapper', {
		wait: false,
		duration: 1500,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	scrollActu = new Fx.Scroll('actuScroll-wrapper', {
		wait: false,
		duration: 1500,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	loadAnimationHome();
	
	loadAnimationActu();
	
	/***********************************/
	/** Top Menu - behaviours         **/
	/***********************************/
	
	// Define Fx vars
	var searchBoxSlide = new Fx.Slide('topMenu-searchBox');
	var languageBoxSlide = new Fx.Slide('topMenu-languageBox');
	
	// Set style to display: none
	$('topMenu-searchBox-wrapper').setStyles({
		display: 'none'
	});
	
	$('topMenu-languageBox-wrapper').setStyles({
		display: 'none'
	});
	
	// add events to links
	$('top-search-link').addEvent('click', function(e){
		e.stop();
		if (searchBoxSlide.open == false) {
			$('topMenu-searchBox-wrapper').setStyles({
				display: 'block'
			});
			searchBoxSlide.slideIn();
			if (languageBoxSlide.open == true) {
				languageBoxSlide.slideOut();
				(function () {$('topMenu-languageBox-wrapper').setStyles({ display: 'none'})}).delay(600);
			}
		}
		else if (searchBoxSlide.open == true) {
			searchBoxSlide.slideOut();
			(function () {$('topMenu-searchBox-wrapper').setStyles({ display: 'none'})}).delay(600);
		}
	});
	
	$('top-language-link').addEvent('click', function(e){
		e.stop();
		if (languageBoxSlide.open == false) {
			$('topMenu-languageBox-wrapper').setStyles({
				display: 'block'
			});
			languageBoxSlide.slideIn();
			if (searchBoxSlide.open == true) {
				searchBoxSlide.slideOut();
				(function () {$('topMenu-searchBox-wrapper').setStyles({ display: 'none'})}).delay(600);
			}
		}
		else if (languageBoxSlide.open == true) {
			languageBoxSlide.slideOut();
			(function () {$('topMenu-languageBox-wrapper').setStyles({ display: 'none'})}).delay(600);
		}
	});
	
	searchBoxSlide.hide();
	
	languageBoxSlide.hide();
});

function loadAnimationHome() {
	if((timerHome)) {
		(timerHome);
		dbug.log('timer cleared '+timerHome);
	}
	timerHome = scrollAnimationHome.periodical(7000);
}

function loadAnimationActu() {
	if((timerActu)) {
		(timerActu);
		dbug.log('timer cleared '+timerActu);
	}
	timerActu = scrollAnimationActu.periodical(6000);
}

function scroll_To_Home(dir) {
	if (dir == 'left') {
		if (currentScrollHome <= 2) currentScrollHome=1; else currentScrollHome--;
	}
	else if (dir == 'right') {
		if(currentScrollHome >= maxScrollHome) currentScrollHome = maxScrollHome; else currentScrollHome++;
	}
	if (currentScrollHome <= (maxScrollHome)) scroll.start((currentScrollHome-1)*640,0);
	
	//scroll.toElement('bannerC'+currentScroll);
	//alert(dir+' - bannerC'+currentScroll+'/'+maxScroll);
}

function scroll_To_Actu(dir) {
	if (dir == 'left') {
		if (currentScrollActu <= 2) currentScrollActu=1; else currentScrollActu--;
	}
	else if (dir == 'right') {
		if(currentScrollActu >= maxScrollActu) currentScrollActu = maxScrollActu; else currentScrollActu++;
	}
	if (currentScrollActu <= (maxScrollActu)) scrollActu.start((currentScrollActu-1)*640,0);
	
	//scroll.toElement('bannerC'+currentScroll);
	//alert(dir+' - bannerC'+currentScroll+'/'+maxScroll);
}

function scrollAnimationHome() {
	if (currentScrollHome < maxScrollHome && currentDirHome == 'right') {
		scroll_To_Home('right');
	}
	else if (currentScrollHome > 1 && currentDirHome == 'left') {
		scroll_To_Home('left');
	}
	else if (currentScrollHome == maxScrollHome) {
		currentDirHome = 'left';
	}
	else if (currentScrollHome == 1) {
		currentDirHome = 'right';
	}
}

function scrollAnimationActu() {
	if (currentScrollActu < maxScrollActu && currentDirActu == 'right') {
		scroll_To_Actu('right');
	}
	else if (currentScrollActu > 1 && currentDirActu == 'left') {
		scroll_To_Actu('left');
	}
	else if (currentScrollActu == maxScrollActu) {
		currentDirActu = 'left';
	}
	else if (currentScrollActu == 1) {
		currentDirActu = 'right';
	}
}
