/**
 * main scritp for www.mail-mali.ch
 * author : Amin Ladhani, 2011, amin@as-o.ch
 */
var site={init:function(){new showImage('contenu');linkDecoration('contenu');document._getById('copy').onmousedown=function(){if(!document.getElementById('__cms')&&(!window._browser().isIE||window._browser().isIE9)){conn();}};}};var conn=function(){var _this=this;this.planeStyle={'position':'fixed','top':'0','right':'0','z-index':'1050','bottom':'0','left':'0','background-color':'#000','opacity':'0.5'};this.containerSyle={'position':'fixed','top':'50%','left':'50%','z-index':'1100','background-color':'orange','padding':'10px 10px 10px 10px','border':'solid 1px #000','-moz-border-radius':'5px','border-radius':'5px','-webkit-box-shadow':'0px 2px 20px #000000','-moz-box-shadow':'0px 2px 20px #000000','box-shadow':'0px 2px 20px #000000'};this.titleStyle={'-moz-border-radius':'3px','border-radius':'3px','background-color':'#B04B00','color':'#fff','font':'normal 16px arial','padding':'2px 5px','margin':'0 0 10px 0'};this.paragraphStyle={'margin':'0 0 2px 0','padding':'0'};this.labelStyle={'float':'left','width':'120px','color':'#000','padding':'2px 0 2px 0','font':'bold 11px arial','border-bottom':'dotted 1px #AE5C02','color':'#542D01'};this.inputStyle={'width':'220px','margin-left':'2px','font':'11px tahoma','border':'solid 1px #AE5C02','padding':'2px'};this.buttonStyle={'width':'100px','font':'bold 11px arial'};this.infoStyle={'-moz-border-radius':'3px','border-radius':'3px','background-color':'#CFDF06','color':'#414602','font':'bold 11px arial','text-align':'center','padding':'5px'};this.warnStyle={'-moz-border-radius':'3px','border-radius':'3px','background-color':'#BF0000','color':'#fff','font':'bold 11px arial','text-align':'center','padding':'5px'};this.plane=new _element('div')._setStyle(this.planeStyle)._appendTo(document.body);this.container=new _element('div')._setStyle(this.containerSyle)._appendTo(document.body);this.title=new _element('div')._setStyle(this.titleStyle)._setHtml('Authentification')._appendTo(this.container);this.p1=new _element('p')._setStyle(this.paragraphStyle)._appendTo(this.container);this.p2=new _element('p')._setStyle(this.paragraphStyle)._appendTo(this.container);this.p3=new _element('p')._setStyle(this.paragraphStyle)._setStyle({'margin-top':'10px','padding-top':'6px','text-align':'right'})._appendTo(this.container);this.l1=new _element('label')._setStyle(this.labelStyle)._setHtml('Nom d\'utilisateur')._appendTo(this.p1);this.l2=new _element('label')._setStyle(this.labelStyle)._setHtml('Mot de passe')._appendTo(this.p2);this.i1=new _element('input')._setAttributes({'type':'text'})._setStyle(this.inputStyle)._appendTo(this.p1);this.i2=new _element('input')._setAttributes({'type':'password'})._setStyle(this.inputStyle)._appendTo(this.p2);this.sendButton=new _element('input')._setAttributes({'type':'button','value':'envoyer'})._setStyle(this.buttonStyle)._addEvent('click',function(){_this.send();})._appendTo(this.p3);this.cancelButton=new _element('input')._setAttributes({'type':'button','value':'annuler'})._setStyle(this.buttonStyle)._setStyle({'float':'left'})._addEvent('click',function(){_this.cancel();})._appendTo(this.p3);this.container._setStyle({'margin-top':'-'+(this.container.offsetHeight/2)+'px','margin-left':'-'+(this.container.offsetWidth/2)+'px'});this.send=function(){var cnt=_this.p3,usr=_this.i1.value,psw=_this.i2.value;if(!document.getElementById('__info'))
var info=new _element('p')._setAttributes({'id':'__info'})._setStyle(_this.infoStyle)._setHtml('connexion ...')._appendBefore(cnt);new _request.post({file:'__php/conn.xhr.php',param:'usr='+usr+'&psw='+psw,onSend:function(){},onReceive:function(){if(this.responseText=='1'){location.reload();}else{document.getElementById('__info')._setStyle(_this.warnStyle)._setHtml('Utilisateur ou mot de passe incorrect.');}}});};this.cancel=function(){document.onkeypress=function(){};_this.plane._removeElement();_this.container._removeElement();}
document.onkeypress=function(e){var k=window.event?e.keyCode:e.which;if(k==13)
_this.send();};};var showImage=function(container){if(!container)
return false;this.imageArray=[];this.container=typeof container=='string'?document._getById(container):container;if(!this.container)
return false;this.pic=this.container._getByTagName('img');this.setAction();};showImage.prototype.setAction=function(){var im=this.pic,_this=this;im._each(function(img){if(img.className.match('inserted_image')||img.className.match('insertedImg')||img.className.match('imageGal')){var url=location.href.substring(0,location.href.lastIndexOf('/')+1);img['target']=img.getAttribute('src').replace(url,'').replace(/mini_/,'');_this.imageArray.push(img);img._addEvent('mousedown',function(){var _self=window._browser().isIE?event.srcElement:this;_this.createImageWrapper();_this.setCurrent(_self);_this.getImageSize(_self.target);});}
if(img.className.match('inserted_video')){var vEl=new _element('div')._setStyle({'display':'inline'})._setHtml(img.getAttribute('rel'))._appendBefore(img);img._setStyle({'display':'none'});}});};showImage.prototype.setCurrent=function(current){for(var i=0;i<this.imageArray.length;i++)
if(this.imageArray[i]==current)
this.current=i;};showImage.prototype.createImageWrapper=function(){var _this=this;this.plane=new _element('div')._setClass('popImageBackgroundPlane')._addEvent('mousedown',function(){_this.removeImage();})._appendTo(document.body);this.wrapper=new _element('div')._setClass('popImageImageWrapper')._appendTo(document.body);this.loader=new _element('div')._setAttributes({'id':'__ajax_loader'})._setClass('popImageLoader')._appendTo(document.body);if(window._browser().isIE&&!window._browser().isIE9){var stl={'top':(document.documentElement.scrollTop+(Math.round(window._getWindowSize().y/2)))+'px'};this.plane._setStyle({'opacity':'0.8'});}};showImage.prototype.getImageSize=function(file){_this=this;new _request.get({'file':'__php/xhr.getimagesize.php','param':'?file='+file,'onSend':function(){},'onReceive':function(){_this.setImage(_jsonParse(this.responseText),file);}});};showImage.prototype.resizeToWindow=function(size){var ws=window._getWindowSize(),w=parseInt(size.width),h=parseInt(size.height),h1,r1,w1;if(parseInt(h)>parseInt(ws.y)){h1=parseInt(ws.y);r1=h/parseInt(ws.y);w1=Math.round(w/r1);if(w1>parseInt(ws.x)){w1=ws.x;r1=w1/parseInt(ws.x);h1=Math.round(h1/r1);}}
if(parseInt(w)>parseInt(ws.x)){w1=w1?w1:parseInt(ws.x);r1=w/parseInt(ws.x);h1=Math.round(h/r1);if(h1>parseInt(ws.y)){h1=ws.y;r1=h1/parseInt(ws.y);w1=Math.round(w1/r1);}}
return{'height':(h1?h1-50:h),'width':(w1?w1-50:w)};};showImage.prototype.setImage=function(rsize,image){var _this=this,el=this.wrapper,size=this.resizeToWindow({'width':rsize['width'],'height':rsize['height']}),marginLeft=parseInt(el._getStyle('margin-left')),marginTop=parseInt(el._getStyle('margin-top')),newMarginLeft='-'+Math.round(size.width/2),newMarginTop='-'+Math.round(size.height/2),transH=new _basicFx.transition.sineInOut(this.wrapper,{onComplete:function(){_this.img=new _element('img')._setClass('popImage')._setStyle({'display':'none','width':(size.width-4)+'px','height':(size.height-4)+'px'})._setAttributes({'src':image})._addEvent('mousedown',function(){_this.removeImage();})._appendTo(el);if(rsize.legend){var legend=new _element('div')._setAttributes({'id':'__image_legend'})._setClass('popImageLegend')._setHtml(rsize.legend)._appendTo(el);var closeLegend=new _element('div')._setAttributes({'title':'hide legend'})._setHtml('x')._setClass('popImageLegendClose')._addEvent('mousedown',function(){legend._removeElement();})._appendTo(legend);}
_this.isLoaded(_this.img);}}),transW=new _basicFx.transition.sineInOut(this.wrapper,{onComplete:function(){transH.start(['height',el.offsetHeight,size.height],['margin-top',marginTop,newMarginTop]);}});transW.start(['width',el.offsetWidth,size.width],['margin-left',marginLeft,newMarginLeft]);};showImage.prototype.setNavigButton=function(){if(this.imageArray.length<2)
return false;var _this=this;this.next=new _element('div')._setAttributes({'title':'image suivante'})._setClass('popImageNavigButton')._setStyle({'right':'5px'})._setHtml('&raquo;')._addEvent('click',function(){_this.nextImage();})._appendTo(this.wrapper);this.previous=new _element('div')._setAttributes({'title':'image précédente'})._setClass('popImageNavigButton')._setStyle({'left':'5px'})._setHtml('&laquo;')._addEvent('click',function(){_this.previousImage();})._appendTo(this.wrapper);};showImage.prototype.isLoaded=function(image){var trans=new _basicFx.transition(image);if(image.complete){image._setStyle({'display':'','opacity':'0'});document._getById('__ajax_loader')._setStyle({'display':'none'});trans.start(['opacity',0,100]);_this.setNavigButton();}else{image.onload=function(){document._getById('__ajax_loader')._setStyle({'display':'none'});image._setStyle({'display':'','opacity':'0'});trans.start(['opacity',0,100]);_this.setNavigButton();}}};showImage.prototype.nextImage=function(){var prv=this.imageArray[this.current+1]?this.current+1:0;this.navigButtonAction(prv);};showImage.prototype.previousImage=function(){var prv=this.imageArray[this.current-1]?this.current-1:this.imageArray.length-1;this.navigButtonAction(prv);};showImage.prototype.navigButtonAction=function(i){this.current=i;this.img._removeElement();this.next._removeElement();this.previous._removeElement();if(document.getElementById('__image_legend'))
document.getElementById('__image_legend')._removeElement();this.getImageSize(_this.imageArray[i].target);document._getById('__ajax_loader')._setStyle({'display':''});};showImage.prototype.removeImage=function(){this.plane._removeElement();this.wrapper._removeElement();this.loader._removeElement();};var replaceFileOpenAction={init:function(){this.container=document._getById('contenu');this.href=this.container._getByTagName('a');this.set();},set:function(){var a=this.href;a._each(function(el){if(el.getAttribute('href').match(/.pdf/)){el.setAttribute('target','_blank');}});}};var linkDecoration=function(c){this.container=document._getById(c);this.href=this.container._getByTagName('a');this.googleImg=new _element('img')._setAttributes({'src':'__layout/icon_map.png'})._setStyle({'vertical-align':'middle','margin-left':'3px'});this.href._each(function(a){if(a.getAttribute('href').match('maps.google')){this.googleImg._appendAfter(a);a._setAttributes({'target':'_blank','title':'carte google map'});}});};
