function setUiSize() {
  $(document).ready(function(){
    $("#animPath").attr({src:imagesPath+"a_pixel.gif"});
  
    var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
    var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
    
    var posx = 150*(percentx/100);
    var posy = 124*(percenty/100);
    $("#menu_1").css({'top':posx,'left':posy});
    posx = 120*(percentx/100);
    posy = 80*(percenty/100);
    width = 123*(percentx/100);
    $("#_1").css({'top':posx,'left':posy});
    $("#1img").css({'width':width+"px"});
    $("#menu_1").fadeIn("slow");
    $("#_1").fadeIn("slow");
    
    posx = 232*(percentx/100);
    posy = 248*(percenty/100);
    $("#menu_2").css({'top':posx,'left':posy});
    posx = 205*(percentx/100);
    posy = 205*(percenty/100);
    width = 110*(percentx/100);
    $("#_2").css({'top':posx,'left':posy});
    $("#2img").css({'width':width+"px"});
    $("#menu_2").fadeIn("slow");
    $("#_2").fadeIn("slow");
    
    posx = 255*(percentx/100);
    posy = 135*(percenty/100);
    $("#menu_3").css({'top':posx,'left':posy});
    posx = 225*(percentx/100);
    posy = 80*(percenty/100);
    width = 133*(percentx/100);
    $("#_3").css({'top':posx,'left':posy});
    $("#3img").css({'width':width+"px"});
    $("#menu_3").fadeIn("slow");
    $("#_3").fadeIn("slow");
    
    posx = 360*(percentx/100);
    posy = 162*(percenty/100);
    $("#menu_4").css({'top':posx,'left':posy});
    posx = 330*(percentx/100);
    posy = 110*(percenty/100);
    width = 127*(percentx/100);
    $("#_4").css({'top':posx,'left':posy});
    $("#4img").css({'width':width+"px"});
    $("#menu_4").fadeIn("slow");
    $("#_4").fadeIn("slow");
    
    posx = 475*(percentx/100);
    posy = 82*(percenty/100);
    $("#menu_5").css({'top':posx,'left':posy});
    posx = 450*(percentx/100);
    posy = 32*(percenty/100);
    width = 127*(percentx/100);
    $("#_5").css({'top':posx,'left':posy});
    $("#5img").css({'width':width+"px"});
    $("#menu_5").fadeIn("slow");
    $("#_5").fadeIn("slow");
    
    posx = 650*(percentx/100);
    posy = 130*(percenty/100);
    $("#menu_6").css({'top':posx,'left':posy});
    posx = 615*(percentx/100);
    posy = 90*(percenty/100);
    width = 110*(percentx/100);
    $("#_6").css({'top':posx,'left':posy});
    $("#6img").css({'width':width+"px"});
    $("#menu_6").fadeIn("slow");
    $("#_6").fadeIn("slow");
    
    posx = 135*(percentx/100);
    posy = 332*(percenty/100);
    $("#menu_7").css({'top':posx,'left':posy});
    posx = 107*(percentx/100);
    posy = 297*(percenty/100);
    width = 97*(percentx/100);
    $("#_7").css({'top':posx,'left':posy});
    $("#7img").css({'width':width+"px"});
    $("#menu_7").fadeIn("slow");
    $("#_7").fadeIn("slow");
    
    var h = $("body").innerHeight() * 25 / 100 ;
    //var w = 339 * ((h*100/250) / 100);
    var w = $("body").innerWidth() * 24 / 100 ;
    //$("#GPS").css({"height":h+"px","width":w+"px"});
    var d = new Date();
    var mapname = "map_"+d.getTime();
    $("body").remove("map");
    var cx = 122 * ((w*100/339) / 100);
    var cy = 39 * ((h*100/250) /100);
    var d = 22  * ((h*100/250) / 100);
    var map = "<map id='"+mapname+"' name='"+mapname+"'>"
                    +"<area shape='circle' alt='contact' title='contact' coords='"+cx+","+cy+","+d+"' href=\"/spip.php?rubrique79\" />";
    cx = 165 * ((w*100/339) / 100);
    cy = 27 * ((h*100/250) /100);
    d = 19  * ((h*100/250) / 100);
    map += "<area shape='circle' alt='search' title='search' coords='"+cx+","+cy+","+d+"' href=\"javascript:toggleGPSUI( 'search' )\" />";
    cx = 79 * ((w*100/339) / 100);
    cy = 58 * ((h*100/250) /100);
    d = 18  * ((h*100/250) / 100);
    map += "<area shape='circle' alt='back' title='back' coords='"+cx+","+cy+","+d+"' href=\""+urlParent+"\" />";
    cx = 52 * ((w*100/339) / 100);
    cy = 95 * ((h*100/250) /100);
    d = 19  * ((h*100/250) / 100);
    map += "<area shape='circle' alt='menu' title='menu' coords='"+cx+","+cy+","+d+"' href=\"javascript:toggleGPSUI( 'arbo' );\" />";
    cx = 30 * ((w*100/339) / 100);
    cy = 132 * ((h*100/250) /100);
    d = 15.5  * ((h*100/250) / 100);
    map += "<area shape='circle' alt='print' title='print' coords='"+cx+","+cy+","+d+"' "+print_url+" />";
    map += "</map>";
    $("body").append(map);
    $("#GPS").attr({"useMap":"#"+mapname,"border":"0"});
    
    var _pastillew = 30*(percentx/100);
    $(".cartoMenuImg").css({"width":_pastillew+"px","height":_pastillew+"px"});
    
    $('img[@src$=.png]').ifixpng();
  });
}

function setLocation( url ) {
  window.top.location.href=url;
}
function highlightMenuCarto(e, div, anim ) {
  $(document).ready(function(){
    $(".cartoMenuImg").attr({src:imagesPath+"menuButton1.gif"});
    jQuery(div).attr({src:imagesPath+"menuButton2.gif"});
    $("#menu"+div.id).attr({src:imagesPath+"menuButton2.gif"});
    switch(anim) {
      case "Societe":
        if($("#animPath").attr("src") != imagesPath+"a_pixel.gif")
          $("#animPath").attr({src:imagesPath+"a_pixel.gif"});
        $("#1img").attr({src:imagesPath+"lasocietev2.gif"});
      break;
      case "Metier":
        var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
        var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
        var posx = 86*(percentx/100);
        var posy = 174*(percenty/100);
        var width = 59*(percentx/100);
        var height = 94*(percenty/100);
        $("#animPath").attr({src:imagesPath+"anim"+anim+".gif"});
        $("#animPath").css({'top':posy+"px",'left':posx+"px",'width':width+"px",'height':height+"px"});
    
        $("#3img").attr({src:imagesPath+"nosmetiersv2.gif"});
      break;
      case "Finalite":
        var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
        var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
        var posx = 153*(percentx/100);
        var posy = 166*(percenty/100);
        var width = 95*(percentx/100);
        var height = 93*(percenty/100);
        $("#animPath").attr({src:imagesPath+"anim"+anim+".gif"});
        $("#animPath").css({'top':posy+"px",'left':posx+"px",'width':width+"px",'height':height+"px"});
        
        $("#2img").attr({src:imagesPath+"bonsplansv2.gif"});
      break;
      case "Client":
        var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
        var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
        var posx = 152*(percentx/100);
        var posy = 167*(percenty/100);
        var width = 90*(percentx/100);
        var height = 200*(percenty/100);
        $("#animPath").attr({src:imagesPath+"anim"+anim+".gif"});
        $("#animPath").css({'top':posy+"px",'left':posx+"px",'width':width+"px",'height':height+"px"});
        
        $("#4img").attr({src:imagesPath+"clientsv2.gif"});
      break;
      case "Search":
        var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
        var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
        var posx = 65*(percentx/100);
        var posy = 176*(percenty/100);
        var width = 79*(percentx/100);
        var height = 304*(percenty/100);
        $("#animPath").attr({src:imagesPath+"anim"+anim+".gif"});
        $("#animPath").css({'top':posy+"px",'left':posx+"px",'width':width+"px",'height':height+"px"});
        
        $("#5img").attr({src:imagesPath+"rechercherv2.gif"});
      break;
      case "Plan":
        var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
        var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
        var posx = 139*(percentx/100);
        var posy = 167*(percenty/100);
        var width = 102*(percentx/100);
        var height = 499*(percenty/100);
        $("#animPath").attr({src:imagesPath+"anim"+anim+".gif"});
        $("#animPath").css({'top':posy+"px",'left':posx+"px",'width':width+"px",'height':height+"px"});
        
        $("#6img").attr({src:imagesPath+"plandusitev2.gif"});
      break;
      case "Press":
        var percentx = $("#cartoMenuBg").innerWidth()*100/582 ;
        var percenty = $("#cartoMenuBg").innerHeight()*100/829 ;
        var posx = 80*(percentx/100);
        var posy = 65*(percenty/100);
        var width = 256*(percentx/100);
        var height = 91*(percenty/100);
        $("#animPath").attr({src:imagesPath+"anim"+anim+".gif"});
        $("#animPath").css({'top':posy+"px",'left':posx+"px",'width':width+"px",'height':height+"px"});
        
        $("#7img").attr({src:imagesPath+"pressev2.gif"});
      break;
    }
  });
  if(e.stopPropagation)
    e.stopPropagation();
}

function lowlightMenuCarto(e, div, anim ) {
  $(document).ready(function(){
    $(".cartoMenuImg").attr({src:imagesPath+"menuButton1.gif"});
    $("#_1").attr({src:imagesPath+"menuButton2.gif"});
    $("#menu_1").attr({src:imagesPath+"menuButton2.gif"});
    if($("#animPath").attr("src") != imagesPath+"a_pixel.gif")
      $("#animPath").attr({src:imagesPath+"a_pixel.gif"});
    switch(anim) {
      case "Societe":
        $("#1img").attr({src:imagesPath+"lasocietev2on.gif"});
      break;
      case "Metier":
        $("#3img").attr({src:imagesPath+"nosmetiersv2on.gif"});
      break;
      case "Finalite":
        $("#2img").attr({src:imagesPath+"bonsplansv2on.gif"});
      break;
      case "Client":
        $("#4img").attr({src:imagesPath+"clientsv2on.gif"});
      break;
      case "Search":
        $("#5img").attr({src:imagesPath+"rechercherv2on.gif"});
      break;
      case "Plan":
        $("#6img").attr({src:imagesPath+"plandusitev2on.gif"});
      break;
      case "Press":
        $("#7img").attr({src:imagesPath+"pressev2on.gif"});
      break;
    }
  });
  if(e.stopPropagation)
    e.stopPropagation();
}

function highlightAgence(e, id) {
  $(document).ready(function(){
      $("table td").removeClass("agenceSelected");
      $("#_"+id).addClass("agenceSelected");
  });
}
function outAgence (e) {
  $(document).ready(function(){
      $("table td").removeClass("agenceSelected");
  });
}

function clickAgence (e, id) {
  $(document).ready(function(){
    $("#mask").css({'position':'absolute','top':'50%','left':'50%','background-color':'black','opacity':'0.8','width':'0px','height':'0px'});
    $("#diapoViewer_content p").html($("#"+id).html()+"<img src='"+imagesPath+"a_pixel.gif' id='_diapo' /><div id='closeDiapo'></div>");
    
    $("#diapoViewer_content p img").each(function(i) {
      jQuery(this).addClass("miniature");
      jQuery(this).click(function() {
        $("#_diapo").attr("src",jQuery(this).attr("src"));
        $("#_diapo").removeClass("miniature");
      });
    });
    
    $("#mask").animate({'top':'0px','left':'0px','width':'100%','height':'100%'},function() {
      $("#diapoViewer").slideDown("slow");
    });
      
      $("#closeDiapo").click(function () {
        $("#diapoViewer").slideUp("slow",function() {
          $("#diapoViewer_content p").html("");
          $("#mask").animate({'top':'50%','left':'50%','width':'0px','height':'0px'});
        });
      });
  });
}

function showPhoto( params ) {
  return;
  
  if(params == null) {
    alert("Aucune photo disponnible");
    return;
  }
  $(document).ready(function(){
    $("#photo_mask").css({'position':'absolute','top':'50%','left':'50%','background-color':'black','opacity':'0.8','width':'0px','height':'0px'});
    
    var html = "<div id='closePhoto'></div><img src=\""+params[0]+"\" />"
    +"<div style='position:absolute;top:40px;left:220px;width:230px;height:320px;'>"
    +"<p style='text-align:center;padding-top:10px;padding-left:30px;'>"+params[1]+"&nbsp;"+params[2]+"</p>"
    +"<p style='text-align:left;padding-left:30px;padding-top:23px;'>"+params[3]+"</p>"
    +"<p style='text-align:left;padding-left:30px;padding-top:15px;font-size:14px;color:black;'>"+params[4]+"</p></div>";
    
    $("#photoViewer_content p").html(html);
    
    $("#photo_mask").animate({'top':'0px','left':'0px','width':'100%','height':'100%'},function() {
      $("#photoViewer").slideDown("slow");
    });
    $("#closePhoto").click(function () {
      $("#photoViewer").slideUp("slow",function() {
        $("#photoViewer_content p").html("");
        $("#photo_mask").animate({'top':'50%','left':'50%','width':'0px','height':'0px'});
      });
    });
  });
}

function toggleGPSUI( ui ) {
  switch(ui) {
    case "search" :
      $("#GPSUI div").hide();
      $("#search_form").show();
    break;
    case "arbo" :
      $("#GPSUI div").hide();
      $("#arbo").show();
    break;
  }
}

function onLargeImageLoaded(e) {
  var img = this;
  $(document).ready(function(){
  
    while( (img.height > ( ($("body").innerHeight()-70)*0.8)) || (img.width > ($("body").innerWidth()*0.8)) ) {
      img.width = (img.width*0.9);
      img.height = (img.height*0.9);
    }
    
    //$("#photo_mask").css({'position':'absolute','top':'50%','left':'50%','background-color':'black','opacity':'0.8','width':'0px','height':'0px'});
    var html = "<div id='closePhoto'></div>";
    html += "<img id=\"myphoto\" src=\""+img.src+"\" width=\""+img.width+"\" height=\""+img.height+"\"/>";
    if(typeof(img.descr) != "undefined")
      html += "<br><div style=\"width:"+img.width+"px;height:50px;overflow:auto;\"><span class=\"image_descr\">"+img.descr+"</span></div>";
    
    $("#imageViewer .img_content").html(html);
    $("#imageViewer").css({'top':'50%','left':'50%','margin-left':'-'+(img.width/2)+'','margin-top':'-'+(img.height/2+40)+''});
    
    /*$("#photo_mask").animate({'top':'0px','left':'0px','width':'100%','height':'100%'},function() {
      $("#imageViewer").slideDown("slow");
    });*/
    $("#closePhoto").click(function () {
      $("#imageViewer").slideUp("slow",function() {
        $("#imageViewer .img_content").html("");
        $("#photo_mask").animate({'top':'50%','left':'50%','width':'0px','height':'0px'});
      });
    });
  });
}

function showLargeImage( url, description ) {
  if(url == null) {
    alert("Aucune photo disponnible");
    return;
  }
  
  var img = new Image();
  img.src = url;
  img.descr = description ;
  img.onload = onLargeImageLoaded ;
  
  $(document).ready(function(){
    
    $("#photo_mask").css({'position':'absolute','top':'50%','left':'50%','background-color':'black','opacity':'0.8','width':'0px','height':'0px'});
    
    var html = "<img id=\"myphoto\" src=\""+imagesPath+"wait_big.gif\" width=\"124\" height=\"124\"/>";
    
    $("#imageViewer .img_content").html(html);
    
    $("#imageViewer").css({'top':'50%','left':'50%','margin-left':'-112px','margin-top':'-152px'});
    
    $("#photo_mask").animate({'top':'0px','left':'0px','width':'100%','height':'100%'},function() {
      $("#imageViewer").slideDown("slow");
    });
  });
  
}

function changeNews() {
  $(document).ready(function(){
    $("#news").fadeOut("slow",function() {
      var html = "<span>"+allnews[actualNews][0]+"&nbsp;&nbsp;<a href='"+allnews[actualNews][1]+"'> Lire la suite ...</a></span>";
      $("#news").html(html);
      $("#news").fadeIn("slow");
    });
    if(actualNews >= (allnews.length-1) )
      actualNews = 0;
    else
      actualNews++;
  });
}

function animFDP () {
  addPoi();
}

function deleteAllAnimeFDP () {
  deletePoi();
  $("#SatImg").fadeOut("slow");
  $("#RezoImg").fadeOut("slow");
  setTimeout(animFDP,5000);
}

var aPoi = new Array ("ballon_foot.png","gare.gif","tribunal.gif","hopital.jpg","piscine.gif") ;
var p = 0;

function deletePoi () {
  for(i=0;i<aPoi.length;i++) {
        $("#POI"+i).fadeOut("slow");
      }
      p=0;
}
function addPoi () {
    if( $("#POI"+p).length > 0 ) {
      $("#POI"+p).fadeIn("slow");
    }else{
      var img = jQuery("<img>");
      img.attr({"src":imagesPath+aPoi[p],"id":"POI"+p});
      switch(p) {
        case 0:
          img.css({"top":"100px","left":"350px","position":"absolute","display":"none"});
        break;
        case 1:
          img.css({"top":"290px","left":"230px","position":"absolute","display":"none"});
        break;
        case 2:
          img.css({"top":"262px","left":"237px","position":"absolute","display":"none"});
        break;
        case 3:
          img.css({"top":"320px","left":"200px","position":"absolute","display":"none"});
        break;
        case 4:
          img.css({"top":"260px","left":"300px","position":"absolute","display":"none"});
        break;
      }
      img.insertBefore("#animPath");
      $('#POI'+p).ifixpng();
      img.fadeIn("slow");
    }
    p++;
    
    if(p > (aPoi.length-1) ) {
      setTimeout(showSatelliteImg,5000);
    }else
      setTimeout(addPoi,2000);
}

function showSatelliteImg () {
  if( $("#SatImg").length > 0 ) {
      $("#SatImg").slideDown("slow");
    }else{
      var img = jQuery("<img>");
      img.attr({"src":imagesPath+"satellite.png","id":"SatImg"});
      img.css({"top":"0px","left":"0px","position":"absolute","display":"none"});
      img.insertAfter("#cartoMenuBg");
      $('#SatImg').ifixpng();
      img.slideDown("slow");
    }
  setTimeout(showRezoImg,5000);
}

function showRezoImg () {
  if( $("#RezoImg").length > 0 ) {
      $("#RezoImg").slideDown("slow");
    }else{
      var img = jQuery("<img>");
      img.attr({"src":imagesPath+"rezo.png","id":"RezoImg"});
      img.css({"top":"0px","left":"0px","position":"absolute","display":"none"});
      img.insertAfter("#SatImg");
      $('#RezoImg').ifixpng();
      img.slideDown("slow");
    }
  setTimeout(deleteAllAnimeFDP,10000);
}

