
window.addEvent('domready', function() {
	
	$$('img').each(function(img){
		img.setProperty('galleryimg','no');
		var myDrag = new Drag(img);
		img.addEvents({
			'contextmenu': function(event){
				return false;
			}
		});
	})


	if ((Browser.Engine.webkit == true || Browser.Engine.gecko == true)){
		$('LeftContent').setStyles({'padding-top': window.getHeight()+50});
		var myEffect = new Fx.Morph('LeftContent', {duration: 600}).start({
		    'padding-top': [window.getHeight()+50,50]
		});
		if (Browser.Engine.gecko == true){
			$('RightContent').setStyles({'padding-top': window.getHeight()+50});
			var myEffect = new Fx.Morph('RightContent', {duration: 600}).start({
			    'padding-top': [window.getHeight()+50,50]
			});
		}
	} else {
		$('LeftContent').setStyles({'padding-top': 50});
	}

	if(Browser.Engine.webkit == true || Browser.Engine.gecko == true){
		$$('a').each(function(a){
			if (!a.get('class').contains('noevent')){
				a.addEvents({
					'click': function(event){
						event.preventDefault();
						$('LeftContent').setStyles({'padding-bottom': window.getHeight()+50});
						if (Browser.Engine.gecko == true){
							$('RightContent').setStyles({'padding-bottom': window.getHeight()+50});
							var myFx = new Fx.Scroll(document, { duration: 600, wait: false }).toBottom();
						}
						var myFx = new Fx.Scroll(document, { duration: 600, wait: false }).toBottom();
						(function(){ document.location.href = a.get('href'); }).delay(600);
					}
				})
			}
		})
	}

});


function setCookies(name,value,complete){
	var myRequest = new Request({
		url: 'setcookies.php?name='+name+'&value='+value,
		onComplete: function(response){
			if (complete){
				document.location.reload();
			}
		}}).get();
}

function setSessions(name,value,complete){
	var myRequest = new Request({
		url: 'setsessions.php?name='+name+'&value='+value,
		onComplete: function(response){
			if (complete){
				document.location.reload();
			}
		}}).get();
}

// Tab

function loadUrlIn(url,target,fade){
	if ((target.getCoordinates().top-window.getScroll().y > 0)){
		loadUrl(url,target,fade);
	} else {
		var myFx = new Fx.Scroll(window, {
		    offset: {
		        'x': 0,
		        'y': -100
		    },
		onComplete: function(){
			loadUrl(url,target,fade);
			}}).start(0,target.getCoordinates().top)
	}
}

function loadUrl(url,target,fade){
	if (fade){ var myFx2 = new Fx.Tween(target,{duration: 800, link: 'chain',transition: Fx.Transitions.Quad.easeIn}).set('opacity',0); }
	var myHTMLRequest = new Request.HTML({
		url: url+'&lng='+lng,
		update: target,
		onComplete: function(){
			if (fade){ myFx2.start('opacity',1); }
			setLink();
		}}).get();
}

function show(id){
	$('show'+id).setStyles({'display':'none'});
	$('content'+id).setStyles({'display':'block'});
}

function hide(id){
	$('show'+id).setStyles({'display':'inline'});
	$('content'+id).setStyles({'display':'none'});
}

//oObj input requires that a matrix filter be applied.
//deg input defines the requested angle of rotation.
var deg2radians = Math.PI * 2 / 360;
function fnSetRotation(oObj, deg)
{    rad = deg * deg2radians ;
    costheta = Math.cos(rad);
    sintheta = Math.sin(rad);

    oObj.filters.item(0).M11 = costheta;
    oObj.filters.item(0).M12 = -sintheta;
    oObj.filters.item(0).M21 = sintheta;
    oObj.filters.item(0).M22 = costheta;

}

function discuss(){
	var myFx = new Fx.Scroll(window,{duration:800}).toBottom();
	$('discuss').focus();
}

var timeoutCloseLngMenu;

function openLngMenu(bt){
	$('LngMenu').set({
		'class':'LngMenuUpHeader',
		'styles': {
			'display':'block',
			'top':$('Lngs').getCoordinates().top+40,
			'left':$('Lngs').getCoordinates().left-200
		}
	});
}

function askcloseLngMenu(){
	timeoutCloseLngMenu = closeLngMenu.delay(1000);
}

function closeLngMenu(){
	$('LngMenu').setStyles({
		'display':'none'
	});
}


window.addEvent('domready', function() {
	
	$$('.LngMenuBt').addEvents({
			'mouseenter': function(){
				openLngMenu(this);
				
				/* ajouter par Olivier 13 juillet 2010 */
				timeoutCloseLngMenu = $clear(timeoutCloseLngMenu);
				/* Fin ajout par Olivier 13 juillet 2010 */
			},
			'mouseleave': function(){
				askcloseLngMenu();
			}
		})
	$('LngMenu').addEvents({
		'mouseover': function(){
			timeoutCloseLngMenu = $clear(timeoutCloseLngMenu);
		},
		'mouseleave': function(){
			askcloseLngMenu();
		}
	});
});



var aScroll = window.getScroll().y;
window.addEvent('scroll', function(event){
	var Columns = $$('.ScrollColumn');
	if((Columns.length>1) && (Browser.Engine.webkit == true)){
	// if(Columns.length>1){
		var cScroll = window.getScroll().y;
		if (cScroll>aScroll){
			scrollColumn('up');
		} else {
			scrollColumn('down');
		}
		aScroll = window.getScroll().y;
	}
});


function scrollColumn(poss){
	var scroll = window.getScroll().y;
	// var offset = $('Footer').getCoordinates().height+70+100;
	var offset = 0;
	var HeaderHeight = 137;
	var FooterHeight = 150;
	var out = new String();
	var Columns = $$('.ScrollColumn');
	Columns.each(function(column){
		var cOffset = column.getCoordinates().height-window.getHeight()+column.getCoordinates().top+FooterHeight;
		if(cOffset-column.getStyle('margin-top').toInt()<0){
			column.setStyles({
				'margin-top': scroll+'px'
				});
		} else {
			if(poss=='up'){
				if(scroll>=cOffset){
					var margin = scroll - cOffset + column.getStyle('margin-top').toInt();
					column.setStyles({
						'margin-top': margin+'px'
						});
				}
			} else {
				var cOffset = column.getCoordinates().height-window.getHeight()+column.getCoordinates().top+FooterHeight-column.getStyle('margin-top').toInt();
				var margin = column.getStyle('margin-top').toInt();
				if(margin>scroll){
					column.setStyles({
						'margin-top': scroll+'px'
					});
				}
			}
		}
	});
}


