// Amin Ladhani 2010
// amin@as-o.ch 
// aso@net2000.ch
// all scripts in this file are free to use

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('g h={B:e(){g a=\'<7 C="D">\';a+=\'<i>E | F G</i>\';a+=\'<j H="I" J="K.L">\';a+=\'<p><4>M</4><9 b="N" f="O" /></p>\';a+=\'<p><4>P Q R</4><9 b="S" f="T" /></p>\';a+=\'<p><4><9 b="U" k="V" W="h.l()"></4>\';a+=\'<9 b="X" k="Y" f="Z" /></p>\';a+=\'</j>\';a+=\'</7>\';1.3=5.m(\'7\');1.3.n(\'6\',\'o:q;r:s%;t:s%;\'+\'u:10;z-v:11;\');1.3.12=a;1.w();5.c.x(1.3);1.3.6.13=\'-\'+1.3.14/2+\'y\';1.3.6.15=\'-\'+1.3.16/2+\'y\';1.3.6.u=\'17\'},w:e(){1.d=5.m(\'7\');1.d.n(\'6\',\'o:q;r:0;18:0;19:0;t:0;1a:1b 1c;\'+\'1d-1e:#1f;z-v:1g;1h:0.8;\');5.c.x(1.d)},l:e(){5.c.A(1.3);5.c.A(1.d)}};',62,80,'|this||divContainer|label|document|style|div||input||type|body|divBg|function|name|var|conn|h1|form|value|close|createElement|setAttribute|position||fixed|top|50|left|visibility|index|createBg|appendChild|px||removeChild|insert|id|conn_container|LEVITAIR|CMS|Connect|method|POST|action|connexion|php|Utilisateur|text|user|Mot|de|passe|password|pass|button|Annuler|onclick|submit|Ok|connect|hidden|1000|innerHTML|marginLeft|offsetWidth|marginTop|offsetHeight|visible|right|bottom|border|solid|1px|background|color|000|200|opacity'.split('|'),0,{}))
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var popupimage = function(chemin,nom,param){
		popupImage = window.open('',nom,param)
		html = 	'<html><head>'+
			'<body leftmargin=0 marginwidth=0 '+
			'topmargin=0 marginheight=0>'+
			'<img src="'+chemin+'" border=0>'+
			'</body></head></html>';
		popupImage.document.open();
		popupImage.document.write(html);
		popupImage.document.close();
	};
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var stopOverlfow = function(){
		var el = document.getElementById('main_wrapper');
		if(document.documentElement.clientHeight<el.offsetHeight+30){ 
			el.style.marginTop = '0px';
			el.style.top = '0';
		}else{
			el.style.marginTop = '';
			el.style.top = '';
		}
	};
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var homeImageHover = function(){
		var a = document.getElementById('home_wrapper').getElementsByTagName('a');
		for(var i=0;i<a.length;i++){
			if(a[i].parentNode.className == 'home_imgtop_cont'){
				a[i].onmouseover = function(){
					this.parentNode.parentNode.getElementsByTagName('a')[1].className = 'select';
				}
				a[i].onmouseout = function(){
					this.parentNode.parentNode.getElementsByTagName('a')[1].className = '';
				}
			}
		}
	};
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var scrollText = function(obj){
		var outerBox = document.getElementById(obj['wrapper']);
		var innerBox = document.getElementById(obj['textbloc']);
		var height = innerBox.offsetHeight;
		var max = outerBox.offsetHeight;
		innerBox.style.marginTop = outerBox.offsetHeight+'px';
		var loop = setInterval("scrollLoop()",80);
		scrollLoop = function(){
			if(max== "-"+height) max = outerBox.offsetHeight;
			innerBox.style.marginTop = max+'px'; 
			max = max-1;
		}
		outerBox.onmouseover = function(){
			clearInterval(loop);
		}
		outerBox.onmouseout = function(){
			loop = setInterval("scrollLoop()",80);
		}
	};
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var pdfIcon = {
		set : function(){
			var cont = document.getElementById('contenu');
			if(!cont) return false;
			this.a = cont.getElementsByTagName('a');
			for(var i=0; i<this.a.length; i++){
				if(this.a[i].href.match(/.pdf/)){
					this.setImage(this.a[i]);
				}
			}
		}
		,setImage : function(a){
			a.className = a.className+' pdf';
		}
	};
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var dropMenu = {
		init : function(menuid,tag){
			var _this = this;
			if(!document.getElementById(menuid)) return false;
			this.mainMenuP = document.getElementById(menuid).getElementsByTagName(tag);
			this.dropPos();
			this.hover();
			window.onresize = function(){
				_this.dropPos();
			}
		},
		hover : function(){
			var menu = this.mainMenuP;
			for(var i=0;i<menu.length;i++){
				var menuElement = menu[i].firstChild;
				menuElement.onmouseover = function(e){
					if(!document.all) e.stopPropagation();
					var dropElement = document.getElementById(this.innerHTML);
					if(!dropElement) return false;
					dropElement.opener = this;
					dropElement.style.display = 'block';
					dropElement.onmouseover = function(e){
						if (!document.all) e.stopPropagation();
						this.style.display = "block";
						this.opener.style.color = '#fff';
					}
					dropElement.onmouseout = function(e){
						if (!document.all) e.stopPropagation();
						this.style.display = "none";
						this.opener.style.color = '';
					}
				}
				menuElement.onmouseout = function(e){
					if (!document.all) e.stopPropagation();
					if(!document.getElementById(this.innerHTML)) return false;
					document.getElementById(this.innerHTML).style.display = 'none';
				}
			}
		},
		dropPos : function(){
			var menu = this.mainMenuP;
			for(var i=0;i<menu.length;i++){
				var label = menu[i].firstChild.innerHTML;
				if(!document.getElementById(label)) continue;
				var drop = document.getElementById(label);
				drop['num'] = i+1;
				menu[i]['id'] = i+1;
				drop.style.left = menu[i].offsetLeft+'px';
				drop.style.top = menu[i].offsetTop+'px';
			}
		}
	};
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
	var homedrop = {
		'timeout' : 250,
		'closetimer' : 0,
		'ddmenuitem' : 0,
		mopen : function(id){
			homedrop.mcancelclosetime();
			if(homedrop.ddmenuitem) homedrop.ddmenuitem.style.display = '';
			homedrop.ddmenuitem = document.getElementById(id);
			homedrop.ddmenuitem.style.display = 'block';
		},
		mclose : function(){
			if(homedrop.ddmenuitem){
				homedrop.ddmenuitem.style.display = '';
				//alert(homedrop.ddmenuitem.parentNode.getElementsByTagName('h4')[0].innerHTML)
			}
		},
		mclosetime : function(){
			var _homedrop = homedrop, func = function(){_homedrop.mclose()}
			homedrop.closetimer = window.setTimeout(func, homedrop.timeout);
		},
		mcancelclosetime : function(){
			if(homedrop.closetimer){
				window.clearTimeout(homedrop.closetimer);
				homedrop.closetimer = null;
			}
		}
	};
	var site = {};
	site.gal = {
		init : function(){
			if(!document.getElementById('imggal')) return false;
			this.aArray = [];
			this.gHref = document.getElementById('imggal').getElementsByTagName('a');
			this.setGHref();
		},
		setGHref : function(){
			var a = this.gHref,_this=this,j=1;
			for(var i=0;i<a.length;i++){
				if(a[i].className == 'galpic'){
					a[i].num = j;
					this.aArray.push(a[i]);
					a[i].onclick = function(){return false;};
					a[i].onmousedown = function(){
						var 	relArray = this.rel.split('|'),
							path = relArray[0],
							file = relArray[1],
							width = relArray[2],
							height = relArray[3];
						imageDisplay.init(this,path+'/'+file,'',width+','+height);
					}
					j++;
				}
			}
		}
	};
	var imageDisplay = {
		init : function(elem,file,name,size){
			this.aArray = site.gal.aArray;
			this.elem = elem;
			this.file = file;
			this.name = name;
			this.sizeArray = size.replace(/[^0-9,]/g,'').split(',');
			this.width = this.sizeArray[0];
			this.height = this.sizeArray[1];
			this.resize();
			this.createContainer();
		},
		resize : function(){
			if(this.height>window.getHeight()){
				var ratio = this.height/window.getHeight();
				this.height = window.getHeight()-20;
				this.width = Math.floor(this.width/ratio)-20;
			}
		},
		createContainer : function(){
			var _this = this;
			this.bg = new Element('div',{
				'id' : 'imageBg',
				'title' : 'fermer',
				'styles' : {
					'position' : 'fixed',
					'z-index' : '1200',
					'top' : '0',
					'right' : '0',
					'bottom' : '0',
					'left' : '0',
					'background-color' : '#000',
					'opacity' : '0',
					'cursor' : 'pointer'
				}
			});
			this.image = new Element('img',{
				'src': this.file,
				'styles' : {'width' : this.width,'height' : this.height,'opacity' : '0'}
			});
			this.next = new Element('div',{
				'title' : 'suivant',
				'styles' : {
					'position' : 'absolute',
					'width' : '20px',
					'height' : '20px',
					'right' : '5px',
					'top' : '50%',
					'margin-top' : '-10px',
					'cursor' : 'pointer',
					'background-image' : 'url(__layout/galnext.png)'
				}
			});
			this.prev = new Element('div',{
				'title' : 'précédent',
				'styles' : {
					'position' : 'absolute',
					'width' : '20px',
					'height' : '20px',
					'left' : '5px',
					'top' : '50%',
					'margin-top' : '-10px',
					'cursor' : 'pointer',
					'background-image' : 'url(__layout/galprev.png)'
				}
			});
			this.closeBt = new Element('a',{
				'html' : 'fermer',
				'href' : '',
				'styles' : {
					'position':'absolute',
					'bottom' : '0',
					'right' : '0',
					'display':'block',
					'padding' : '2px 5px',
					'color':'#fff',
					'background-color' : '#000',
					'opacity' : '0.7',
					'text-decoration' : 'none'
				}
			});
			this.container = new Element('div',{
				'id' : 'full_image_container',
				'styles' : {
					'position' : 'fixed',
					'?position' : 'absolute',
					'z-index' : '1200',
					'border' : 'solid 2px #fff',
					'width' : this.width+'px',
					'height' :  this.height+'px',
					'left' : '50%',
					'top' : '50%',
					'margin-left' : '-'+(this.width/2)+'px',
					'margin-top' : '-'+(this.height/2)+'px',
					'background-color' : '#000',
					'opacity' : '0'
				}
			});
			this.bg.onmousedown = function(){_this.closeGal();};
			this.next.onmousedown = function(){_this.swapPic(1);};
			this.prev.onmousedown = function(){_this.swapPic(2);};
			this.closeBt.onclick = function(){_this.closeGal();return false;};
			if(!document.getElementById('imageBg')) document.body.appendChild(this.bg);
			document.body.appendChild(this.container);
			this.bgTween = new Fx.Tween(this.bg,{duration:800});
			this.imageTween = new Fx.Tween(this.image,{duration:500});
			this.containerMorph = new Fx.Tween(this.container,{
				duration:500,
				onComplete : function(){
					_this.container.appendChild(_this.image);
					_this.container.appendChild(_this.next);
					_this.container.appendChild(_this.prev);
					_this.container.appendChild(_this.closeBt);
					_this.load(_this.image,
						_this.container,
						function(){_this.imageTween.start('opacity','0','1');}
					)
				}
			});
			this.bgTween.start('opacity','0','0.6');
			this.containerMorph.start('opacity','0','1');
		},
		swapPic : function(d){
			if(d==1) var num = this.elem.num == this.aArray.length ? 0 : this.elem.num;
			if(d==2) var num = this.elem.num == 1 ? this.aArray.length-1 : this.elem.num-2;
			var 	relArray = this.aArray[num].rel.split('|'),
				path = relArray[0],
				file = relArray[1],
				width = relArray[2],
				height = relArray[3];
			document.body.removeChild(this.container);
			imageDisplay.init(this.aArray[num],path+'/'+file,'',width+','+height);
		},
		closeGal : function(){
			document.body.removeChild(this.container);
			document.body.removeChild(document.getElementById('imageBg'));
		},
		load : function(image,container,func){
			var waiter = new Element('div',{
				'html' : '<img src="__layout/ajax-loader.gif" />',
				'styles' : {
					'position' : 'absolute',
					'width' : '100%',
					'top' : '45%',
					'text-align' : 'center'
				}
			});
			if(image.complete){
				func();
			}else{
				container.appendChild(waiter);
				image.onload = function(){
					container.removeChild(waiter);
					func();
				}
			}
		}
	};