var GOOGLEMAPINCLUDE = 0;
var MAXIMUM_WAITING_TIME = 2000;
var requestTimer = '';
var opt = 'icones';
var select = -1;
var d;
var hpage; var wpage;
var prev; var next;
var current;
var imgsave = '';
var saveid;
window.onresize = getPageSize;
var ord = 'asc';
var diapo = false;
var tilt = 'r';
var dir;
var histo = null;
var INFO = false;
var TRANSPARENCY = false;
var dddd = new Date();
var CURSORMOVE = dddd.getTime();
var LOADOSM = false;
var tmp = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
if(tmp) var isIE = document.namespaces ? 1 : 0;
if(isIE){
    if(document.namespaces['v'] == null){
        var stl = document.createStyleSheet();
        stl.addRule("v\\:*", "behavior: url(#default#VML);"); 
        document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
    }
 }

function getPageSize(){
    wpage = (document.body.clientWidth);
    hpage = $('page').clientHeight;
    if($('full')) view('current');
}

function getSize(size){
    if (size == '') return ('');
    if ( size > 1024 * 1024 * 1024 ) return parseFloat(size/(1024*1024*1024)).toFixed(2)+'&nbsp;Go';
    if (size > 1024 * 1024 ) return parseFloat(size/(1024*1024)).toFixed(2)+'&nbsp;Mo';
    if (size > 1024 ) return parseFloat(size/1024).toFixed(2)+'&nbsp;Ko';
    return size+'&nbsp;o'}

function i(d){
    //    alert(d);
    $('page').innerHTML = '<div style="position:absolute;left: 50%;top: 50%;"margin-top: -24px; margin-left: -24px;><img src="i/load.gif" /></div>';
    dir = d;
    asyncRequest('glob.php', function(o) {responseThumbs(o.responseText);}, 'dir=gallery/'+d);
}

function history(){
    var date = new Date();
    if($('full') && CURSORMOVE && CURSORMOVE+5000 < date.getTime()) {
       $('v'+next).style.display = $('v'+prev).style.display =  $('barre').style.display = 'none';
        //alert('oh');
        CURSORMOVE =  false;
        //       document.body.style.cursor = $('full').cursor = "url('i/trans.png'),default";
       addCN('full', 'cur');
       addCN('v'+current, 'cur');
    }
    if((window.location.hash) && (window.location.hash) != '#' && histo != parseInt(window.location.hash.substring(1))){
        if($('full')) $('page').removeChild($('full'));
        histo = parseInt(window.location.hash.substring(1));
        view(histo);
    }
    else if((histo != null) && (!(window.location.hash) ||(window.location.hash) == '#') ){closeViewer();}
    setTimeout('history();', 100); 
}

function gimp(action, valeur){
    if(diapo) stopdiaporama;
    $('v'+current).style.opacity = "0.5";
    asyncRequest('gimp.php', function(o) {responseGimp(o.responseText);}, 'img=gallery/'+dir+'/'+d.f[current].n+'&action='+action+'&valeur='+valeur);
    //voir pour gérer ça dans la nouvelle fct
    //    requestTimer = setTimeout(function(){xhr.abort();}, 100);//MAXIMUM_WAITING_TIME)
}

function save(img1, img2){
    saveid = current;
    asyncRequest('save.php', function(o) {responseSave(o.responseText);}, 'img1='+img1+'&img2='+img2+'&dir=gallery/'+dir);
    //    requestTimer = setTimeout(function(){xhr.abort();}, MAXIMUM_WAITING_TIME)
}

function transparency() {
    $('full').style.background = (TRANSPARENCY)?"black":"url(i/trans.png)";
    TRANSPARENCY = !TRANSPARENCY;
}
function view(k, option){
    var himg;var wimg;
    var date = new Date();
    var pioupiou = date.getTime()+'.jpg';
    if($('menu')) $('full').removeChild($('menu'));
    if($('info')) {
        $('full').removeChild($('info'));
        $('v'+current).style.display = '';
        INFO = false;
    }
    if(k == 'next') j = next;
    else if(k == 'prev') j = prev;
    else if(k == 'current') j = current;
    else j = k;
    if(imgsave != '' && current != j){
        if(confirm('Enregistrer les modifications ?')){save(d.f[current].n, imgsave.n)}
        else{d.f[current] = imgsave;
            var img = new Image();
            img.src='http://viewer.gheop.com/gallery/'+dir+'/'+imgsave.n+((pioupiou!='')?'?uniqId='+pioupiou:'');
            img.height = himg;
            img.width = wimg;
            $('full').removeChild($('v'+current));
            img.id = 'v'+current;
            $('full').appendChild(img);
        }
        imgsave = '';
    }
    histo = current = j;
    window.location.hash=histo;
    document.title = dir+'#'+j;
    if(option == 'zoom'){
        $('v'+current).height = $('v'+current).height*1.1;
        $('v'+current).width = $('v'+current).width*1.1;
        return}
    else if(option == 'dezoom'){
        $('v'+current).height = $('v'+current).height*0.9;
        $('v'+current).width = $('v'+current).width*0.9;
        return;}
    else{
        var tmpw = d.f[j].w/(wpage-40);
        var tmph = d.f[j].h/(hpage-20);
        wimg = d.f[j].w;himg = d.f[j].h;
        if((tmpw > 1 && tmpw > tmph && (arguments.length == 1 || option=='gimp')) || (tmpw < tmph < 1 && option=='full')){
            wimg = parseInt(d.f[j].w/tmpw);
            himg = parseInt(d.f[j].h/tmpw)} 
        else if((tmph > 1 && tmph > tmpw && (arguments.length == 1 || option=='gimp')) || (tmph < tmpw < 1 && option=='full')){
            wimg = parseInt(d.f[j].w/tmph);
            himg = parseInt(d.f[j].h/tmph)}
        if(option == 'full' || option == 'gimp'){
            $('v'+current).height = himg;
            $('v'+current).width = wimg;
            if(option == 'gimp') $('v'+current).src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[j].n+((pioupiou!='')?'?uniqId='+pioupiou:''); 
                return; 
        }
    }

    var saveprev = prev; var savenext = next;
    prev = (j == 0)?d.f.length-1:(j-1);
    next = (j ==d.f.length-1)?0:j+1; 
    if(!$('full')){
        var full = document.createElement('div');
        full.id = 'full';
        $('page').appendChild(full);
        var div = document.createElement('div');
        div.id = 'barre';
        div.innerHTML = '<a class="i1" onclick="view(\'prev\');" title="Previous"><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i2" onclick="view(\'next\')" title="Next"><img src="http://viewer.gheop.com/i/trans.gif" /></a><a id="diaporama" class="i3" onclick="startdiaporama()" title="Démarrer Diaporama" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a id="iinfo" class="i14" onclick="affInfo()" title="Plus d\'information" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a id="itrans" class="i15" onclick="transparency()" title="Fond transparent" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i4" onclick="view(\'current\', \'zoom\')" title="zoomer" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i5" onclick="view(\'current\', \'dezoom\')" title="dézoomer" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i6" onclick="view(\'current\', \'full\')" title="taille maxi visible" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i7" onclick="view(\'current\', \'normale\')" title="taille normale" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i8" onclick="gimp(\'rotate\',270)" title="rotation vers la gauche" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i9" onclick="gimp(\'rotate\',180)" title="rotation à 180°"/><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i10" onclick="gimp(\'rotate\',90)" title="rotation vers la droite" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i11" onclick="gimp(\'flip\',0)" title="mirroir vertical" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i12" onclick="gimp(\'flip\',1)" title="mirroir horizontal" /><img src="http://viewer.gheop.com/i/trans.gif" /></a><a class="i13" onclick="closeViewer();" title="fermer" /><img src="http://viewer.gheop.com/i/trans.gif" /></a>';
        full.appendChild(div);

         $('full').oncontextmenu = imgMenu;
         $('full').onmousedown = imgClic;

        var img = new Image();
        img.id = 'v'+current;
        img.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[j].n+((pioupiou!='')?'?uniqId='+pioupiou:'');
        $('full').appendChild(img);
        if(option) return;
        
        if(next != current) {
            var inext = new Image();
            inext.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[next].n;
            inext.id = 'v'+next;
            $('full').appendChild(inext);
        }
        if (prev != current) {
            var iprev = new Image();
            iprev.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[prev].n;
            iprev.id = 'v'+prev;
            $('full').appendChild(iprev);
        }
    }
    else{
         if(k == 'next'){
             $('v'+saveprev).className = 'unshow';
             if(!$('v'+next)){
                 var inext = new Image();
                 inext.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[next].n;
                 inext.id = 'v'+next;
                 $('full').appendChild(inext);
             }
         }
         else if(k == 'prev'){
             $('v'+savenext).className = 'unshow';
             if(!$('v'+prev)){
                 var iprev = new Image();
                 iprev.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[prev].n;
                 iprev.id = 'v'+prev;
                 $('full').appendChild(iprev);
             }
         }
         else{
             var img = new Image();
             img.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[j].n+((pioupiou!='')?'?uniqId='+pioupiou:'');
             img.onload = function (){$('full').removeChild($('v'+current));
                                      img.id = 'v'+current;
                                      $('full').appendChild(img)}
         }
    }
    if(isIE){
        var img = new Image();
        img.src='http://viewer.gheop.com/gallery/'+dir+'/'+d.f[j].n+((pioupiou!='')?'?uniqId='+pioupiou:'');
        img.onload = function (){$('full').removeChild($('v'+current));
                                 img.id = 'v'+current;
                                 img.className = 'current';
                                 img.height = himg;
                                 img.width = wimg;
                                 $('full').appendChild(img)}}
    else{
        $('v'+current).style.display = '';
        $('v'+current).className = 'current';
        $('v'+current).height = himg;
        $('v'+current).width = wimg}
    if($('comm')) $('full').removeChild($('comm'));
    if(d.f[j].c) {
        var comm = document.createElement('div');
        comm.id = 'comm';
        comm.innerHTML = '<div id="commin">'+unescape(d.f[j].c)+'</div>';
        $('full').appendChild(comm);
    }
    //alert(d.f[j].c);
    if(prev != current) {
        if(d.f[prev].w > d.f[prev].h){ $('v'+prev).width = 100; $('v'+prev).height = (100*d.f[prev].h)/d.f[prev].w}
        else{$('v'+prev).height = 100; $('v'+prev).width = (100*d.f[prev].w)/d.f[prev].h}
        $('v'+prev).className = 'prev';
        $('v'+prev).style.opacity = 0.2;
        $('v'+prev).style.filter = "alpha(opacity=20)";
        $('v'+prev).setAttribute('onclick', 'view("prev")'); 
        $('v'+prev).setAttribute('onmouseover', 'setOpacity("v"+prev, 0.6)');
        $('v'+prev).setAttribute('onmouseout', 'setOpacity("v"+prev, 0.2)');  
    }
    if(next != current) {
        if(d.f[next].w > d.f[next].h){ $('v'+next).width = 100; $('v'+next).height = (100*d.f[next].h)/d.f[next].w}
        else{$('v'+next).height = 100; $('v'+next).width = (100*d.f[next].w)/d.f[next].h}
        $('v'+next).className = 'next';
        $('v'+next).style.opacity = 0.2;
        $('v'+next).style.filter = "alpha(opacity=20)";
        $('v'+next).setAttribute('onclick', 'view("next")'); 
        $('v'+next).setAttribute('onmouseover', 'setOpacity("v"+next,0.6)'); 
        $('v'+next).setAttribute('onmouseout', 'setOpacity("v"+next, 0.2)'); 
    }
    $('v'+current).setAttribute('onclick','');
    $('v'+current).setAttribute('onmouseover','');
    $('v'+current).setAttribute('onmouseout','');
    $('v'+current).style.opacity = 1;
    $('v'+current).style.filter = "alpha(opacity=100)";
    document.onkeydown = viewerCheckKey;
    if ($('v'+current).addEventListener) $('v'+current).addEventListener('DOMMouseScroll', wheel, false);
    $('v'+current).onmousewheel = wheel;
    addCN('full', 'cur');
    addCN('v'+current, 'cur');
    $('full').onmousemove = $('full').onclick =  function () { 
        removeCN('full', 'cur');
        removeCN('v'+current, 'cur');
        //        removeCN('full', 'cur');
        $('v'+next).style.display = $('v'+prev).style.display = $('barre').style.display = '';
        var d = new Date();
        CURSORMOVE = d.getTime();
    };
}

function setOpacity(id,nb){$(id).style.opacity=nb}

function startdiaporama(){
    addCN('full', 'cur');
    addCN('v'+current, 'cur');
    window.fullScreen = true;
    $('v'+next).style.display = $('v'+prev).style.display =  $('barre').style.display = 'none';
    $('diaporama').className = 'i3b';
    $('diaporama').onclick = stopdiaporama;
    setTimeout('diaporama();', 3000);
    diapo = true}

function diaporama(){
    if(!diapo) return;
    view('next');
    $('v'+next).style.display = $('v'+prev).style.display = $('barre').style.display = 'none';
    setTimeout('diaporama();', 3000)}

function stopdiaporama(){
    diapo = false;
    $('diaporama').className = 'i3';
    $('diaporama').onclick = startdiaporama}

function closeViewer(){
    if(diapo) stopdiaporama();
    if(imgsave != '') (confirm('Enregistrer les modifications ?'))?save(d.f[current].n, imgsave.n):d.f[current] = imgsave;
    imgsave = '';
    document.onkeydown = function (){;};
    $('page').removeChild($('full'));
    INFO = false;
    histo = null;
    document.title = dir;
    window.location.hash = '#'}

function viewerCheckKey(ev){
    if(!ev) ev = window.event;
    var c = (ev.which)?ev.which:ev.keyCode;
    if(c == 39 || c == 32 || c == 78) view('next');
    else if(c == 37 || c == 80) view('prev');
    else if(c==27 || c == 81){closeViewer()}}

function repCheckKey(ev){
    if(!ev) ev = window.event;
    var c = (ev.which)?ev.which:ev.keyCode;
    if(c == 39 || c == 32 || c == 78) view('next');
    else if(c == 37 || c == 80) view('prev');
    else if(c==27 || c == 81){closeViewer()}}

function triName(a, b){
    if(a.n.toLowerCase() > b.n.toLowerCase()) return 1;
    else return -1}
function reverseName(a, b){ 
    if(a.n.toLowerCase() > b.n.toLowerCase()) return -1;
    else return 1}
function triSize(a, b){return a.s - b.s}
function reverseSize(a, b){return b.s - a.s}
function triTaille(a, b){return (a.h*a.w) - (b.h*b.w)}
function reverseTaille(a, b){return (b.h*b.w) - (a.h*a.w)}

function viewRep(opt, order){
    var data='';
    var date = new Date();
    var t = date.getTime();
    var thsizename = 0;
    var thsizetaille = 0;
    var thsizepoids = 0;
    removeCN("viewlist", "current");
    removeCN("viewicons", "current");
    
    if(opt == 'icones' || !opt){
        $('page').innerHTML = '';  addCN("viewicons", 'current');
        var img = new Array();
        for(j=0;j<d.f.length;j++){
            img[j] = new Image();
            img[j].id = j;
            $('page').appendChild(img[j]);   
            img[j].className = "min";
            img[j].setAttribute('onclick', 'view('+j+')'); 
            img[j].src = 'http://viewer.gheop.com/gallery/'+dir+'/.t/'+d.f[j].n+'.jpg?uniqID='+t+'.jpg';
            //img[j].onload = function (nb){return function(){(isIE)?addIEInstant(nb,tilt):addCadre(nb,tilt);}}(j);
        }
        getPageSize();
    }
    else{
        addCN("viewlist", 'current');
        if($('c0')) thsizename = $('c0').style.width;
        if($('c2')) thsizepoids = $('c2').style.width;
        if($('c1')) thsizetaille = $('c1').style.width;
        var no,so,to;
        no=so=to='tribg';
        if(order == 'name'){
            if(ord == 'asc'){ord='desc';d.f.sort(reverseName)}
            else{ord = 'asc';d.f.sort(triName)}
            no = 'tri'+ord}
        else if(order == 'size'){
            if(ord == 'asc'){ord = 'desc';d.f.sort(reverseSize)}
            else{ord = 'asc';d.f.sort(triSize)}
            so = 'tri'+ord}
        else if(order == 'taille'){
            if(ord == 'asc'){ord = 'desc';d.f.sort(reverseTaille)}
            else{ord = 'asc';d.f.sort(triTaille)}
            to = 'tri'+ord}
        data += '<table><thead><tr><th id="c0" style="width:'+thsizename+'" onclick="viewRep(\'details\', \'name\')" class="'+no+'">Nom</th><th id="r0">|</th><th id="c1" style="width:'+thsizetaille+'" onclick="viewRep(\'details\', \'taille\')" class="'+to+'">Taille</th><th id="r1">|</th><th id="c2" style="width:'+thsizepoids+'" onclick="viewRep(\'details\', \'size\')" class="'+so+'">Poids</th><th id="r2">|</th></tr></thead><tfoot><tr><th id="c0" class="'+no+'" onclick="viewRep(\'details\', \'name\')" >Nom</th><th id="f0">|</th><th id="c1" class="'+to+'" onclick="viewRep(\'details\', \'taille\')">Taille</th><th id="f1">|</th><th id="c2" class="'+so+'" onclick="viewRep(\'details\', \'size\')">Poids</th><th id="f2">|</th></tr></tfoot><tbody>';
        for(j=0;j<d.f.length;j++) data += '<tr id="tr'+j+'" class="ligne" onclick="view('+j+')"><td><img id="'+j+'" class="mindetails" src="http://viewer.gheop.com/gallery/'+dir+'/.t/'+d.f[j].n+'.jpg?uniqID='+t+'.jpg" /> '+d.f[j].n+'</td><td></td><td class="right">'+d.f[j].h+'X'+d.f[j].w+'px</td><td></td><td class="right">'+getSize(d.f[j].s)+'</td><td></td></tr>';
        data+='</tbody></table>';
        $('page').innerHTML = data;
        getPageSize();
        $('c0').style.width = (thsizename)?thsizename:wpage*0.8+'px';
        $('c1').style.width = (thsizetaille)?thsizetaille:wpage*0.1+'px';
        $('c2').style.width = (thsizepoids)?thsizepoids:wpage*0.1+'px';
        $('r0').onmousedown = $('r1').onmousedown = $('r2').onmousedown = setPosition;
        $('f0').onmousedown = $('f1').onmousedown = $('f2').onmousedown = setPosition;
        $('page').onmousemove = setNewPosition;
        $('page').onmouseup = endPosition;
    }
    $('page').onkeydown = repCheckKey;
}

var asyncRequest = function() {
    function handleReadyState(o, callback) {
        if (o && o.readyState == 4) (o.status==200)?callback(o):affError();
        //     if(o.status==200) {
//                 if(callback) callback(o);
//                 if(requestTimer) clearTimeout(requestTimer);
//             }
//             else affError(); 
    }
    var getXHR=function(){return (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Msxml2.XMLHTTP")};
    return function(uri, callback, postData) {
        var xhr = getXHR();
        xhr.open('POST', uri, true);
        xhr.onreadystatechange=function(){handleReadyState(xhr, callback)};
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send('http=1&'+postData);
        //  requestTimer = setTimeout(function(){xhr.abort();},10);// MAXIMUM_WAITING_TIME);
        return xhr};
}();

function responseThumbs(str) {
    //alert(str);
    d=eval('('+str+')');
    viewRep(opt);
    history()}

function responseGimp(o){
    //alert(o);
    var tmp =  eval('('+o+')');
    if (imgsave == '') imgsave = d.f[current];
    d.f[current] = tmp.f[0];
    view(current, 'gimp')}

function responseSave(o){
    var tmp =  eval('('+o+')');
    d.f[saveid] = tmp.f[0];  
    //var img = new Image();
    $(saveid).src='http://viewer.gheop.com/gallery/'+dir+'/.t/'+d.f[saveid].n+'.jpg?uniqID='+Date();
   //  img.src = 'http://viewer.gheop.com/gallery/'+dir+'/.t/'+d.f[saveid].n+'.jpg?uniqID='+Date();
//     img.id = saveid;
//     img.onload = function(){
//         $(saveid).parentNode.replaceChild(img,$(saveid));
//         //        addCadre(saveid, $(saveid).className)
//     } 
    
}

function mercatorToLonLat(lat,lon) {
    var lo = lon * 20037508.34 / 180;
    var la = (Math.log (Math.tan ((90 + lat) * Math.PI / 360)) / (Math.PI / 180))* (20037508.34 / 180);
    return new OpenLayers.LonLat(lo, la);
}

function get_osm_url (bounds) {
    var res = this.map.getResolution();
    var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
    var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
    var z = this.map.getZoom();
    var limit = Math.pow(2, z);
    if (y < 0 || y >= limit) return null;
    else {
        x = ((x % limit) + limit) % limit;
        var path = z + "/" + x + "/" + y + "." + this.type; 
        var url = this.url;
        if (url instanceof Array) url = this.selectUrl(path, url);
        return url + path;
    }
}


function openlayers() {
    if(!LOADOSM) {
        LOADOSM = true;
        var head= document.getElementsByTagName('head')[0];
        var script= document.createElement('script');
        script.onload=function (){return function(){ openlayers();}}();
        script.type= 'text/javascript';
        script.src= 'OpenLayers.js';
        head.appendChild(script);
        return;
    }
    var zoom = 5;
    var lat = [d.f[current].fa,d.f[current].fo]; 
    if(!lat[0] || lat[0] == '--') return;
    $('geoMap').style.height = "300px";
    var map = new OpenLayers.Map ("geoMap", {
        controls:[
                  new OpenLayers.Control.MouseToolbar(),
                  // new OpenLayers.Control.MousePosition(),
                  new OpenLayers.Control.KeyboardDefaults()],
                maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
                numZoomLevels:18, maxResolution:156543, units:'meters', projection: "EPSG:41001"} );
    var layerTilesAtHome = new OpenLayers.Layer.TMS( 
                                                    "tiles@home (direct)", 
                                                    "http://a.tile.openstreetmap.org/",
                                                    {type:'png', getURL: get_osm_url, displayOutsideMaxExtent: true } );
    
    map.addLayer(layerTilesAtHome);
    var center = mercatorToLonLat(parseFloat(lat[0]), parseFloat(lat[1]));
    map.setCenter (center, zoom);
    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);
    
    var size = new OpenLayers.Size(20,34);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/ORANGE.png',size,offset);
    markers.addMarker(new OpenLayers.Marker(center,icon));
}

function returnImg(x, y) {
    if($('v'+current).width > 0) {
        if($('v'+current).width > 80) $('v'+current).width -= 80;
        else $('v'+current).width = 0;
        setTimeout('returnImg('+x+','+y+')', 40);
    }
    else {  
        $('v'+current).style.display = 'none';
        INFO = true;
        var div = document.createElement('div');
        div.id = 'info';
        div.style.height = y+'px';
        div.style.width = x+'px';
        $('full').appendChild(div);
        $('info').innerHTML = '<div id="infohead"><div id="infoimg"><img src="gallery/'+dir+'/.t/'+d.f[current].n+'.jpg" /></div><div id="infotitle">'+d.f[current].n+'<br /><input type="submit" value="Retour à la photo" onclick="affInfo()" /></div></div><div id="infotext"><div class="infoTableTitleBg">	</div><div class="infoTableTitle" id="infoTableImageTitle">Image</div><div style="clear:both;"></div><table><tr><td class="a">Largeur :</td><td class="b">'+d.f[current].w+' pixels</td></tr><tr><td class="a">Hauteur :</td><td class="b">'+d.f[current].h+' pixels</td></tr><tr><td class="a">Type :</td><td class="b">'+d.f[current].t+'</td></tr><tr><td class="a">Prise le :</td><td class="b">'+d.f[current].d+'</td></tr></table><div class="infoTableTitleBg">	</div><div class="infoTableTitle" id="infoTableImageTitle">Fichier</div><div style="clear:both;"></div><table><tr><td class="a">Nom :</td><td class="b">'+d.f[current].n+'</td></tr><tr><td class="a">Taille :</td><td class="b">'+getSize(d.f[current].s)+'</td></tr><tr><td class="a">Modifié le :</td><td class="b">'+d.f[current].dm+'</td></tr></table><div class="infoTableTitleBg">	</div><div class="infoTableTitle" id="infoTableImageTitle">Appareil Photo</div><div style="clear:both;"></div><table><tr><td class="a">Fabricant :</td><td class="b">'+d.f[current].co+'</td></tr><tr><td class="a">Modèle :</td><td class="b">'+d.f[current].m+'</td></tr><tr><td class="a">Logiciel :</td><td class="b">'+d.f[current].so+'</td></tr></table><div class="infoTableTitleBg">	</div><div class="infoTableTitle" id="infoTableImageTitle">Exposition</div><div style="clear:both;"></div><table><tr><td class="a">Obturateur :</td><td class="b">'+d.f[current].ob+'</td></tr><tr><td class="a">Ouverture :</td><td class="b">'+d.f[current].a+'</td></tr><tr><td class="a">Ouverture max :</td><td class="b">'+d.f[current].oa+'</td></tr><tr><td class="a">Angle d\'exposition :</td><td class="b">'+d.f[current].ae+'</td></tr><tr><td class="a">Exposition :</td><td class="b">'+d.f[current].e+'</td></tr><tr><td class="a">Index d\'exposition :</td><td class="b">'+d.f[current].ie+'</td></tr><tr><td class="a">Longueur focale :</td><td class="b">'+d.f[current].f+'</td></tr><tr><td class="a">Distance :</td><td class="b">'+d.f[current].di+'</td></tr><tr><td class="a">Détection :</td><td class="b">'+d.f[current].de+'</td></tr><tr><td class="a">Source de lumière :</td><td class="b">'+d.f[current].sl+'</td></tr><tr><td class="a">Flash :</td><td class="b">'+d.f[current].fl+'</td></tr><tr><td class="a">Mesure :</td><td class="b">'+d.f[current].me+'</td></tr><tr><td class="a">Luminosité :</td><td class="b">'+d.f[current].lu+'</td></tr><tr><td class="a">Vitesse ISO :</td><td class="b">'+d.f[current].i+'</td></tr><tr><td class="a">Latitude GPS :</td><td class="b">'+d.f[current].ga+'</td></tr><tr><td class="a">Longitude GPS :</td><td class="b">'+d.f[current].go+'</td></tr><tr><td class="a">Altitude GPS :</td><td class="b">'+d.f[current].gz+'</td></tr></table><div id="geoMap" style="clear:both;margin:auto;min-width:300px;"></div></div>';
        $('info').onload = openlayers();
    }
    //    return false;
}

function returnInfo(x, y) {
    var xx = $('v'+current).width;
    if( xx < x - 80) {
        xx += 80;
        $('v'+current).width = xx;
        setTimeout('returnInfo('+x+','+y+')', 40);
    }
    else  {
        $('v'+current).width = x;
        INFO = false;
    }
    return false;
}

function affInfo() {
    if(INFO == 'on') return;
    var xsave; var ysave;
    if(!INFO) {
        INFO = 'on';
        xsave = $('v'+current).width;
        ysave = $('v'+current).height;
        returnImg(xsave, ysave);
    }
    else {
        INFO = 'on';
        xsave = parseInt($('info').style.width);
        ysave = parseInt($('info').style.height);
        $('full').removeChild($('info'));
        $('v'+current).style.display = '';
        returnInfo(xsave, ysave);   
    }
    if($('geoMap'))  openlayers();
    //return false; 
}

function imgMenu(ev){
    if($('menu')){ $('full').removeChild($('menu')); return false;}
    if (!ev) ev = window.event;
    affInfo();
    //    var div = document.createElement('div');
    //     div.id = 'menu';
    //     div.style.position = 'absolute';
    //     div.style.top =ev.clientY+'px';
    //     div.style.left = ev.clientX+'px';
    //     $('full').appendChild(div); 
    //     asyncRequest('exif.php', function(o) {responseExif(o.responseText);}, 'img='+d.f[current].n+'&dir=gallery/'+dir);
    return false;
}

function imgClic(ev){return true}
function delError(){$('page').removeChild($('error'))}
function affError(text){
    var div = document.createElement('div');
    div.id = 'error'; 
    if(!text) text ='Le serveur n\'a pas répondu assez rapidement. Veuillez réessayer ultérieurement.'; 
    div.innerHTML = text;
    $('page').appendChild(div);
    setTimeout('delError()', 2000);
}

//gestion de la molette - zoom sur image diaporama
function wheel(event){
    var delta = 0;
    if (!event) event = window.event;
    if (event.wheelDelta){                
        delta = event.wheelDelta;
        if (window.opera) delta = -delta/80} 
    else if (event.detail) delta = -event.detail/3;
    if (delta > 0) view('current', 'zoom');
    else if(delta < 0) view('current', 'dezoom');
    if (event.preventDefault) event.preventDefault();
    event.returnValue = false}

//tablo.js
var MoveResize = false;
var StartXResize;
var Colonne;
var Largeur;

function endPosition() {MoveResize = false}

function setPosition(e) {
    if (!e) e = window.event;
    StartXResize = e.clientX;
    MoveResize = true;
    Colonne = this.previousSibling.id;
    Largeur = $(Colonne).style.width;
    if(!Largeur || Largeur == '') Largeur = '0px';
    Largeur = parseInt(Largeur.substring(0,Largeur.length-2));
}

function setNewPosition(e) {
    if (!e) e = window.event;
    var X = e.clientX - StartXResize;
    if(MoveResize === true)
        $(Colonne).style.width = ((Largeur+X>0)?Largeur+X:0)+'px';
}

//lib.js
function $(i){return document.getElementById(i)}
function addClassName(oElm, strClassName){
	var strCurrentClass = oElm.className;
        if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		oElm.className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
        }
}

function addCN(id, strClassName) {
    var oElm = $(id);
    addClassName(oElm, strClassName)}

function removeClassName(oElm, strClassName){
    var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
    oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "")}

function removeCN(id, strClassName) {
    var oElm = $(id);
    removeClassName(oElm, strClassName)}

// getStyle(truc, top) returne $(truc).style.top sans le px a la fin
function getStyle(el,styleProp) {
    var x = $(el);
    var v = "0px";
    if (x.currentStyle) v = x.currentStyle[styleProp];
    else if (window.getComputedStyle) v = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    return parseFloat(v.substring(0, v.length-2));
}


