

window.addEvent('domready', function() {

	// var colors = {'pageProfile':'#75bf56','pagePublication':'#babcbf','pageContact':'#fdc220','work00':'#babcbf','work01':'#75bf56','work02':'#fdc220','work03':'#75bf56','work04':'#fdc220','work05':'#fdc220','work06':'#fdc220','work07':'#fdc220'}

var colors = new Array();
colors['pageProfile'] = '#75bf56';
colors['Publication'] = '#5ed1b3';
colors['publication00'] = '#16c3f1';
colors['publication01'] = '#f1163b';
colors['publication02'] = '#aa5cbb';
colors['publication03'] = '#14daa5';
colors['pageContact'] = '#fdc220';
colors['Work'] = '#64a2be';
colors['work00'] = '#5ed1b3';
colors['work01'] = '#775187';
colors['work02'] = '#fdc220';
colors['work03'] = '#ad5a8e';
colors['work04'] = '#775187';
colors['work05'] = '#cb3454';
colors['work06'] = '#48a6d6';
colors['work07'] = '#d65522';
colors['work081'] = '#e4c400';
colors['work082'] = '#e45400';
colors['work09'] = '#3dbb35';
colors['work10'] = '#fdc220';
colors['work11'] = '#ad5a8e';
colors['work12'] = '#775187';
colors['work13'] = '#cb3454';

var oldColor = '#babcbf';
var page = "";

var myElement = $('RightContent');
var myScroll = new Fx.Scroll(myElement, {
    duration: 700,
    wait: false,
	offset: {
        'x': 0,
        'y': -153
    }
});
// color fade
var Main = $('Main');
var myFxColor = new Fx.Tween(Main, {
    duration: 1000,
    wait: false
});

var ColorsObj = $$('.color');
var myFxColorObj = new Fx.Tween(ColorsObj, { duration: 1000, wait: false });

//
		
var WorksBt = $('Menu').getElements('a');

WorksBt.each(function(bt){
	var alt = bt.get('alt');
	var div = $(bt.get('alt'));
	var parent = bt.getParent('.SubMenu');
	var submenu = document.getElement('div[alt='+alt+']');

	bt.addEvents({
		'click': function(event){
		    event.preventDefault();
			page = alt;
			if (div){
				$$('#Menu a').removeClass('select color');
				bt.addClass('select color');
				if (parent){
					var parentBt = $('Menu').getElement('a[alt='+parent.get('alt')+']');
					parentBt.addClass('select color');
				} else {
					$$('.SubMenu').setStyles({'display':'none'});
				}
				myScroll.toElement(div);
				myFxColor.start('background-color', colors[page]);
				$$('#Menu a').setStyles({'color':'#000'});
				colorBt(colors[page]);
				LoadContent(bt.get('href'));
			}
			if (submenu){
				$$('SubMenu').setStyles({'display':'none'});
				submenu.setStyles({'display':'block'});
			}
			oldColor = colors[page];
			setNumPage();
		}
	})
});

$('Logo').addEvents({
	'click': function(){
		$$('#Menu a').removeClass('select color');
		myScroll.toElement($('pageHome'));
		myFxColor.start('background-color', '#babcbf');
		$$('#Menu a').setStyles({'color':'#000'});
		colorBt('#babcbf');
		$$('.SubMenu').setStyles({'display':'none'});
		oldColor = '#babcbf';
	}
});

function LoadContent(link){
	var Result;
	var Target = $(page).getElement('.PagesFrame');
	// var req = new Request.HTML({
	// 	url:link,
	// 	async: false,
	// 	onSuccess: function(html) {
	// 		var empty = Target.empty();
	// 		Target.adopt(html);
	// 	},
	// 	onFailure: function() {
	// 	}
	// }).send();
	get_content(link,Target);
}

function get_content(url,update) {
	if ( document.location.protocol == "file:" ) {
		// console.log(’local’);
		var ifr = new IFrame({
			src:url,
			events:{
				load: function() {
					$(update).set("html", this.contentWindow.document.body.innerHTML );
					setNumPage();
				}
			}
			}).inject(document.body);
		} else {
			// console.log(’server’);
			var myHTMLRequest = new Request.HTML({
				update:update,
					onSuccess: function(html) {
						setNumPage();
					}
				}).get(url);
			}
}

function setNumPage(){
	var nbs = $(page).getElements('.PageFrame').length;
	var nbsHide = $(page).getElements('.Hide').length;
	var pagenumtarget = $(page).getElement('.PageNum');
	if(nbs>0){
		pagenumtarget.set({'html':nbsHide+1+'/'+nbs});
	}
}

function colorBt(color){
	var Bts = $$('.color');
	Bts.each(function(bt){
		var myFxColorObj = new Fx.Tween(bt, { duration: 1000, wait: false }).start('color', oldColor, color);
	});
}


function showPrev(){
	if ($(page).getElements('.Hide').length > 0){
		var hide = $(page).getElements('.Hide');
		var Box = hide[hide.length-1];
		Box.removeClass('Hide');
		var ColumnContent = Box.getElement('.PageFrameContent');
		var myHorizontalSlide = new Fx.Slide(ColumnContent, {mode: 'horizontal',duration:500,transition: Fx.Transitions.Quad.easeInOut}).hide();
		myHorizontalSlide.slideIn();
		setNumPage();
	}
}

function showNext(){
	if ($(page).getElements('div[class=PageFrame]').length > 1){
		var Box = $(page).getElement('div[class=PageFrame]');
		var BoxContent = Box.getElement('.PageFrameContent');
		var myFx3 = new Fx.Slide(BoxContent, {mode: 'horizontal',duration:500,transition: Fx.Transitions.Quad.easeInOut}).show().slideOut();
		Box.set({'class':'PageFrame Hide'});
		setNumPage();
	}
}



$$('.PrecBt').addEvents({
	'click': function(event){
    event.preventDefault();
	showPrev();
	}
});

$$('.SuivBt').addEvents({
	'click': function(event){
    event.preventDefault();
	showNext();
}
});


});


